Removed toJson() in CallResponse.
This commit is contained in:
parent
353927580d
commit
8060f856ee
9 changed files with 28 additions and 26 deletions
|
@ -64,7 +64,10 @@ bitly.bitlinks().shorten("https://www.erik.thauvin.net/blog", toJson = true)
|
||||||
Non-implemented methods can also be called directly:
|
Non-implemented methods can also be called directly:
|
||||||
|
|
||||||
```kotlin
|
```kotlin
|
||||||
bitly.call("/user".toEndPoint(), method = Methods.GET).toJson()
|
val response = bitly.call("/user".toEndPoint(), method = Methods.GET)
|
||||||
|
if (response.isSuccessful) {
|
||||||
|
println(response.body)
|
||||||
|
}
|
||||||
```
|
```
|
||||||
```json
|
```json
|
||||||
{
|
{
|
||||||
|
@ -87,5 +90,5 @@ bitly.call("/user".toEndPoint(), method = Methods.GET).toJson()
|
||||||
```
|
```
|
||||||
- View [Example](https://github.com/ethauvin/bitly-shorten/blob/master/examples/src/main/kotlin/com/example/BitlyRetrieve.kt)
|
- View [Example](https://github.com/ethauvin/bitly-shorten/blob/master/examples/src/main/kotlin/com/example/BitlyRetrieve.kt)
|
||||||
|
|
||||||
### More
|
### More...
|
||||||
If all else fails, there's always more [Documentation](https://ethauvin.github.io/bitly-shorten/).
|
If all else fails, there's always more [Documentation](https://ethauvin.github.io/bitly-shorten/).
|
||||||
|
|
|
@ -2,4 +2,4 @@
|
||||||
|
|
||||||
# body
|
# body
|
||||||
|
|
||||||
`var body: `[`String`](https://kotlinlang.org/api/latest/jvm/stdlib/kotlin/-string/index.html) [(source)](https://github.com/ethauvin/bitly-shorten/tree/master/src/main/kotlin/net/thauvin/erik/bitly/CallResponse.kt#L40)
|
`var body: `[`String`](https://kotlinlang.org/api/latest/jvm/stdlib/kotlin/-string/index.html) [(source)](https://github.com/ethauvin/bitly-shorten/tree/master/src/main/kotlin/net/thauvin/erik/bitly/CallResponse.kt#L38)
|
|
@ -2,7 +2,7 @@
|
||||||
|
|
||||||
# CallResponse
|
# CallResponse
|
||||||
|
|
||||||
`data class CallResponse` [(source)](https://github.com/ethauvin/bitly-shorten/tree/master/src/main/kotlin/net/thauvin/erik/bitly/CallResponse.kt#L40)
|
`data class CallResponse` [(source)](https://github.com/ethauvin/bitly-shorten/tree/master/src/main/kotlin/net/thauvin/erik/bitly/CallResponse.kt#L38)
|
||||||
|
|
||||||
Provides a data class to hold the JSON response.
|
Provides a data class to hold the JSON response.
|
||||||
|
|
||||||
|
@ -19,9 +19,3 @@ Provides a data class to hold the JSON response.
|
||||||
| [body](body.md) | `var body: `[`String`](https://kotlinlang.org/api/latest/jvm/stdlib/kotlin/-string/index.html) |
|
| [body](body.md) | `var body: `[`String`](https://kotlinlang.org/api/latest/jvm/stdlib/kotlin/-string/index.html) |
|
||||||
| [isSuccessful](is-successful.md) | `val isSuccessful: `[`Boolean`](https://kotlinlang.org/api/latest/jvm/stdlib/kotlin/-boolean/index.html) |
|
| [isSuccessful](is-successful.md) | `val isSuccessful: `[`Boolean`](https://kotlinlang.org/api/latest/jvm/stdlib/kotlin/-boolean/index.html) |
|
||||||
| [resultCode](result-code.md) | `var resultCode: `[`Int`](https://kotlinlang.org/api/latest/jvm/stdlib/kotlin/-int/index.html) |
|
| [resultCode](result-code.md) | `var resultCode: `[`Int`](https://kotlinlang.org/api/latest/jvm/stdlib/kotlin/-int/index.html) |
|
||||||
|
|
||||||
### Functions
|
|
||||||
|
|
||||||
| Name | Summary |
|
|
||||||
|---|---|
|
|
||||||
| [toJson](to-json.md) | `fun toJson(): JSONObject` |
|
|
||||||
|
|
|
@ -2,4 +2,4 @@
|
||||||
|
|
||||||
# isSuccessful
|
# isSuccessful
|
||||||
|
|
||||||
`val isSuccessful: `[`Boolean`](https://kotlinlang.org/api/latest/jvm/stdlib/kotlin/-boolean/index.html) [(source)](https://github.com/ethauvin/bitly-shorten/tree/master/src/main/kotlin/net/thauvin/erik/bitly/CallResponse.kt#L41)
|
`val isSuccessful: `[`Boolean`](https://kotlinlang.org/api/latest/jvm/stdlib/kotlin/-boolean/index.html) [(source)](https://github.com/ethauvin/bitly-shorten/tree/master/src/main/kotlin/net/thauvin/erik/bitly/CallResponse.kt#L39)
|
|
@ -2,4 +2,4 @@
|
||||||
|
|
||||||
# resultCode
|
# resultCode
|
||||||
|
|
||||||
`var resultCode: `[`Int`](https://kotlinlang.org/api/latest/jvm/stdlib/kotlin/-int/index.html) [(source)](https://github.com/ethauvin/bitly-shorten/tree/master/src/main/kotlin/net/thauvin/erik/bitly/CallResponse.kt#L40)
|
`var resultCode: `[`Int`](https://kotlinlang.org/api/latest/jvm/stdlib/kotlin/-int/index.html) [(source)](https://github.com/ethauvin/bitly-shorten/tree/master/src/main/kotlin/net/thauvin/erik/bitly/CallResponse.kt#L38)
|
|
@ -4,8 +4,8 @@ import net.thauvin.erik.bitly.Bitly;
|
||||||
|
|
||||||
public class BitlySample {
|
public class BitlySample {
|
||||||
public static void main(String[] args) {
|
public static void main(String[] args) {
|
||||||
final Bitly bitly = new Bitly(/* "YOUR_API_TOKEN from https://bitly.is/accesstoken" */);
|
|
||||||
if (args.length > 0) {
|
if (args.length > 0) {
|
||||||
|
final Bitly bitly = new Bitly(/* "YOUR_API_TOKEN from https://bitly.is/accesstoken" */);
|
||||||
for (final String arg : args) {
|
for (final String arg : args) {
|
||||||
if (arg.contains("bit.ly")) {
|
if (arg.contains("bit.ly")) {
|
||||||
System.out.println(arg + " <-- " + bitly.bitlinks().expand(arg));
|
System.out.println(arg + " <-- " + bitly.bitlinks().expand(arg));
|
||||||
|
|
|
@ -3,16 +3,23 @@ package com.example
|
||||||
import net.thauvin.erik.bitly.Bitly
|
import net.thauvin.erik.bitly.Bitly
|
||||||
import net.thauvin.erik.bitly.Methods
|
import net.thauvin.erik.bitly.Methods
|
||||||
import net.thauvin.erik.bitly.Utils.Companion.toEndPoint
|
import net.thauvin.erik.bitly.Utils.Companion.toEndPoint
|
||||||
|
import org.json.JSONObject
|
||||||
import kotlin.system.exitProcess
|
import kotlin.system.exitProcess
|
||||||
|
|
||||||
fun main() {
|
fun main() {
|
||||||
val bitly = Bitly(/* "YOUR_API_ACCESS_TOKEN from https://bitly.is/accesstoken" */)
|
val bitly = Bitly(/* "YOUR_API_ACCESS_TOKEN from https://bitly.is/accesstoken" */)
|
||||||
|
|
||||||
val json = bitly.call("/bitlinks/bit.ly/380ojFd".toEndPoint(), method = Methods.GET).toJson()
|
// See https://dev.bitly.com/v4/#operation/getBitlink
|
||||||
|
val response = bitly.call("/bitlinks/bit.ly/380ojFd".toEndPoint(), method = Methods.GET)
|
||||||
|
|
||||||
println("Bitlink is titled : " + json.getString("title"))
|
if (response.isSuccessful) {
|
||||||
println("Bitlink created by: " + json.getString("created_by"))
|
val json = JSONObject(response.body)
|
||||||
|
println("Title : " + json.getString("title"))
|
||||||
|
println("URL : " + json.getString("long_url"))
|
||||||
|
println("By : " + json.getString("created_by"))
|
||||||
|
} else {
|
||||||
|
println("Invalid Response: ${response.resultCode}")
|
||||||
|
}
|
||||||
|
|
||||||
exitProcess(0)
|
exitProcess(0)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -32,16 +32,10 @@
|
||||||
|
|
||||||
package net.thauvin.erik.bitly
|
package net.thauvin.erik.bitly
|
||||||
|
|
||||||
import org.json.JSONObject
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Provides a data class to hold the JSON response.
|
* Provides a data class to hold the JSON response.
|
||||||
*/
|
*/
|
||||||
data class CallResponse(var body: String = Constants.EMPTY_JSON, var resultCode: Int = -1) {
|
data class CallResponse(var body: String = Constants.EMPTY_JSON, var resultCode: Int = -1) {
|
||||||
val isSuccessful: Boolean
|
val isSuccessful: Boolean
|
||||||
get() = resultCode in 200..299
|
get() = resultCode in 200..299
|
||||||
|
|
||||||
fun toJson(): JSONObject {
|
|
||||||
return JSONObject(body)
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
|
@ -34,6 +34,7 @@ package net.thauvin.erik.bitly
|
||||||
|
|
||||||
import net.thauvin.erik.bitly.Utils.Companion.removeHttp
|
import net.thauvin.erik.bitly.Utils.Companion.removeHttp
|
||||||
import net.thauvin.erik.bitly.Utils.Companion.toEndPoint
|
import net.thauvin.erik.bitly.Utils.Companion.toEndPoint
|
||||||
|
import org.json.JSONObject
|
||||||
import org.junit.Before
|
import org.junit.Before
|
||||||
import java.io.File
|
import java.io.File
|
||||||
import java.util.logging.Level
|
import java.util.logging.Level
|
||||||
|
@ -103,9 +104,12 @@ class BitlyTest {
|
||||||
fun `created by`() {
|
fun `created by`() {
|
||||||
assertEquals(
|
assertEquals(
|
||||||
"ethauvin",
|
"ethauvin",
|
||||||
bitly.call("/bitlinks/${shortUrl.removeHttp()}".toEndPoint(), method = Methods.GET)
|
JSONObject(
|
||||||
.toJson()
|
bitly.call(
|
||||||
.getString("created_by")
|
"/bitlinks/${shortUrl.removeHttp()}".toEndPoint(),
|
||||||
|
method = Methods.GET
|
||||||
|
).body
|
||||||
|
).getString("created_by")
|
||||||
)
|
)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue