// Path: sthlmtraveling/src/main/java/com/markupartist/sthlmtraveling/data/misc/HttpHelper.java
// public class HttpHelper {
//     static final int DISK_CACHE_SIZE = 50 * 1024 * 1024; // 50MB
//     private static HttpHelper sInstance;
//     OkHttpClient mClient;
// 
//     private HttpHelper(final Context context) {
//         mClient = new OkHttpClient();
//         mClient.setConnectTimeout(15, TimeUnit.SECONDS);
//         mClient.setReadTimeout(15, TimeUnit.SECONDS);
//         installHttpCache(context);
//     }
// 
//     public static HttpHelper getInstance(final Context context) {
//         if (sInstance == null) {
//             sInstance = new HttpHelper(context);
//         }
//         return sInstance;
//     }
// 
//     /**
//      * Install an HTTP cache in the application cache directory.
//      */
//     private void installHttpCache(final Context context) {
//         // Install an HTTP cache in the application cache directory.
//         try {
//             // Install an HTTP cache in the application cache directory.
//             File cacheDir = new File(context.getCacheDir(), "http");
//             Cache cache = new Cache(cacheDir, DISK_CACHE_SIZE);
//             mClient.setCache(cache);
//         } catch (Throwable e) {
//             Log.e("HttpHelper", "Unable to install disk cache.");
//         }
//     }
// 
//     public Request createRequest(final String endpoint) throws IOException {
//         return new Request.Builder()
//                 .get()
//                 .url(endpoint)
//                 .addHeader("X-STHLMTraveling-API-Key", ApiConf.get(ApiConf.KEY))
//                 .header("User-Agent", AppConfig.USER_AGENT)
//                 .build();
//     }
// 
//     public OkHttpClient getClient() {
//         return mClient;
//     }
// 
// }
// 
// Path: sthlmtraveling/src/main/java/com/markupartist/sthlmtraveling/provider/ApiConf.java
// public static String apiEndpoint2() {
//     return AppConfig.STHLM_TRAVELING_API_ENDPOINT;
// }


import android.content.Context;
import android.text.format.Time;
import android.util.Log;
import android.util.TimeFormatException;
import com.markupartist.sthlmtraveling.data.misc.HttpHelper;
import com.squareup.okhttp.Response;
import org.json.JSONArray;
import org.json.JSONException;
import org.json.JSONObject;
import java.io.IOException;
import java.util.ArrayList;
import java.util.regex.Matcher;
import java.util.regex.Pattern;
import static com.markupartist.sthlmtraveling.provider.ApiConf.apiEndpoint2;
                    created.parse(jsonDeviation.getString("created"));

                    Deviation deviation = new Deviation();
                    deviation.setCreated(created);
                    deviation.setDetails(stripNewLinesAtTheEnd(jsonDeviation.getString("description")));
                    deviation.setHeader(jsonDeviation.getString("header"));
                    //deviation.setLink(jsonDeviation.getString("link"));
                    //deviation.setMessageVersion(jsonDeviation.getInt("messageVersion"));
                    deviation.setReference(jsonDeviation.getLong("reference"));
                    deviation.setScope(jsonDeviation.getString("scope"));
                    deviation.setScopeElements(jsonDeviation.getString("scope_elements"));
                    //deviation.setSortOrder(jsonDeviation.getInt("sortOrder"));

                    deviations.add(deviation);
                } catch (TimeFormatException e) {
                    e.printStackTrace();
                } catch (JSONException e) {
                    e.printStackTrace();
                }
            }
        } catch (JSONException e) {
            e.printStackTrace();
        }

        return deviations;
    }

    private String retrieveDeviations(final Context context) throws IOException {
        final String endpoint = apiEndpoint2() + "v1/deviation/";

// Path: sthlmtraveling/src/main/java/com/markupartist/sthlmtraveling/data/misc/HttpHelper.java
// public class HttpHelper {
//     static final int DISK_CACHE_SIZE = 50 * 1024 * 1024; // 50MB
//     private static HttpHelper sInstance;
//     OkHttpClient mClient;
// 
//     private HttpHelper(final Context context) {
//         mClient = new OkHttpClient();
//         mClient.setConnectTimeout(15, TimeUnit.SECONDS);
//         mClient.setReadTimeout(15, TimeUnit.SECONDS);
//         installHttpCache(context);
//     }
// 
//     public static HttpHelper getInstance(final Context context) {
//         if (sInstance == null) {
//             sInstance = new HttpHelper(context);
//         }
//         return sInstance;
//     }
// 
//     /**
//      * Install an HTTP cache in the application cache directory.
//      */
//     private void installHttpCache(final Context context) {
//         // Install an HTTP cache in the application cache directory.
//         try {
//             // Install an HTTP cache in the application cache directory.
//             File cacheDir = new File(context.getCacheDir(), "http");
//             Cache cache = new Cache(cacheDir, DISK_CACHE_SIZE);
//             mClient.setCache(cache);
//         } catch (Throwable e) {
//             Log.e("HttpHelper", "Unable to install disk cache.");
//         }
//     }
// 
//     public Request createRequest(final String endpoint) throws IOException {
//         return new Request.Builder()
//                 .get()
//                 .url(endpoint)
//                 .addHeader("X-STHLMTraveling-API-Key", ApiConf.get(ApiConf.KEY))
//                 .header("User-Agent", AppConfig.USER_AGENT)
//                 .build();
//     }
// 
//     public OkHttpClient getClient() {
//         return mClient;
//     }
// 
// }
// 
// Path: sthlmtraveling/src/main/java/com/markupartist/sthlmtraveling/provider/ApiConf.java
// public static String apiEndpoint2() {
//     return AppConfig.STHLM_TRAVELING_API_ENDPOINT;
// }


// Path: sthlmtraveling/src/main/java/com/markupartist/sthlmtraveling/provider/deviation/DeviationStore.java
import android.content.Context;
import android.text.format.Time;
import android.util.Log;
import android.util.TimeFormatException;
import com.markupartist.sthlmtraveling.data.misc.HttpHelper;
import com.squareup.okhttp.Response;
import org.json.JSONArray;
import org.json.JSONException;
import org.json.JSONObject;
import java.io.IOException;
import java.util.ArrayList;
import java.util.regex.Matcher;
import java.util.regex.Pattern;
import static com.markupartist.sthlmtraveling.provider.ApiConf.apiEndpoint2;

                    created.parse(jsonDeviation.getString("created"));

                    Deviation deviation = new Deviation();
                    deviation.setCreated(created);
                    deviation.setDetails(stripNewLinesAtTheEnd(jsonDeviation.getString("description")));
                    deviation.setHeader(jsonDeviation.getString("header"));
                    //deviation.setLink(jsonDeviation.getString("link"));
                    //deviation.setMessageVersion(jsonDeviation.getInt("messageVersion"));
                    deviation.setReference(jsonDeviation.getLong("reference"));
                    deviation.setScope(jsonDeviation.getString("scope"));
                    deviation.setScopeElements(jsonDeviation.getString("scope_elements"));
                    //deviation.setSortOrder(jsonDeviation.getInt("sortOrder"));

                    deviations.add(deviation);
                } catch (TimeFormatException e) {
                    e.printStackTrace();
                } catch (JSONException e) {
                    e.printStackTrace();
                }
            }
        } catch (JSONException e) {
            e.printStackTrace();
        }

        return deviations;
    }

    private String retrieveDeviations(final Context context) throws IOException {
        final String endpoint = apiEndpoint2() + "v1/deviation/";

        HttpHelper httpHelper = HttpHelper.getInstance(context);