Skip to content

Commit 66e7322

Browse files
authored
Update README.md
1 parent 6cedb23 commit 66e7322

File tree

1 file changed

+48
-14
lines changed

1 file changed

+48
-14
lines changed

README.md

Lines changed: 48 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,12 @@
11

22
# OpenGraphParser
33
[![](https://jitpack.io/v/Priyansh-Kedia/OpenGraphParser.svg)](https://jitpack.io/#Priyansh-Kedia/OpenGraphParser)
4-
<a href="https://devlibrary.withgoogle.com/products/android/repos/Priyansh-Kedia-OpenGraphParser"><img alt="Google" src="https://raw.githubusercontent.com/Priyansh-Kedia/OpenGraphParser/612637f6e864ac874cd1dd5071db8ee9e2e971eb/images/google-devlib.png"/></a>
5-
[![License: MIT](https://img.shields.io/badge/License-MIT-yellow.svg)](https://opensource.org/licenses/MIT)
6-
<a
7-
href="https://proandroiddev.com/how-to-create-a-preview-for-a-link-in-android-6906d0aa9e12"><img alt="ProAndroidDev" src="https://raw.githubusercontent.com/Priyansh-Kedia/OpenGraphParser/master/images/Story-Medium.png"/></a>
4+
<a href="https://devlibrary.withgoogle.com/products/android/repos/Priyansh-Kedia-OpenGraphParser"><img alt="Google" src="https://raw.githubusercontent.com/Priyansh-Kedia/OpenGraphParser/master/images/google-devlib.svg"/>
5+
</a>[![License: MIT](https://img.shields.io/badge/License-MIT-yellow.svg)](https://opensource.org/licenses/MIT)
6+
<a
7+
href="https://proandroiddev.com/how-to-create-a-preview-for-a-link-in-android-6906d0aa9e12"><img alt="ProAndroidDev" src="https://raw.githubusercontent.com/Priyansh-Kedia/OpenGraphParser/master/images/%20Story-Medium.svg"/></a>
88

9-
A small and easy to use library which provides the convenience of using [Open Graph Protocol](https://ogp.me/) in Android very easily.
9+
A small and easy to use library which provides the convenience of using [Open Graph Protocol](https://ogp.me/) in Android very easily.
1010
Create previews for links to share in Android very easily.
1111

1212

@@ -48,16 +48,45 @@ Add the dependency
4848

4949
openGraphParser.parse(linkUrl) // To parse the link provided
5050

51+
or you can use the Builder to create the instance of the class if you need to specify additional values. You can do so like this
52+
53+
OpenGraphParser.Builder(listener = this)
54+
.cacheProvider(OpenGraphCacheProvider(this))
55+
.showNullOnEmpty(true)
56+
.maxBodySize(1000000)
57+
.timeout(1000000)
58+
.jsoupProxy(JsoupProxy("<host>", 8000))
59+
.build()
60+
61+
Values that can be specified using the Builder pattern are
62+
63+
> listener:- Specified [here](#listener-opengraphcallback)
64+
65+
> showNullOnEmpty:- Specified [here](#shownullonempty)
66+
67+
> cacheProvider:- Specified [here](#cacheprovider)
68+
69+
> maxBodySize:- max body size to fetch from internet (default 1000000 bytes)
70+
71+
> timeout:- timeout for network request (default 60000 ms)
72+
73+
> jsoupProxy:- Specify proxy while fetching from internet. This will be an instance of JsoupProxy to specify host and port. See: [JsoupProxy](#jsoupproxy-class)
74+
75+
76+
##### Listener (OpenGraphCallback)
5177
The class requires you to implement two callback functions,`onError(error: String)` and `onPostResponse(openGraphResult: OpenGraphResult)`. The former is invoked in case of error (incorrect url), and the latter is invoked on successful response.
5278

79+
##### showNullOnEmpty
5380
The `showNullOnEmpty` is an optional parameter, with a default value of `false`. If set to `true`, the parser would invoke `onError` if the `title` and `description` are empty for the link provided.
5481

82+
##### CacheProvider
5583
The `cacheProvider` is also an optional parameter. It can be passed in two ways :-
56-
1. The default `OpenGraphCacheProvider`, which implements `SharedPreferences` from the library itself.
57-
2. A custom Shared Preferences class which should implement the interface `CacheProvider`. The `CacheProvider` interface provides two callback functions `getOpenGraphResult` and `setOpenGraphResult`, where `getOpenGraphResult` is used to write to the cache, and `setOpenGraphResult` is used to read from the cache.
84+
1. The default `OpenGraphCacheProvider`, which implements `SharedPreferences` from the library itself.
85+
2. A custom Shared Preferences class which should implement the interface `CacheProvider`. The `CacheProvider` interface provides two callback functions `getOpenGraphResult` and `setOpenGraphResult`, where `getOpenGraphResult` is used to write to the cache, and `setOpenGraphResult` is used to read from the cache.
5886

87+
---------
5988

60-
Inside `onPostResponse(openGraphResult: OpenGraphResult)` you can use the data to show on your UI like this.
89+
Inside `onPostResponse(openGraphResult: OpenGraphResult)` you can use the data to show on your UI like this.
6190

6291
override fun onPostResponse(openGraphResult: OpenGraphResult) {
6392
linkPreviewLayout.apply {
@@ -69,12 +98,17 @@ Inside `onPostResponse(openGraphResult: OpenGraphResult)` you can use the data t
6998

7099
## OpenGraphResult class
71100
The data class ***OpenGraphResult*** contains:
72-
- title -> The title of the page the link points to
73-
- description -> The description metadata of the page
74-
- url -> The url of the page
75-
- image -> The image metadata for the page
76-
- siteName -> The name of the website (BASE URL).
77-
- type -> The type of the object e.g., "video.movie".
101+
- title -> The title of the page the link points to
102+
- description -> The description metadata of the page
103+
- url -> The url of the page
104+
- image -> The image metadata for the page
105+
- siteName -> The name of the website (BASE URL).
106+
- type -> The type of the object e.g., "video.movie".
107+
108+
## JsoupProxy class
109+
The data class ***JsoupProxy*** contains:
110+
- host -> The host for the proxy
111+
- port -> The port for the proxy
78112

79113

80114
# Contributions

0 commit comments

Comments
 (0)