Created
September 1, 2019 05:30
-
-
Save mitchtabian/0e033be2c61ed05e93b5718e765f4f67 to your computer and use it in GitHub Desktop.
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
interface ApiService { | |
@GET("android-code-test/feed.json") | |
fun getFeedItems(): Call<List<FeedItem>> | |
} |
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
data class FeedItem( | |
@Expose | |
@SerializedName("task_id") | |
val task_id: Int, | |
@Expose | |
@SerializedName("profile_id") | |
val profile_id: Int, | |
@Expose | |
@SerializedName("text") | |
val task_text: String?, | |
@Expose | |
@SerializedName("created_at") | |
val created_at: String?, | |
@Expose | |
@SerializedName("event") | |
val event: String? | |
){ | |
override fun toString(): String { | |
return "FeedItem(task_id=$task_id, profile_id=$profile_id, task_text=$task_text, created_at=$created_at, event=$event)" | |
} | |
} |
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
apiService.getFeedItems().enqueue(object: Callback<List<FeedItem>>{ | |
override fun onFailure(call: Call<List<FeedItem>>, t: Throwable) { | |
println("DEBUG: ${t.message}") | |
println("DEBUG: ${call.request().body()}") | |
} | |
override fun onResponse( | |
call: Call<List<FeedItem>>, | |
response: Response<List<FeedItem>> | |
) { | |
println("DEBUG: ${response.code()}") | |
println("DEBUG: ${call.request().url()}") | |
println("DEBUG: ${call.request().body().toString()}") | |
println("DEBUG: ${response.raw().body().toString()}") | |
println("DEBUG: ${response.body().toString()}") | |
println("DEBUG: ${response.errorBody().toString()}") | |
for(item in response.body().orEmpty()){ | |
println("DEBUG: ${item}") | |
} | |
} | |
}) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment