andriangungon
9/6/2018 - 4:12 PM

retrofit parse array

private void getAdmakerImage() {
        AdMakerImageInterface apiService = APIClient.getClient().create(AdMakerImageInterface.class);
        Call<AdMakerImageResponse> call = apiService.getResults(Helper.getAuthToken());
        call.enqueue(new Callback<AdMakerImageResponse>() {
            @Override
            public void onResponse(Call<AdMakerImageResponse> call, final Response<AdMakerImageResponse> response) {

                if (response.isSuccessful()) {
                    try {
                        final AdMakerImageAPI image = response.body().getMessage();
                        Picasso.with(context).load(image.getImage_file_url()).into(makeAd, new com.squareup.picasso.Callback(){
                            @Override
                            public void onSuccess() {

                            }

                            @Override
                            public void onError() {
                                Toast.makeText(context, "There's an error fetching the Ad Maker Image.", Toast.LENGTH_SHORT).show();
                            }
                        });

                    } catch (Throwable e) {
                        Log.e(TAG, "Error (Throwable): " + e.getMessage());
                    }


                } else {
                    if (response.code() == 401) {
                        Log.d(TAG, "Profile 401");
                    }
                    Log.e(TAG, "Profile Retrofit Failed: " + response.message());
                }

            }

            @Override
            public void onFailure(Call<AdMakerImageResponse> call, Throwable t) {
                Log.d(TAG, "getAdmakerImage() error: " + t.getMessage());
            }

        });
    }
package com.ixm.app.prototype.networking.adMakerImage;

import com.google.gson.annotations.Expose;
import com.google.gson.annotations.SerializedName;

import java.util.ArrayList;

public class AdMakerImageAPI {

    @SerializedName("id")
    @Expose private String id;

    @SerializedName("image_file_url")
    @Expose private String image_file_url;

    public String getId() {
        return id;
    }

    public void setId(String id) {
        this.id = id;
    }

    public String getImage_file_url() {
        return image_file_url;
    }

    public void setImage_file_url(String image_file_url) {
        this.image_file_url = image_file_url;
    }
}
package com.ixm.app.prototype.networking.adMakerImage;

import com.google.gson.annotations.Expose;
import com.google.gson.annotations.SerializedName;

import java.util.ArrayList;
import java.util.List;

/**
 * Created by andriangungon on 1/7/17.
 */

public class AdMakerImageResponse {

    @SerializedName("status")
    @Expose private String status;

    @SerializedName("message")
    @Expose private AdMakerImageAPI message;

    public String getStatus() {
        return status;
    }

    public void setStatus(String status) {
        this.status = status;
    }

    public AdMakerImageAPI getMessage() {
        return message;
    }

    public void setMessage(AdMakerImageAPI message) {
        this.message = message;
    }
}