package com.github.zouzhberk.essence.rxweather;

import retrofit2.Retrofit;
import retrofit2.adapter.rxjava.RxJavaCallAdapterFactory;
import retrofit2.converter.jackson.JacksonConverterFactory;

/**
 * Created by berk (zouzhberk@163.com)) on 3/23/16.
 */
public class RxWeather {
    private final Retrofit retrofit;
    private String baseUrl;

    public static class Builder {
        private String baseUrl;


        public static Builder baseUrl(String baseUrl) {
            Builder builder = new Builder();
            builder.baseUrl = baseUrl;
            return builder;
        }

        public RxWeather build() {
            RxWeather we = new RxWeather();
            we.baseUrl = baseUrl;
            return we;
        }
    }

    private RxWeather() {
        retrofit = new Retrofit.Builder().addConverterFactory
                (JacksonConverterFactory
                        .create())
                .baseUrl(baseUrl == null ? "http://api.heweather.com/" : null)
                .addCallAdapterFactory(RxJavaCallAdapterFactory.create())
                .build();
    }

    public <T> T create(Class<T> featureApi) {
        return retrofit.create(featureApi);
    }

}

@@ -42,16 +42,45 @@
 ather;%0A%0A
+import okhttp3.OkHttpClient;%0A
 import r
@@ -217,16 +217,444 @@
 ctory;%0A%0A
+import javax.net.ssl.SSLContext;%0Aimport javax.net.ssl.TrustManagerFactory;%0Aimport java.io.IOException;%0Aimport java.io.InputStream;%0Aimport java.security.KeyManagementException;%0Aimport java.security.KeyStore;%0Aimport java.security.KeyStoreException;%0Aimport java.security.NoSuchAlgorithmException;%0Aimport java.security.cert.Certificate;%0Aimport java.security.cert.CertificateException;%0Aimport java.security.cert.CertificateFactory;%0A%0A
 /**%0A * C
@@ -1192,24 +1192,1221 @@
    %7D%0A    %7D%0A%0A
+    public OkHttpClient getSSLHttpClient() %7B%0A%0A        OkHttpClient.Builder okHttpClientBuilder = new OkHttpClient.Builder();%0A        try %7B%0A            CertificateFactory cf = CertificateFactory.getInstance(%22X.509%22);%0A            InputStream instream = getClass().getResourceAsStream(%22api.heweather.com.crt%22);%0A            Certificate ca;%0A            ca = cf.generateCertificate(instream);%0A            KeyStore kStore = KeyStore.getInstance(KeyStore.getDefaultType());%0A            kStore.load(null, null);%0A            kStore.setCertificateEntry(%22ca%22, ca);%0A            TrustManagerFactory tmf = TrustManagerFactory.getInstance(TrustManagerFactory.getDefaultAlgorithm());%0A            tmf.init(kStore);%0A            SSLContext sslContext = SSLContext.getInstance(%22TLS%22);%0A            sslContext.init(null, tmf.getTrustManagers(), null);%0A            okHttpClientBuilder.sslSocketFactory(sslContext.getSocketFactory());%0A        %7D catch (CertificateException%0A                %7C KeyStoreException%0A                %7C NoSuchAlgorithmException%0A                %7C IOException%0A                %7C KeyManagementException e) %7B%0A            e.printStackTrace();%0A        %7D%0A        return okHttpClientBuilder.build();%0A    %7D%0A%0A
     private 
@@ -2461,16 +2461,43 @@
 ilder().
+client(getSSLHttpClient()).
 addConve

update custom configuration.