// Path: androidsdk/src/main/java/com/wootric/androidsdk/network/WootricApiCallback.java
// public interface WootricApiCallback {
//     void onAuthenticateSuccess(String accessToken);
//     void onGetEndUserIdSuccess(long endUserId);
//     void onEndUserNotFound();
//     void onCreateEndUserSuccess(long endUserId);
//     void onApiError(Exception error);
// }
// 
// Path: androidsdk/src/main/java/com/wootric/androidsdk/utils/Utils.java
// public final class Utils {
// 
//     private Utils(){}
// 
//     public static <T> T checkNotNull(T object, String objectDescription) {
//         if(object == null) {
//             throw new IllegalArgumentException(objectDescription + " must not be null");
//         }
// 
//         return object;
//     }
// 
//     public static boolean isNotEmpty(String s) {
//         return s != null && !s.isEmpty() && !isWhitespaceString(s);
//     }
// 
//     public static boolean isBlank(String s) {
//         return s == null || (s != null && (s.isEmpty() || isWhitespaceString(s)));
//     }
// 
//     private static boolean isWhitespaceString(String s) {
//         return s.trim().length() == 0;
//     }
// 
//     public static void checkDate(long date) {
//         if (date > 9999999999L) {
//             Log.d(Constants.TAG, "WARNING: The created date exceeds the maximum 10 characters allowed. " +
//                     "If you are using System.currentTimeMillis() divide it by 1000.");
//         } else {
//             Date d = new Date(date * 1000L);
//             Date now = new Date();
//             if (d.after(now)){
//                 Log.d(Constants.TAG, "WARNING: The created date is on the future");
//             }
//         }
//     }
// 
//     public static byte getByteValue(Boolean bool) {
//         if (bool != null) {
//             return bool ? (byte) 1 : (byte) 0;
//         } else {
//             return (byte) 0;
//         }
//     }
// 
//     public static boolean startsWithEU(String aString) {
//         return aString.startsWith("NPS-EU");
//     }
// }


import java.io.IOException;
import java.io.InputStream;
import java.io.UnsupportedEncodingException;
import java.net.HttpURLConnection;
import java.net.URL;
import java.util.HashMap;
import java.util.Map;
import android.net.Uri;
import android.os.AsyncTask;
import android.os.Build;
import android.util.Log;
import com.wootric.androidsdk.BuildConfig;
import com.wootric.androidsdk.network.WootricApiCallback;
import com.wootric.androidsdk.utils.Utils;
/*
 * Copyright (c) 2016 Wootric (https://wootric.com)
 *
 * Permission is hereby granted, free of charge, to any person obtaining a copy
 * of this software and associated documentation files (the "Software"), to deal
 * in the Software without restriction, including without limitation the rights
 * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
 * copies of the Software, and to permit persons to whom the Software is
 * furnished to do so, subject to the following conditions:
 *
 * The above copyright notice and this permission notice shall be included in
 * all copies or substantial portions of the Software.
 *
 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
 * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
 * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
 * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
 * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
 * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
 * THE SOFTWARE.
 */

package com.wootric.androidsdk.network.tasks;




/**
 * Created by maciejwitowski on 10/13/15.
 */
public abstract class WootricRemoteRequestTask extends AsyncTask<Void, Void, String> {
    private static final String HTTP_AGENT = "Wootric-Mobile-SDK";

    static final String REQUEST_TYPE_POST = "POST";
    static final String REQUEST_TYPE_PUT = "PUT";
    static final String REQUEST_TYPE_GET = "GET";

    protected static final String API_ENDPOINT = "https://api.wootric.com";
    protected static final String SURVEY_ENDPOINT = "https://survey.wootric.com";
    protected static final String EU_API_ENDPOINT = "https://app.wootric.eu";
    protected static final String EU_SURVEY_ENDPOINT = "https://eligibility.wootric.eu";
    protected static final String END_USERS_PATH = "/api/v1/end_users";
    protected static final String OAUTH_PATH = "/oauth/token";
    protected static final String ELIGIBLE_PATH = "/eligible.json";
    protected static final String REGISTERED_EVENTS_PATH = "/registered_events.json";

    private final String requestType;
    private final String accessToken;
    private final String accountToken;
    protected final WootricApiCallback wootricApiCallback;
    protected final HashMap<String, String> paramsMap;


