// Path: src/main/java/com/cardinity/Cardinity.java
// public abstract class Cardinity {
// 
//     public static final String API_BASE = "https://api.cardinity.com";
//     public static final String API_VERSION = "v1";
//     public static final String VERSION = "0.1";
//     public static final String ENCODING_CHARSET = "UTF-8";
// 
// }
// 
// Path: src/main/java/com/cardinity/exceptions/CardinityClientException.java
// public class CardinityClientException extends CardinityException {
// 
//     private static final long serialVersionUID = 5273072716090618133L;
// 
//     public CardinityClientException(String message) {
//         super(message);
//     }
// }
// 
// Path: src/main/java/com/cardinity/model/CardinityError.java
// public class CardinityError {
// 
//     private String type;
//     private String title;
//     private Integer status;
//     private String detail;
//     private Set<ErrorItem> errors;
// 
//     public String getType() {
//         return type;
//     }
// 
//     public String getTitle() {
//         return title;
//     }
// 
//     public Integer getStatus() {
//         return status;
//     }
// 
//     public String getDetail() {
//         return detail;
//     }
// 
//     public Set<ErrorItem> getErrorItems() {
//         return errors;
//     }
// 
// }
// 
// Path: src/main/java/com/cardinity/model/Response.java
// public class Response {
// 
//     private final Integer code;
//     private final String body;
// 
//     public Response(Integer code, String body) {
//         this.code = code;
//         this.body = body;
//     }
// 
//     public Integer getCode() {
//         return code;
//     }
// 
//     public String getBody() {
//         return body;
//     }
// }
// 
// Path: src/main/java/com/cardinity/model/Result.java
// public class Result<T> {
// 
//     private T item;
//     private CardinityError cardinityError;
// 
//     public Result(T item) {
//         this.item = item;
//     }
// 
//     public Result(CardinityError cardinityError) {
//         this.cardinityError = cardinityError;
//     }
// 
//     public T getItem() {
//         return item;
//     }
// 
//     public CardinityError getCardinityError() {
//         return cardinityError;
//     }
// 
//     public boolean isValid() {
//         return item != null;
//     }
// }
// 
// Path: src/main/java/com/cardinity/oauth/OAuthProvider.java
// public interface OAuthProvider {
// 
//     String buildAuthorizationHeader(RestResource.RequestMethod requestMethod, String requestUrl) throws
//             GeneralSecurityException, UnsupportedEncodingException;
// 
//     String buildAuthorizationHeader(RestResource.RequestMethod requestMethod, String requestUrl, Map<String, String>
//             params) throws
//             GeneralSecurityException, UnsupportedEncodingException;
// 
// }
// 
// Path: src/main/java/com/cardinity/rest/RestResource.java
// public enum RequestMethod {
//     GET, PATCH, POST
// }


