Skip to content

Instantly share code, notes, and snippets.

@mitchtabian
Created September 1, 2019 05:30
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save mitchtabian/0e033be2c61ed05e93b5718e765f4f67 to your computer and use it in GitHub Desktop.
Save mitchtabian/0e033be2c61ed05e93b5718e765f4f67 to your computer and use it in GitHub Desktop.
interface ApiService {
@GET("android-code-test/feed.json")
fun getFeedItems(): Call<List<FeedItem>>
}
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)"
}
}
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