Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
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
You can’t perform that action at this time.