This repository has been archived by the owner on Jun 16, 2019. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 11
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
ec69a99
commit 77c45ab
Showing
7 changed files
with
77 additions
and
6 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
6 changes: 6 additions & 0 deletions
6
library/src/main/java/com/afollestad/iconrequest/remote/ApiResponse.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,6 @@ | ||
package com.afollestad.iconrequest.remote | ||
|
||
data class ApiResponse( | ||
var status: String = "success", | ||
var error: String? = null | ||
) |
42 changes: 42 additions & 0 deletions
42
library/src/main/java/com/afollestad/iconrequest/remote/ApiTypeAdapter.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,42 @@ | ||
package com.afollestad.iconrequest.remote | ||
|
||
import com.google.gson.TypeAdapter | ||
import com.google.gson.stream.JsonReader | ||
import com.google.gson.stream.JsonWriter | ||
import java.io.IOException | ||
|
||
class ApiTypeAdapter : TypeAdapter<ApiResponse>() { | ||
companion object { | ||
private const val KEY_STATUS = "status" | ||
private const val KEY_ERROR = "error" | ||
} | ||
|
||
@Throws(IOException::class) | ||
override fun write( | ||
out: JsonWriter, | ||
value: ApiResponse | ||
) { | ||
out.beginObject() | ||
out.name(KEY_STATUS) | ||
.value(value.status) | ||
out.name(KEY_ERROR) | ||
.value(value.error) | ||
out.endObject() | ||
} | ||
|
||
@Throws(IOException::class) | ||
override fun read(input: JsonReader): ApiResponse? { | ||
input.beginObject() | ||
var status = "success" | ||
var error: String? = null | ||
while (input.hasNext()) { | ||
val next = input.nextString() | ||
when (next) { | ||
"status" -> status = next | ||
"error" -> error = next | ||
} | ||
} | ||
input.endObject() | ||
return ApiResponse(status = status, error = error) | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters