Ecosyste.ms: Awesome
An open API service indexing awesome lists of open source software.
https://github.com/0xd3adcode/metronapi
Kotlin library for working with Metron API. Powered by OkHttp, Retrofit, Gson and RxJava
https://github.com/0xd3adcode/metronapi
api gson kotlin library metron okhttp retrofit2 rxjava2
Last synced: about 1 month ago
JSON representation
Kotlin library for working with Metron API. Powered by OkHttp, Retrofit, Gson and RxJava
- Host: GitHub
- URL: https://github.com/0xd3adcode/metronapi
- Owner: 0xD3ADCODE
- License: mit
- Created: 2023-01-02T19:38:28.000Z (about 2 years ago)
- Default Branch: main
- Last Pushed: 2023-07-23T14:47:52.000Z (over 1 year ago)
- Last Synced: 2024-11-07T17:33:18.091Z (about 2 months ago)
- Topics: api, gson, kotlin, library, metron, okhttp, retrofit2, rxjava2
- Language: Kotlin
- Homepage:
- Size: 65.4 KB
- Stars: 1
- Watchers: 1
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
- License: LICENSE
Awesome Lists containing this project
README
# MetronAPI
Kotlin library for working with [Metron API](https://metron.cloud). Powered by [OkHttp](https://square.github.io/okhttp/), [Retrofit](https://square.github.io/retrofit/), [Gson](https://github.com/google/gson) and [RxJava](https://github.com/ReactiveX/RxJava)
## Dependency
To add this library as dependency, add this line into your `dependencies` build.gradle block:
```groovy
implementation 'com.github.AtsumeruDev:MetronAPI:-SNAPSHOT'
```Also, make sure to add this repository into `repositories` block:
```groovy
maven { url 'https://jitpack.io' }
```## Usage
### Initializing
Usage of library is very simple. First, initialize it (make sure to do it as soon as possible before making any Metron requests):
```kotlin
MetronApi.init(
builder: OkHttpClient.Builder = OkHttpClient.Builder(), // Custom OkHttp client Builder
userName: String, // Your Metron account username
password: String, // Your Metron account password
apiEndpoint: String = "https://metron.cloud/api/", // API Endpoint url. Always try to use default one
userAgent: String = "MetronAPI Library", // API UserAgent. Set your app's name or use default one
httpConnectTimeoutMs: Long = 15000, // Connection timeout in milliseconds
httpReadTimeoutMs: Long = 25000, // Read timeout in milliseconds
isDebug: Boolean = false // Debug mode or not. When true, library will log every request into logs
)
```Simple initializing method with defaults:
```kotlin
MetronApi.init(userName = {username}, password = {password})
```### API Methods calling
After that, you can make calls to any of defined methods. For example, getting info about [Suicide Squad (2016)](https://metron.cloud/series/suicide-squad-2016/) serie (with id `3006`):
#### Async RXJava way:
```java
MetronApi.getSerie(3006)
.cache()
.subscribeOn(Schedulers.newThread())
.observeOn(Schedulers.io())
.subscribe(
serie -> {do on success},
throwable -> {do on throwable}
);
```#### Blocking way:
```java
MetronApi.getSerie(3006).blockingGet()
```