- Notifications
You must be signed in to change notification settings - Fork0
A Kotlin Based Android library for fetching metadata of URL effortlessly
License
zeeshanali-k/MetaProbe
Folders and files
Name | Name | Last commit message | Last commit date | |
---|---|---|---|---|
Repository files navigation
A simple Android Kotlin library for fetching link details like Title, Description, Icon and OG Image effortlessly based onKtor for fetching HTML from provided URL andJsoup for parsing Meta Data. The usecase of this library could be seen in Social Media and Messaging Apps.
For Kotlin Multiplatform CheckMetaProbeKMP
A sample usage is also provided on code along with the design most social media apps use.
Add following dependency to your module level gradle file and make suremavenCentral()
is added in repositories in yoursettings.gradle
file.
Forbuild.gradle.kts
:
implementation("tech.dev-scion:metaprobe:1.0.3")
Forbuild.gradle
:
implementation"tech.dev-scion:metaprobe:1.0.3"
You can use this library in Coroutines or via Callback method (without managing any Coroutine or Thread).
With Coroutine Suspend Method:
MetaProbe(url) .apply { setClient(HttpClient(Android) { engine { connectTimeout=100_000 socketTimeout=100_000 } } ) } .probeLink() .fold( onSuccess= { isLoading.value=false probedData.value= it }, onFailure= { isLoading.value=false }, )
Fold here is just an Convinience Extension Method of KotlinResult
Class, so you can also use MetaProbe without it.For Callback Method Use this code:
MetaProbe(url) .probeLink(object:OnMetaDataProbed {overridefunonMetaDataProbed(pb:Result<ProbedData>) { isLoading.value=falseLog.d(TAG,"onMetaDataProbed:$pb")Log.d(TAG,"onMetaDataProbed:${pb.getOrNull()?.title}")Log.d(TAG,"onMetaDataProbed:${pb.getOrNull()?.icon}")Log.d(TAG,"onMetaDataProbed:${pb.getOrNull()?.description}") probedData.value= pb.getOrNull() } })
You can removesetClient
as it is not necessary and only needed when you want to cutomise your HTTPClient, for example for logging etc.
ProbedData
is the class returned in result which contains the actual values of Title, Description, Icon and OGImage.
About
A Kotlin Based Android library for fetching metadata of URL effortlessly