    public WootricRemoteRequestTask(String requestType, String accessToken, String accountToken, WootricApiCallback wootricApiCallback) {
        this.requestType = requestType;
        this.accessToken = accessToken;
        this.accountToken = accountToken;
        this.wootricApiCallback = wootricApiCallback;
        this.paramsMap = new HashMap<>();
    }

// Path: androidsdk/src/main/java/com/wootric/androidsdk/network/WootricApiCallback.java
// public interface WootricApiCallback {
//     void onAuthenticateSuccess(String accessToken);
//     void onGetEndUserIdSuccess(long endUserId);
//     void onEndUserNotFound();
//     void onCreateEndUserSuccess(long endUserId);
//     void onApiError(Exception error);
// }
// 
// Path: androidsdk/src/main/java/com/wootric/androidsdk/utils/Utils.java
// public final class Utils {
// 
//     private Utils(){}
// 
//     public static <T> T checkNotNull(T object, String objectDescription) {
//         if(object == null) {
//             throw new IllegalArgumentException(objectDescription + " must not be null");
//         }
// 
//         return object;
//     }
// 
//     public static boolean isNotEmpty(String s) {
//         return s != null && !s.isEmpty() && !isWhitespaceString(s);
//     }
// 
//     public static boolean isBlank(String s) {
//         return s == null || (s != null && (s.isEmpty() || isWhitespaceString(s)));
//     }
// 
//     private static boolean isWhitespaceString(String s) {
//         return s.trim().length() == 0;
//     }
// 
//     public static void checkDate(long date) {
//         if (date > 9999999999L) {
//             Log.d(Constants.TAG, "WARNING: The created date exceeds the maximum 10 characters allowed. " +
//                     "If you are using System.currentTimeMillis() divide it by 1000.");
//         } else {
//             Date d = new Date(date * 1000L);
//             Date now = new Date();
//             if (d.after(now)){
//                 Log.d(Constants.TAG, "WARNING: The created date is on the future");
//             }
//         }
//     }
// 
//     public static byte getByteValue(Boolean bool) {
//         if (bool != null) {
//             return bool ? (byte) 1 : (byte) 0;
//         } else {
//             return (byte) 0;
//         }
//     }
// 
//     public static boolean startsWithEU(String aString) {
//         return aString.startsWith("NPS-EU");
//     }
// }


// Path: androidsdk/src/main/java/com/wootric/androidsdk/network/tasks/WootricRemoteRequestTask.java
import java.io.IOException;
import java.io.InputStream;
import java.io.UnsupportedEncodingException;
import java.net.HttpURLConnection;
import java.net.URL;
import java.util.HashMap;
import java.util.Map;
import android.net.Uri;
import android.os.AsyncTask;
import android.os.Build;
import android.util.Log;
import com.wootric.androidsdk.BuildConfig;
import com.wootric.androidsdk.network.WootricApiCallback;
import com.wootric.androidsdk.utils.Utils;

/*
 * Copyright (c) 2016 Wootric (https://wootric.com)
 *
 * Permission is hereby granted, free of charge, to any person obtaining a copy
 * of this software and associated documentation files (the "Software"), to deal
 * in the Software without restriction, including without limitation the rights
 * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
 * copies of the Software, and to permit persons to whom the Software is
 * furnished to do so, subject to the following conditions:
 *
 * The above copyright notice and this permission notice shall be included in
 * all copies or substantial portions of the Software.
 *
 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
 * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
 * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
 * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
 * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
 * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
 * THE SOFTWARE.
 */

package com.wootric.androidsdk.network.tasks;




/**
 * Created by maciejwitowski on 10/13/15.
 */
public abstract class WootricRemoteRequestTask extends AsyncTask<Void, Void, String> {
    private static final String HTTP_AGENT = "Wootric-Mobile-SDK";

    static final String REQUEST_TYPE_POST = "POST";
    static final String REQUEST_TYPE_PUT = "PUT";
    static final String REQUEST_TYPE_GET = "GET";

    protected static final String API_ENDPOINT = "https://api.wootric.com";
    protected static final String SURVEY_ENDPOINT = "https://survey.wootric.com";
    protected static final String EU_API_ENDPOINT = "https://app.wootric.eu";
    protected static final String EU_SURVEY_ENDPOINT = "https://eligibility.wootric.eu";
    protected static final String END_USERS_PATH = "/api/v1/end_users";
    protected static final String OAUTH_PATH = "/oauth/token";
    protected static final String ELIGIBLE_PATH = "/eligible.json";
    protected static final String REGISTERED_EVENTS_PATH = "/registered_events.json";

    private final String requestType;
    private final String accessToken;
    private final String accountToken;
    protected final WootricApiCallback wootricApiCallback;
    protected final HashMap<String, String> paramsMap;


    public WootricRemoteRequestTask(String requestType, String accessToken, String accountToken, WootricApiCallback wootricApiCallback) {
        this.requestType = requestType;
        this.accessToken = accessToken;
        this.accountToken = accountToken;
        this.wootricApiCallback = wootricApiCallback;
        this.paramsMap = new HashMap<>();
    }

    @Override