Skip to content

Commit fa42219

Browse files
committed
Initial commit v1.0.0.
1 parent 2d60d47 commit fa42219

20 files changed

+846
-0
lines changed

.idea/dictionaries/epool.xml

Lines changed: 7 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

.idea/gradle.xml

Lines changed: 17 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

.idea/misc.xml

Lines changed: 7 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

.idea/modules/ip-api-klient_main.iml

Lines changed: 27 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

.idea/modules/ip-api-klient_test.iml

Lines changed: 27 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

.idea/vcs.xml

Lines changed: 6 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

README.md

Lines changed: 103 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,103 @@
1+
# IpApiKlient
2+
3+
This is a utility written in [Kotlin](http://kotlinlang.org/) for checking ip's info by fetching the [ip-api.com](http://ip-api.com/) API.
4+
5+
## Libraries
6+
7+
This project uses the following libraries internally to work.
8+
9+
### Development libraries
10+
11+
- [Retrofit](http://square.github.io/retrofit/) used to consume the Picasa api.
12+
- [Retrofit Gson Converter](https://github.com/square/retrofit/tree/master/retrofit-converters/gson) converter to deserialize JSON responses from the picasa api.
13+
- [RxJava2](https://github.com/ReactiveX/RxJava) async requests.
14+
- [Okhttp Logging Interceptor](https://github.com/ReactiveX/RxJava) for logging http requests/responses for the Picasa api.
15+
16+
### Testing libraries
17+
18+
- [Spek](http://spekframework.org/) Used to write some integration tests as specs.
19+
20+
## Usage
21+
22+
### Dependency
23+
24+
```groovy
25+
repositories {
26+
...
27+
maven { url 'https://jitpack.io' }
28+
...
29+
}
30+
31+
dependencies {
32+
...
33+
implementation "com.github.epool:ip-api-klient:1.0.0"
34+
...
35+
}
36+
```
37+
38+
### Blocking
39+
40+
Use it when blocking is safe to use like on web servers.
41+
42+
###### Java
43+
44+
```java
45+
IpCheckResult ipCheckResult = IpApiKlient.getIpInfo("8.8.8.8").blockingGet();
46+
if (ipCheckResult.isSuccess()) {
47+
IpInfo ipInfo = ipCheckResult.getIpInfo();
48+
} else {
49+
IpError ipError = ipCheckResult.getIpError();
50+
}
51+
```
52+
53+
###### Kotlin
54+
55+
```kotlin
56+
val ipCheckResult = IpApiKlient.getIpInfo("8.8.8.8").blockingGet()
57+
if (ipCheckResult.isSuccess()) {
58+
val ipInfo = ipCheckResult.ipInfo
59+
} else {
60+
val ipError = ipCheckResult.ipError
61+
}
62+
```
63+
64+
### Async
65+
66+
Use it when blocking is not safe to use like on Android main thread.
67+
68+
###### Java
69+
70+
```java
71+
IpApiKlient.getIpInfo("8.8.8.8")
72+
.subscribeOn(Schedulers.io())
73+
.observeOn(AndroidSchedulers.mainThread()) // In case you are using it on Android or use any other scheduler you need
74+
.subscribe(
75+
new Consumer<IpCheckResult>() {
76+
@Override
77+
public void accept(IpCheckResult ipCheckResult) throws Exception {
78+
System.out.println(profile.isSuccess());
79+
}
80+
},
81+
new Consumer<Throwable>() {
82+
@Override
83+
public void accept(Throwable throwable) throws Exception {
84+
System.out.println(throwable.getCause().toString());
85+
}
86+
}
87+
);
88+
```
89+
90+
###### Kotlin
91+
92+
```kotlin
93+
IpApiKlient.getIpInfo("8.8.8.8")
94+
.subscribeOn(Schedulers.io())
95+
.observeOn(AndroidSchedulers.mainThread())
96+
.subscribe(
97+
{ println(it.isSuccess()) },
98+
{ println(it.cause.toString()) }
99+
)
100+
```
101+
102+
**NOTE:** If the ip check has an error `IpCheckResult.isSuccess()` will be false.
103+

build.gradle

Lines changed: 85 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,85 @@
1+
group 'com.nearsoft'
2+
version '1.0.1'
3+
4+
buildscript {
5+
ext.kotlin_version = '1.2.50'
6+
ext.spek_version = '1.1.5'
7+
ext.ok_http_version = '3.10.0'
8+
ext.retrofit_version = '2.4.0'
9+
ext.rx_java_2_version = '2.1.16'
10+
11+
repositories {
12+
mavenCentral()
13+
}
14+
dependencies {
15+
classpath "org.jetbrains.kotlin:kotlin-gradle-plugin:$kotlin_version"
16+
classpath 'org.junit.platform:junit-platform-gradle-plugin:1.0.0'
17+
}
18+
}
19+
20+
apply plugin: 'kotlin'
21+
apply plugin: 'maven'
22+
apply plugin: 'org.junit.platform.gradle.plugin'
23+
24+
group = 'com.github.epool'
25+
26+
junitPlatform {
27+
filters {
28+
engines {
29+
include 'spek'
30+
}
31+
}
32+
}
33+
34+
repositories {
35+
mavenCentral()
36+
}
37+
38+
dependencies {
39+
testImplementation "org.jetbrains.spek:spek-api:$spek_version"
40+
testRuntime "org.jetbrains.spek:spek-junit-platform-engine:$spek_version"
41+
42+
implementation "org.jetbrains.kotlin:kotlin-stdlib-jdk8:$kotlin_version"
43+
implementation "com.squareup.okhttp3:logging-interceptor:$ok_http_version"
44+
implementation "com.squareup.retrofit2:retrofit:$retrofit_version"
45+
implementation "com.squareup.retrofit2:converter-gson:$retrofit_version"
46+
implementation "com.squareup.retrofit2:adapter-rxjava2:$retrofit_version"
47+
implementation "io.reactivex.rxjava2:rxjava:$rx_java_2_version"
48+
}
49+
50+
compileKotlin {
51+
kotlinOptions.jvmTarget = "1.8"
52+
}
53+
compileTestKotlin {
54+
kotlinOptions.jvmTarget = "1.8"
55+
}
56+
57+
task sourcesJar(type: Jar, dependsOn: classes) {
58+
classifier = 'sources'
59+
from sourceSets.main.allSource
60+
}
61+
62+
task javadocJar(type: Jar, dependsOn: javadoc) {
63+
classifier = 'javadoc'
64+
from javadoc.destinationDir
65+
}
66+
67+
artifacts {
68+
archives sourcesJar
69+
archives javadocJar
70+
}
71+
72+
// To specify a license in the pom:
73+
install {
74+
repositories.mavenInstaller {
75+
pom.project {
76+
licenses {
77+
license {
78+
name 'The Apache Software License, Version 2.0'
79+
url 'http://www.apache.org/licenses/LICENSE-2.0.txt'
80+
distribution 'repo'
81+
}
82+
}
83+
}
84+
}
85+
}

gradle/wrapper/gradle-wrapper.jar

53.1 KB
Binary file not shown.
Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
#Sun Jul 01 14:32:38 CDT 2018
2+
distributionBase=GRADLE_USER_HOME
3+
distributionPath=wrapper/dists
4+
zipStoreBase=GRADLE_USER_HOME
5+
zipStorePath=wrapper/dists
6+
distributionUrl=https\://services.gradle.org/distributions/gradle-4.4-all.zip

0 commit comments

Comments
 (0)