import com.cardinity.Cardinity;
import com.cardinity.exceptions.CardinityClientException;
import com.cardinity.model.CardinityError;
import com.cardinity.model.Response;
import com.cardinity.model.Result;
import com.cardinity.oauth.OAuthProvider;
import com.cardinity.rest.RestResource.RequestMethod;
import com.google.gson.reflect.TypeToken;
import java.io.IOException;
import java.io.InputStream;
import java.io.OutputStream;
import java.io.UnsupportedEncodingException;
import java.lang.reflect.Field;
import java.net.HttpURLConnection;
import java.net.ProtocolException;
import java.net.URL;
import java.security.GeneralSecurityException;
import java.util.HashMap;
import java.util.Map;
import java.util.Scanner;
    public <T> Result<T> sendRequest(RequestMethod method, String url, TypeToken<T> clazz, Map<String, String> params) {
        boolean methodGet = method == RequestMethod.GET;
        return _sendRequest(method, url, clazz, methodGet ? null : params, methodGet ? params : null);
    }

    private <T> Result<T> _sendRequest(RequestMethod method, String url, TypeToken<T> clazz, Object requestObject,
            Map<String, String> params) {

        Response response = getResponse(method, url, requestObject, params);

        int responseCode = response.getCode();
        String responseBody = response.getBody();

        Result<T> result;

        if (responseCode < 200 || (responseCode >= 300 && responseCode != 402))
            result = new Result<T>(RestResource.GSON.fromJson(responseBody, CardinityError.class));
        else {
            T resultObject = RestResource.GSON.fromJson(responseBody, clazz.getType());
            result = new Result<T>(resultObject);
        }

        return result;
    }

    private Response getResponse(RequestMethod method, String url, Object requestObject, Map<String, String> params) {
        HttpURLConnection conn = null;

        try {
            switch (method) {
// Path: src/main/java/com/cardinity/Cardinity.java
// public abstract class Cardinity {
// 
//     public static final String API_BASE = "https://api.cardinity.com";
//     public static final String API_VERSION = "v1";
//     public static final String VERSION = "0.1";
//     public static final String ENCODING_CHARSET = "UTF-8";
// 
// }
// 
// Path: src/main/java/com/cardinity/exceptions/CardinityClientException.java
// public class CardinityClientException extends CardinityException {
// 
//     private static final long serialVersionUID = 5273072716090618133L;
// 
//     public CardinityClientException(String message) {
//         super(message);
//     }
// }
// 
// Path: src/main/java/com/cardinity/model/CardinityError.java
// public class CardinityError {
// 
//     private String type;
//     private String title;
//     private Integer status;
//     private String detail;
//     private Set<ErrorItem> errors;
// 
//     public String getType() {
//         return type;
//     }
// 
//     public String getTitle() {
//         return title;
//     }
// 
//     public Integer getStatus() {
//         return status;
//     }
// 
//     public String getDetail() {
//         return detail;
//     }
// 
//     public Set<ErrorItem> getErrorItems() {
//         return errors;
//     }
// 
// }
// 
// Path: src/main/java/com/cardinity/model/Response.java
// public class Response {
// 
//     private final Integer code;
//     private final String body;
// 
//     public Response(Integer code, String body) {
//         this.code = code;
//         this.body = body;
//     }
// 
//     public Integer getCode() {
//         return code;
//     }
// 
//     public String getBody() {
//         return body;
//     }
// }
// 
// Path: src/main/java/com/cardinity/model/Result.java
// public class Result<T> {
// 
//     private T item;
//     private CardinityError cardinityError;
// 
//     public Result(T item) {
//         this.item = item;
//     }
// 
//     public Result(CardinityError cardinityError) {
//         this.cardinityError = cardinityError;
//     }
// 
//     public T getItem() {
//         return item;
//     }
// 
//     public CardinityError getCardinityError() {
//         return cardinityError;
//     }
// 
//     public boolean isValid() {
//         return item != null;
//     }
// }
// 
// Path: src/main/java/com/cardinity/oauth/OAuthProvider.java
// public interface OAuthProvider {
// 
//     String buildAuthorizationHeader(RestResource.RequestMethod requestMethod, String requestUrl) throws
//             GeneralSecurityException, UnsupportedEncodingException;
// 
//     String buildAuthorizationHeader(RestResource.RequestMethod requestMethod, String requestUrl, Map<String, String>
//             params) throws
//             GeneralSecurityException, UnsupportedEncodingException;
// 
// }
// 
// Path: src/main/java/com/cardinity/rest/RestResource.java
// public enum RequestMethod {
//     GET, PATCH, POST
// }


// Path: src/main/java/com/cardinity/rest/CardinityRestClient.java
import com.cardinity.Cardinity;
import com.cardinity.exceptions.CardinityClientException;
import com.cardinity.model.CardinityError;
import com.cardinity.model.Response;
import com.cardinity.model.Result;
import com.cardinity.oauth.OAuthProvider;
import com.cardinity.rest.RestResource.RequestMethod;
import com.google.gson.reflect.TypeToken;
import java.io.IOException;
import java.io.InputStream;
import java.io.OutputStream;
import java.io.UnsupportedEncodingException;
import java.lang.reflect.Field;
import java.net.HttpURLConnection;
import java.net.ProtocolException;
import java.net.URL;
import java.security.GeneralSecurityException;
import java.util.HashMap;
import java.util.Map;
import java.util.Scanner;

    public <T> Result<T> sendRequest(RequestMethod method, String url, TypeToken<T> clazz, Map<String, String> params) {
        boolean methodGet = method == RequestMethod.GET;
        return _sendRequest(method, url, clazz, methodGet ? null : params, methodGet ? params : null);
    }

    private <T> Result<T> _sendRequest(RequestMethod method, String url, TypeToken<T> clazz, Object requestObject,
            Map<String, String> params) {

        Response response = getResponse(method, url, requestObject, params);

        int responseCode = response.getCode();
        String responseBody = response.getBody();

        Result<T> result;

        if (responseCode < 200 || (responseCode >= 300 && responseCode != 402))
            result = new Result<T>(RestResource.GSON.fromJson(responseBody, CardinityError.class));
        else {
            T resultObject = RestResource.GSON.fromJson(responseBody, clazz.getType());
            result = new Result<T>(resultObject);
        }

        return result;
    }

    private Response getResponse(RequestMethod method, String url, Object requestObject, Map<String, String> params) {
        HttpURLConnection conn = null;

        try {
            switch (method) {
                case GET: