Example usage for com.squareup.okhttp CertificatePinner.Builder CertificatePinner.Builder

List of usage examples for com.squareup.okhttp CertificatePinner.Builder CertificatePinner.Builder

Introduction

In this page you can find the example usage for com.squareup.okhttp CertificatePinner.Builder CertificatePinner.Builder.

Prototype

CertificatePinner.Builder

Source Link

Usage

From source file:com.mycelium.wallet.external.cashila.api.CashilaService.java

License:Microsoft Reference Source License

public CashilaService(String baseUrl, String apiVersion, Bus eventBus) {
    this.baseUrl = baseUrl;
    this.eventBus = eventBus;

    OkHttpClient client = new OkHttpClient();
    client.setConnectTimeout(5000, TimeUnit.MILLISECONDS);
    client.setReadTimeout(5000, TimeUnit.MILLISECONDS);
    client.networkInterceptors().add(hmacInterceptor);
    CertificatePinner certPinner = new CertificatePinner.Builder().add("cashila.com", CASHILA_CERT)
            .add("cashila-staging.com", CASHILA_CERT).build();
    client.setCertificatePinner(certPinner);

    // use jackson as json mapper, as we already use it in the rest of the project
    objectMapper = new ObjectMapper();
    objectMapper.configure(DeserializationFeature.FAIL_ON_UNKNOWN_PROPERTIES, false);
    objectMapper.setPropertyNamingStrategy(PropertyNamingStrategy.CAMEL_CASE_TO_LOWER_CASE_WITH_UNDERSCORES);
    objectMapper.registerModule(new WapiJsonModule());

    RestAdapter adapter = new RestAdapter.Builder().setEndpoint(baseUrl + apiVersion + "/")
            .setLogLevel(RestAdapter.LogLevel.BASIC)
            //.setLogLevel(RestAdapter.LogLevel.FULL)
            .setConverter(new JacksonConverter(objectMapper)).setClient(new OkClient(client))
            .setRequestInterceptor(apiIdInterceptor).build();

    cashila = adapter.create(Cashila.class);

    // initialise nonce with current time and increase by one on each call
    lastNonce = System.currentTimeMillis();
}