Search in sources :

Example 1 with MenigaScheduledReimbursement

use of com.meniga.sdk.models.offers.redemptions.MenigaScheduledReimbursement in project mobile-sdk-android by meniga.

the class MenigaRedemptionConverter method responseBodyConverter.

@Override
public Converter<ResponseBody, ?> responseBodyConverter(Type type, Annotation[] annotations, Retrofit retrofit) {
    Type typeOfRedemptions = new TypeToken<MenigaRedemptions>() {
    }.getType();
    if (typeOfRedemptions.equals(type)) {
        return new Converter<ResponseBody, MenigaRedemptions>() {

            @Override
            public MenigaRedemptions convert(ResponseBody resBody) throws IOException {
                InputStreamReader isr = new InputStreamReader(resBody.byteStream());
                JsonElement element;
                try {
                    element = new JsonParser().parse(isr);
                } finally {
                    isr.close();
                }
                Gson gson = GsonProvider.getGsonBuilder();
                MenigaRedemptions page = gson.fromJson(getAsArray(element), MenigaRedemptions.class);
                JsonObject object = element.getAsJsonObject();
                JsonObject meta = object.getAsJsonObject("meta");
                List<MenigaScheduledReimbursement> cashBackRaw = gson.fromJson(meta.getAsJsonArray("scheduledReimbursements"), new TypeToken<List<MenigaScheduledReimbursement>>() {
                }.getType());
                MenigaRedemptions main = MenigaConverter.mergeMeta(gson, page, meta);
                main.setScheduledReimbursement(cashBackRaw);
                return main;
            }
        };
    }
    return null;
}
Also used : InputStreamReader(java.io.InputStreamReader) MenigaScheduledReimbursement(com.meniga.sdk.models.offers.redemptions.MenigaScheduledReimbursement) Gson(com.google.gson.Gson) JsonObject(com.google.gson.JsonObject) MenigaRedemptions(com.meniga.sdk.models.offers.redemptions.MenigaRedemptions) ResponseBody(okhttp3.ResponseBody) Type(java.lang.reflect.Type) JsonElement(com.google.gson.JsonElement) TypeToken(com.google.gson.reflect.TypeToken) Converter(retrofit2.Converter) JsonParser(com.google.gson.JsonParser)

Aggregations

Gson (com.google.gson.Gson)1 JsonElement (com.google.gson.JsonElement)1 JsonObject (com.google.gson.JsonObject)1 JsonParser (com.google.gson.JsonParser)1 TypeToken (com.google.gson.reflect.TypeToken)1 MenigaRedemptions (com.meniga.sdk.models.offers.redemptions.MenigaRedemptions)1 MenigaScheduledReimbursement (com.meniga.sdk.models.offers.redemptions.MenigaScheduledReimbursement)1 InputStreamReader (java.io.InputStreamReader)1 Type (java.lang.reflect.Type)1 ResponseBody (okhttp3.ResponseBody)1 Converter (retrofit2.Converter)1