Beaver

Additional

Language
Kotlin
Version
1.0.1 (May 16, 2019)
Created
Apr 9, 2019
Updated
Apr 25, 2021 (Retired)
Owner
Taylan Sabırcan (savepopulation)
Contributors
Mert Şimşek (iammert)
Taylan Sabırcan (savepopulation)
2
Activity
Badge
Generate
Download
Source code

beaver

Beaver is a lightweight url meta data parser library. Beaver, loads the metadata of the given url and stores it locally and caches in memory by default. Beaver uses Kotlin-Coroutines for background operations. Room is used for local cache operations.

Tech Stack:

  • Kotlin
  • Kotlin Coroutines
  • Room
  • Repository pattern

How to use?

It's easy to use. Just Init Beaver before start using.

Beaver.build(this)

And load url's metadata like the following:

launch {
  val metaData = Beaver.load("https://www.example.com").await()
  if (metaData != null) {
    // do what ever you want with your meta data..
  }

With defaults, load method checks memory cache, local cache and if there's no metadata available in caches it parses metada data from remote.

You can force to refresh with RemoteDataSource

Beaver.load("https://www.example.com",forceRefresh = true).await()

You can use only cache sources with

Beaver.load("https://www.example.com",forceLocal = true).await()

You can destroy Beaver easily with

Beaver.destroy()

You can drop cache

Beaver.dropCache()()

Or you can just drop local cache. By default, this clears all the local db

Beaver.dropLocalCache()()

If you want to drop only one item's local cache you can pass a url

Beaver.dropLocalCache("https://www.example.com")

Customizing Beaver

Beaver is fully customizable.

You can implement your own metada data parser with implementing MetaDataParser and passing to Beaver By defaults, Beaver uses meta data parser implementation of PannomKathrik's RichLinkPreview library's meta data parser implementation. You can find this useful library from here: https://github.com/PonnamKarthik/RichLinkPreview

Beaver.build(this, metaDataParser = yourCustomMetaDataParserImpl)

By defaults, Beaver uses it's own AsnyManager for handling async operations. If you need you can implement AsyncManager pass it to Beaver and use your own implementation for async operations.

Beaver.build(this, asyncManager = yourCustomAsyncManagerImpl)

Also you can use your own memory cache implementation. You can implement DataSource.Cache<String, MetaData>? and pass while building.

Beaver.build(this, cacheDataSource = yourCacheDataSourceImpl)

You can customize your local storing implementation. By defaults Beaver uses it's own local cache implementation which uses Room. You can implement DataSource.Local<String, MetaData>? and pass it to Beaver instance while building.

Beaver.build(this, localDataSource = yourLocalDataSourceImpl)

Dependency

maven { url 'https://jitpack.io' }
dependencies {
    implementation 'com.github.savepopulation:beaver:1.0.1'
}

Apps Using in Production

Screenshots:

License:

 Copyright 2018 Taylan SABIRCAN

   Licensed under the Apache License, Version 2.0 (the "License");
   you may not use this file except in compliance with the License.
   You may obtain a copy of the License at

       http://www.apache.org/licenses/LICENSE-2.0

   Unless required by applicable law or agreed to in writing, software
   distributed under the License is distributed on an "AS IS" BASIS,
   WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
   See the License for the specific language governing permissions and
   limitations under the License.