Implemented lastCallResponse property. Closes #2

This commit is contained in:
Erik C. Thauvin 2020-07-31 13:26:09 -07:00
parent 683cb3aa35
commit b12931c6ad
10 changed files with 53 additions and 19 deletions

View file

@ -2,7 +2,7 @@
# clicks # clicks
`@JvmOverloads fun clicks(bitlink: `[`String`](https://kotlinlang.org/api/latest/jvm/stdlib/kotlin/-string/index.html)`, unit: `[`Units`](../-units/index.md)` = Units.DAY, units: `[`Int`](https://kotlinlang.org/api/latest/jvm/stdlib/kotlin/-int/index.html)` = -1, size: `[`Int`](https://kotlinlang.org/api/latest/jvm/stdlib/kotlin/-int/index.html)` = 50, unit_reference: `[`String`](https://kotlinlang.org/api/latest/jvm/stdlib/kotlin/-string/index.html)` = Constants.EMPTY, toJson: `[`Boolean`](https://kotlinlang.org/api/latest/jvm/stdlib/kotlin/-boolean/index.html)` = false): `[`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/Bitlinks.kt#L63) `@Synchronized @JvmOverloads fun clicks(bitlink: `[`String`](https://kotlinlang.org/api/latest/jvm/stdlib/kotlin/-string/index.html)`, unit: `[`Units`](../-units/index.md)` = Units.DAY, units: `[`Int`](https://kotlinlang.org/api/latest/jvm/stdlib/kotlin/-int/index.html)` = -1, size: `[`Int`](https://kotlinlang.org/api/latest/jvm/stdlib/kotlin/-int/index.html)` = 50, unit_reference: `[`String`](https://kotlinlang.org/api/latest/jvm/stdlib/kotlin/-string/index.html)` = Constants.EMPTY, toJson: `[`Boolean`](https://kotlinlang.org/api/latest/jvm/stdlib/kotlin/-boolean/index.html)` = false): `[`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/Bitlinks.kt#L70)
Returns the click counts for a specified Bitlink. Returns the click counts for a specified Bitlink.

View file

@ -2,7 +2,7 @@
# create # create
`@JvmOverloads fun create(domain: `[`String`](https://kotlinlang.org/api/latest/jvm/stdlib/kotlin/-string/index.html)` = Constants.EMPTY, title: `[`String`](https://kotlinlang.org/api/latest/jvm/stdlib/kotlin/-string/index.html)` = Constants.EMPTY, group_guid: `[`String`](https://kotlinlang.org/api/latest/jvm/stdlib/kotlin/-string/index.html)` = Constants.EMPTY, tags: `[`Array`](https://kotlinlang.org/api/latest/jvm/stdlib/kotlin/-array/index.html)`<`[`String`](https://kotlinlang.org/api/latest/jvm/stdlib/kotlin/-string/index.html)`> = emptyArray(), deeplinks: `[`Array`](https://kotlinlang.org/api/latest/jvm/stdlib/kotlin/-array/index.html)`<`[`Map`](https://kotlinlang.org/api/latest/jvm/stdlib/kotlin.collections/-map/index.html)`<`[`String`](https://kotlinlang.org/api/latest/jvm/stdlib/kotlin/-string/index.html)`, `[`String`](https://kotlinlang.org/api/latest/jvm/stdlib/kotlin/-string/index.html)`>> = emptyArray(), long_url: `[`String`](https://kotlinlang.org/api/latest/jvm/stdlib/kotlin/-string/index.html)`, toJson: `[`Boolean`](https://kotlinlang.org/api/latest/jvm/stdlib/kotlin/-boolean/index.html)` = false): `[`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/Bitlinks.kt#L99) `@Synchronized @JvmOverloads fun create(domain: `[`String`](https://kotlinlang.org/api/latest/jvm/stdlib/kotlin/-string/index.html)` = Constants.EMPTY, title: `[`String`](https://kotlinlang.org/api/latest/jvm/stdlib/kotlin/-string/index.html)` = Constants.EMPTY, group_guid: `[`String`](https://kotlinlang.org/api/latest/jvm/stdlib/kotlin/-string/index.html)` = Constants.EMPTY, tags: `[`Array`](https://kotlinlang.org/api/latest/jvm/stdlib/kotlin/-array/index.html)`<`[`String`](https://kotlinlang.org/api/latest/jvm/stdlib/kotlin/-string/index.html)`> = emptyArray(), deeplinks: `[`Array`](https://kotlinlang.org/api/latest/jvm/stdlib/kotlin/-array/index.html)`<`[`Map`](https://kotlinlang.org/api/latest/jvm/stdlib/kotlin.collections/-map/index.html)`<`[`String`](https://kotlinlang.org/api/latest/jvm/stdlib/kotlin/-string/index.html)`, `[`String`](https://kotlinlang.org/api/latest/jvm/stdlib/kotlin/-string/index.html)`>> = emptyArray(), long_url: `[`String`](https://kotlinlang.org/api/latest/jvm/stdlib/kotlin/-string/index.html)`, toJson: `[`Boolean`](https://kotlinlang.org/api/latest/jvm/stdlib/kotlin/-boolean/index.html)` = false): `[`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/Bitlinks.kt#L107)
Converts a long url to a Bitlink and sets additional parameters. Converts a long url to a Bitlink and sets additional parameters.

View file

@ -2,7 +2,7 @@
# expand # expand
`@JvmOverloads fun expand(bitlink_id: `[`String`](https://kotlinlang.org/api/latest/jvm/stdlib/kotlin/-string/index.html)`, toJson: `[`Boolean`](https://kotlinlang.org/api/latest/jvm/stdlib/kotlin/-boolean/index.html)` = false): `[`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/Bitlinks.kt#L137) `@Synchronized @JvmOverloads fun expand(bitlink_id: `[`String`](https://kotlinlang.org/api/latest/jvm/stdlib/kotlin/-string/index.html)`, toJson: `[`Boolean`](https://kotlinlang.org/api/latest/jvm/stdlib/kotlin/-boolean/index.html)` = false): `[`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/Bitlinks.kt#L146)
Expands a Bitlink. Expands a Bitlink.

View file

@ -14,6 +14,12 @@ See the [Bitly API](https://dev.bitly.com/v4/#tag/Bitlinks) for more information
|---|---| |---|---|
| [&lt;init&gt;](-init-.md) | Provides functions to create and manage [Bitlinks](https://dev.bitly.com/v4/#tag/Bitlinks).`Bitlinks(accessToken: `[`String`](https://kotlinlang.org/api/latest/jvm/stdlib/kotlin/-string/index.html)`)` | | [&lt;init&gt;](-init-.md) | Provides functions to create and manage [Bitlinks](https://dev.bitly.com/v4/#tag/Bitlinks).`Bitlinks(accessToken: `[`String`](https://kotlinlang.org/api/latest/jvm/stdlib/kotlin/-string/index.html)`)` |
### Properties
| Name | Summary |
|---|---|
| [lastCallResponse](last-call-response.md) | The last API call response.`var lastCallResponse: `[`CallResponse`](../-call-response/index.md) |
### Functions ### Functions
| Name | Summary | | Name | Summary |

View file

@ -0,0 +1,8 @@
[docs](../../index.md) / [net.thauvin.erik.bitly](../index.md) / [Bitlinks](index.md) / [lastCallResponse](./last-call-response.md)
# lastCallResponse
`var lastCallResponse: `[`CallResponse`](../-call-response/index.md) [(source)](https://github.com/ethauvin/bitly-shorten/tree/master/src/main/kotlin/net/thauvin/erik/bitly/Bitlinks.kt#L51)
The last API call response.

View file

@ -2,7 +2,7 @@
# shorten # shorten
`@JvmOverloads fun shorten(long_url: `[`String`](https://kotlinlang.org/api/latest/jvm/stdlib/kotlin/-string/index.html)`, group_guid: `[`String`](https://kotlinlang.org/api/latest/jvm/stdlib/kotlin/-string/index.html)` = Constants.EMPTY, domain: `[`String`](https://kotlinlang.org/api/latest/jvm/stdlib/kotlin/-string/index.html)` = Constants.EMPTY, toJson: `[`Boolean`](https://kotlinlang.org/api/latest/jvm/stdlib/kotlin/-boolean/index.html)` = false): `[`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/Bitlinks.kt#L185) `@Synchronized @JvmOverloads fun shorten(long_url: `[`String`](https://kotlinlang.org/api/latest/jvm/stdlib/kotlin/-string/index.html)`, group_guid: `[`String`](https://kotlinlang.org/api/latest/jvm/stdlib/kotlin/-string/index.html)` = Constants.EMPTY, domain: `[`String`](https://kotlinlang.org/api/latest/jvm/stdlib/kotlin/-string/index.html)` = Constants.EMPTY, toJson: `[`Boolean`](https://kotlinlang.org/api/latest/jvm/stdlib/kotlin/-boolean/index.html)` = false): `[`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/Bitlinks.kt#L195)
Shortens a long URL. Shortens a long URL.

View file

@ -2,7 +2,7 @@
# update # update
`@JvmOverloads fun update(bitlink: `[`String`](https://kotlinlang.org/api/latest/jvm/stdlib/kotlin/-string/index.html)`, references: `[`Map`](https://kotlinlang.org/api/latest/jvm/stdlib/kotlin.collections/-map/index.html)`<`[`String`](https://kotlinlang.org/api/latest/jvm/stdlib/kotlin/-string/index.html)`, `[`String`](https://kotlinlang.org/api/latest/jvm/stdlib/kotlin/-string/index.html)`> = emptyMap(), archived: `[`Boolean`](https://kotlinlang.org/api/latest/jvm/stdlib/kotlin/-boolean/index.html)` = false, tags: `[`Array`](https://kotlinlang.org/api/latest/jvm/stdlib/kotlin/-array/index.html)`<`[`String`](https://kotlinlang.org/api/latest/jvm/stdlib/kotlin/-string/index.html)`> = emptyArray(), created_at: `[`String`](https://kotlinlang.org/api/latest/jvm/stdlib/kotlin/-string/index.html)` = Constants.EMPTY, title: `[`String`](https://kotlinlang.org/api/latest/jvm/stdlib/kotlin/-string/index.html)` = Constants.EMPTY, deeplinks: `[`Array`](https://kotlinlang.org/api/latest/jvm/stdlib/kotlin/-array/index.html)`<`[`Map`](https://kotlinlang.org/api/latest/jvm/stdlib/kotlin.collections/-map/index.html)`<`[`String`](https://kotlinlang.org/api/latest/jvm/stdlib/kotlin/-string/index.html)`, `[`String`](https://kotlinlang.org/api/latest/jvm/stdlib/kotlin/-string/index.html)`>> = emptyArray(), created_by: `[`String`](https://kotlinlang.org/api/latest/jvm/stdlib/kotlin/-string/index.html)` = Constants.EMPTY, long_url: `[`String`](https://kotlinlang.org/api/latest/jvm/stdlib/kotlin/-string/index.html)` = Constants.EMPTY, client_id: `[`String`](https://kotlinlang.org/api/latest/jvm/stdlib/kotlin/-string/index.html)` = Constants.EMPTY, custom_bitlinks: `[`Array`](https://kotlinlang.org/api/latest/jvm/stdlib/kotlin/-array/index.html)`<`[`String`](https://kotlinlang.org/api/latest/jvm/stdlib/kotlin/-string/index.html)`> = emptyArray(), link: `[`String`](https://kotlinlang.org/api/latest/jvm/stdlib/kotlin/-string/index.html)` = Constants.EMPTY, id: `[`String`](https://kotlinlang.org/api/latest/jvm/stdlib/kotlin/-string/index.html)` = Constants.EMPTY, toJson: `[`Boolean`](https://kotlinlang.org/api/latest/jvm/stdlib/kotlin/-boolean/index.html)` = false): `[`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/Bitlinks.kt#L222) `@Synchronized @JvmOverloads fun update(bitlink: `[`String`](https://kotlinlang.org/api/latest/jvm/stdlib/kotlin/-string/index.html)`, references: `[`Map`](https://kotlinlang.org/api/latest/jvm/stdlib/kotlin.collections/-map/index.html)`<`[`String`](https://kotlinlang.org/api/latest/jvm/stdlib/kotlin/-string/index.html)`, `[`String`](https://kotlinlang.org/api/latest/jvm/stdlib/kotlin/-string/index.html)`> = emptyMap(), archived: `[`Boolean`](https://kotlinlang.org/api/latest/jvm/stdlib/kotlin/-boolean/index.html)` = false, tags: `[`Array`](https://kotlinlang.org/api/latest/jvm/stdlib/kotlin/-array/index.html)`<`[`String`](https://kotlinlang.org/api/latest/jvm/stdlib/kotlin/-string/index.html)`> = emptyArray(), created_at: `[`String`](https://kotlinlang.org/api/latest/jvm/stdlib/kotlin/-string/index.html)` = Constants.EMPTY, title: `[`String`](https://kotlinlang.org/api/latest/jvm/stdlib/kotlin/-string/index.html)` = Constants.EMPTY, deeplinks: `[`Array`](https://kotlinlang.org/api/latest/jvm/stdlib/kotlin/-array/index.html)`<`[`Map`](https://kotlinlang.org/api/latest/jvm/stdlib/kotlin.collections/-map/index.html)`<`[`String`](https://kotlinlang.org/api/latest/jvm/stdlib/kotlin/-string/index.html)`, `[`String`](https://kotlinlang.org/api/latest/jvm/stdlib/kotlin/-string/index.html)`>> = emptyArray(), created_by: `[`String`](https://kotlinlang.org/api/latest/jvm/stdlib/kotlin/-string/index.html)` = Constants.EMPTY, long_url: `[`String`](https://kotlinlang.org/api/latest/jvm/stdlib/kotlin/-string/index.html)` = Constants.EMPTY, client_id: `[`String`](https://kotlinlang.org/api/latest/jvm/stdlib/kotlin/-string/index.html)` = Constants.EMPTY, custom_bitlinks: `[`Array`](https://kotlinlang.org/api/latest/jvm/stdlib/kotlin/-array/index.html)`<`[`String`](https://kotlinlang.org/api/latest/jvm/stdlib/kotlin/-string/index.html)`> = emptyArray(), link: `[`String`](https://kotlinlang.org/api/latest/jvm/stdlib/kotlin/-string/index.html)` = Constants.EMPTY, id: `[`String`](https://kotlinlang.org/api/latest/jvm/stdlib/kotlin/-string/index.html)` = Constants.EMPTY, toJson: `[`Boolean`](https://kotlinlang.org/api/latest/jvm/stdlib/kotlin/-boolean/index.html)` = false): `[`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/Bitlinks.kt#L233)
Updates fields in the Bitlink. Updates fields in the Bitlink.

View file

@ -8,7 +8,7 @@
<modelVersion>4.0.0</modelVersion> <modelVersion>4.0.0</modelVersion>
<groupId>net.thauvin.erik</groupId> <groupId>net.thauvin.erik</groupId>
<artifactId>bitly-shorten</artifactId> <artifactId>bitly-shorten</artifactId>
<version>0.9.2</version> <version>0.9.3</version>
<dependencyManagement> <dependencyManagement>
<dependencies> <dependencies>
<dependency> <dependency>
@ -30,13 +30,13 @@
<dependency> <dependency>
<groupId>com.squareup.okhttp3</groupId> <groupId>com.squareup.okhttp3</groupId>
<artifactId>okhttp</artifactId> <artifactId>okhttp</artifactId>
<version>4.7.2</version> <version>4.8.0</version>
<scope>runtime</scope> <scope>runtime</scope>
</dependency> </dependency>
<dependency> <dependency>
<groupId>com.squareup.okhttp3</groupId> <groupId>com.squareup.okhttp3</groupId>
<artifactId>logging-interceptor</artifactId> <artifactId>logging-interceptor</artifactId>
<version>4.7.2</version> <version>4.8.0</version>
<scope>runtime</scope> <scope>runtime</scope>
</dependency> </dependency>
<dependency> <dependency>

View file

@ -45,6 +45,12 @@ import java.util.logging.Level
* See the [Bitly API](https://dev.bitly.com/v4/#tag/Bitlinks) for more information. * See the [Bitly API](https://dev.bitly.com/v4/#tag/Bitlinks) for more information.
*/ */
open class Bitlinks(private val accessToken: String) { open class Bitlinks(private val accessToken: String) {
/**
* The last API call response.
*/
var lastCallResponse = CallResponse()
private set
/** /**
* Returns the click counts for a specified Bitlink. * Returns the click counts for a specified Bitlink.
* *
@ -59,6 +65,7 @@ open class Bitlinks(private val accessToken: String) {
* @param toJson Returns the full JSON response if `true` * @param toJson Returns the full JSON response if `true`
* @return The click counts or JSON response object. * @return The click counts or JSON response object.
*/ */
@Synchronized
@JvmOverloads @JvmOverloads
fun clicks( fun clicks(
bitlink: String, bitlink: String,
@ -70,7 +77,7 @@ open class Bitlinks(private val accessToken: String) {
): String { ): String {
var clicks = if (toJson) Constants.EMPTY_JSON else Constants.EMPTY var clicks = if (toJson) Constants.EMPTY_JSON else Constants.EMPTY
if (bitlink.isNotBlank()) { if (bitlink.isNotBlank()) {
val response = Utils.call( lastCallResponse = Utils.call(
accessToken, accessToken,
("/bitlinks/${bitlink.removeHttp()}/clicks/summary").toEndPoint(), ("/bitlinks/${bitlink.removeHttp()}/clicks/summary").toEndPoint(),
hashMapOf( hashMapOf(
@ -81,7 +88,7 @@ open class Bitlinks(private val accessToken: String) {
), ),
Methods.GET Methods.GET
) )
clicks = parseJsonResponse(response, "total_clicks", clicks, toJson) clicks = parseJsonResponse(lastCallResponse, "total_clicks", clicks, toJson)
} }
return clicks return clicks
} }
@ -95,6 +102,7 @@ open class Bitlinks(private val accessToken: String) {
* @param toJson Returns the full JSON response if `true` * @param toJson Returns the full JSON response if `true`
* @return The shorten URL or JSON response, or on error, an empty string/JSON object. * @return The shorten URL or JSON response, or on error, an empty string/JSON object.
*/ */
@Synchronized
@JvmOverloads @JvmOverloads
fun create( fun create(
domain: String = Constants.EMPTY, domain: String = Constants.EMPTY,
@ -107,7 +115,7 @@ open class Bitlinks(private val accessToken: String) {
): String { ): String {
var link = if (toJson) Constants.EMPTY_JSON else Constants.EMPTY var link = if (toJson) Constants.EMPTY_JSON else Constants.EMPTY
if (long_url.isNotBlank()) { if (long_url.isNotBlank()) {
val response = Utils.call( lastCallResponse = Utils.call(
accessToken, accessToken,
"/bitlinks".toEndPoint(), "/bitlinks".toEndPoint(),
mutableMapOf<String, Any>(Pair("long_url", long_url)).apply { mutableMapOf<String, Any>(Pair("long_url", long_url)).apply {
@ -119,7 +127,7 @@ open class Bitlinks(private val accessToken: String) {
}, },
Methods.POST Methods.POST
) )
link = parseJsonResponse(response, "link", link, toJson) link = parseJsonResponse(lastCallResponse, "link", link, toJson)
} }
return link return link
} }
@ -133,17 +141,18 @@ open class Bitlinks(private val accessToken: String) {
* @param toJson Returns the full JSON response if `true` * @param toJson Returns the full JSON response if `true`
* @return The long URL or JSON response, or on error, an empty string/JSON object. * @return The long URL or JSON response, or on error, an empty string/JSON object.
*/ */
@Synchronized
@JvmOverloads @JvmOverloads
fun expand(bitlink_id: String, toJson: Boolean = false): String { fun expand(bitlink_id: String, toJson: Boolean = false): String {
var longUrl = if (toJson) Constants.EMPTY_JSON else Constants.EMPTY var longUrl = if (toJson) Constants.EMPTY_JSON else Constants.EMPTY
if (bitlink_id.isNotBlank()) { if (bitlink_id.isNotBlank()) {
val response = Utils.call( lastCallResponse = Utils.call(
accessToken, accessToken,
"/expand".toEndPoint(), "/expand".toEndPoint(),
mapOf(Pair("bitlink_id", bitlink_id.removeHttp())), mapOf(Pair("bitlink_id", bitlink_id.removeHttp())),
Methods.POST Methods.POST
) )
longUrl = parseJsonResponse(response, "long_url", longUrl, toJson) longUrl = parseJsonResponse(lastCallResponse, "long_url", longUrl, toJson)
} }
return longUrl return longUrl
@ -181,6 +190,7 @@ open class Bitlinks(private val accessToken: String) {
* @param toJson Returns the full JSON response if `true` * @param toJson Returns the full JSON response if `true`
* @return The short URL or JSON response, or on error, the [long_url] or an empty JSON object. * @return The short URL or JSON response, or on error, the [long_url] or an empty JSON object.
*/ */
@Synchronized
@JvmOverloads @JvmOverloads
fun shorten( fun shorten(
long_url: String, long_url: String,
@ -201,9 +211,9 @@ open class Bitlinks(private val accessToken: String) {
} }
params["long_url"] = long_url params["long_url"] = long_url
val response = Utils.call(accessToken, "/shorten".toEndPoint(), params) lastCallResponse = Utils.call(accessToken, "/shorten".toEndPoint(), params)
bitlink = parseJsonResponse(response, "link", bitlink, toJson) bitlink = parseJsonResponse(lastCallResponse, "link", bitlink, toJson)
} }
return bitlink return bitlink
@ -218,6 +228,7 @@ open class Bitlinks(private val accessToken: String) {
* @param toJson Returns the full JSON response if `true` * @param toJson Returns the full JSON response if `true`
* @return `true` is the update was successful, `false` otherwise, or JSON response. * @return `true` is the update was successful, `false` otherwise, or JSON response.
*/ */
@Synchronized
@JvmOverloads @JvmOverloads
fun update( fun update(
bitlink: String, bitlink: String,
@ -237,7 +248,7 @@ open class Bitlinks(private val accessToken: String) {
): String { ): String {
var result = if (toJson) Constants.EMPTY_JSON else Constants.FALSE var result = if (toJson) Constants.EMPTY_JSON else Constants.FALSE
if (bitlink.isNotBlank()) { if (bitlink.isNotBlank()) {
val response = Utils.call( lastCallResponse = Utils.call(
accessToken, "/bitlinks/${bitlink.removeHttp()}".toEndPoint(), mutableMapOf<String, Any>().apply { accessToken, "/bitlinks/${bitlink.removeHttp()}".toEndPoint(), mutableMapOf<String, Any>().apply {
if (references.isNotEmpty()) put("references", references) if (references.isNotEmpty()) put("references", references)
if (archived) put("archived", archived) if (archived) put("archived", archived)
@ -255,9 +266,9 @@ open class Bitlinks(private val accessToken: String) {
Methods.PATCH Methods.PATCH
) )
if (response.isSuccessful) { if (lastCallResponse.isSuccessful) {
result = if (toJson) { result = if (toJson) {
response.body lastCallResponse.body
} else { } else {
Constants.TRUE Constants.TRUE
} }

View file

@ -123,6 +123,15 @@ class BitlyTest {
assertEquals(longUrl, Bitlinks(bitly.accessToken).expand(shortUrl)) assertEquals(longUrl, Bitlinks(bitly.accessToken).expand(shortUrl))
} }
@Test
fun `bitlinks lastCallResponse`() {
val bl = Bitlinks(bitly.accessToken)
bl.shorten(longUrl, domain="bit.ly")
assertEquals(true, bl.lastCallResponse.isSuccessful, "is successful")
assertEquals(200, bl.lastCallResponse.resultCode, "resultCode == 200")
assertTrue(bl.lastCallResponse.body.contains("\"link\":\"$shortUrl\""), "valid body")
}
@Test @Test
fun `clicks summary`() { fun `clicks summary`() {
assertNotEquals(Constants.EMPTY, bitly.bitlinks().clicks(shortUrl)) assertNotEquals(Constants.EMPTY, bitly.bitlinks().clicks(shortUrl))