package com.alwaysallthetime.adnlib.response;

import com.alwaysallthetime.adnlib.AppDotNetResponseException;
import com.alwaysallthetime.adnlib.data.IAppDotNetObject;
import com.alwaysallthetime.adnlib.data.ResponseEnvelope;
import com.google.gson.reflect.TypeToken;

import java.io.Reader;
import java.net.HttpURLConnection;

public abstract class AppDotNetResponseEnvelopeHandler<T extends IAppDotNetObject> extends AppDotNetResponseHandler<T> {
    protected AppDotNetResponseEnvelopeHandler(TypeToken<ResponseEnvelope<T>> typeToken) {
        super(typeToken);
    }

    @Override
    public void handleResponse(Reader reader) {
        final ResponseEnvelope<T> response = parseResponse(reader);
        final int status = response.getMeta().getCode();
        if (status != HttpURLConnection.HTTP_OK) {
            onError(new AppDotNetResponseException(response.getMeta()));
        } else {
            onSuccess(response.getData());
        }
    }
}
@@ -219,16 +219,70 @@
 velope;%0A
+import com.alwaysallthetime.adnlib.data.ResponseMeta;%0A
 import c
@@ -496,16 +496,58 @@
 er%3CT%3E %7B%0A
+    protected ResponseMeta responseMeta;%0A%0A
     prot
@@ -804,24 +804,20 @@
     
-final int status
+responseMeta
  = r
@@ -837,19 +837,10 @@
 ta()
-.getCode()
 ;
+%0A
 %0A   
@@ -852,14 +852,30 @@
 if (
-status
+responseMeta.getCode()
  != 
@@ -962,26 +962,20 @@
 response
-.get
 Meta
-()
 ));%0A    
@@ -1045,10 +1045,502 @@
  %7D%0A    %7D
+%0A%0A    public ResponseMeta getResponseMeta() %7B%0A        return responseMeta;%0A    %7D%0A%0A    public String getMaxId() %7B%0A        if (responseMeta == null)%0A            return null;%0A%0A        return responseMeta.getMaxId();%0A    %7D%0A%0A    public String getMinId() %7B%0A        if (responseMeta == null)%0A            return null;%0A%0A        return responseMeta.getMinId();%0A    %7D%0A%0A    public boolean isMore() %7B%0A        if (responseMeta == null)%0A            return false;%0A%0A        return responseMeta.isMore();%0A    %7D
 %0A%7D

add accessors for pagination metadata