/*
 * Copyright 2012 Yu AOKI
 */

package com.aokyu.dev.pocket;

import java.util.Set;

import org.json.JSONException;
import org.json.JSONObject;

import com.aokyu.dev.pocket.http.HttpParameters;
import com.aokyu.dev.pocket.util.JSONUtils;

public class Response {

    public interface Parameter extends ResponseParameter {

        public static final String STATUS = "status";

    }

    private HttpParameters mParameters = new HttpParameters();

    protected Response(JSONObject jsonObj) throws JSONException {
        if (jsonObj != null) {
            String[] keys = JSONUtils.getKeys(jsonObj);
            int size = keys.length;
            for (int i = 0; i < size; i++) {
                String key = keys[i];
                Object value = jsonObj.get(key);
                put(key, value);
            }
        }
    }

    protected Response(JSONObject jsonObj, String rootKey) throws JSONException {
        JSONObject obj = jsonObj.getJSONObject(rootKey);
        if (obj != null) {
            String[] keys = JSONUtils.getKeys(obj);
            int size = keys.length;
            for (int i = 0; i < size; i++) {
                String key = keys[i];
                Object value = obj.get(key);
                put(key, value);
            }
        }
    }

    /* package */ void put(String key, Object value) {
        mParameters.put(key, value);
    }

    public Set<String> keySet() {
        return mParameters.keySet();
    }

    public int size() {
        return mParameters.size();
    }

    public Object get(String key) {
        return mParameters.get(key);
    }

    public boolean containsKey(String key) {
        return mParameters.containsKey(key);
    }

}

@@ -378,24 +378,566 @@
 s%22;%0A%0A    %7D%0A%0A
+    public enum Status %7B%0A        FAILED(0),%0A        SUCCEEDED(1);%0A%0A        private int mStatus;%0A%0A        private Status(int status) %7B%0A            mStatus = status;%0A        %7D%0A%0A        public int intValue() %7B%0A            return mStatus;%0A        %7D%0A%0A        public static Status valueOf(int value) %7B%0A            Status%5B%5D statuses = values();%0A            for (Status status : statuses) %7B%0A                if (status.intValue() == value) %7B%0A                    return status;%0A                %7D%0A            %7D%0A            return null;%0A        %7D%0A    %7D%0A%0A
     private 
@@ -2239,10 +2239,255 @@
 %0A    %7D%0A%0A
+    public Status getStatus() %7B%0A        if (containsKey(Parameter.STATUS)) %7B%0A            int status = (Integer) get(Parameter.STATUS);%0A            return Status.valueOf(status);%0A        %7D else %7B%0A            return Status.FAILED;%0A        %7D%0A    %7D%0A
 %7D%0A

Add a method to Response class for getting the status