List of usage examples for com.squareup.okhttp OkHttpClient OkHttpClient
public OkHttpClient()
From source file:com.squareup.picasso.OkHttpDownloader.java
License:Apache License
private static OkHttpClient defaultOkHttpClient() { OkHttpClient client = new OkHttpClient(); client.setConnectTimeout(Utils.DEFAULT_CONNECT_TIMEOUT_MILLIS, TimeUnit.MILLISECONDS); client.setReadTimeout(Utils.DEFAULT_READ_TIMEOUT_MILLIS, TimeUnit.MILLISECONDS); client.setWriteTimeout(Utils.DEFAULT_WRITE_TIMEOUT_MILLIS, TimeUnit.MILLISECONDS); return client; }
From source file:com.squareup.picasso.OkHttpDownloaderWithSetting.java
License:Apache License
/** * Create new downloader that uses OkHttp. This will install an image cache into your application * cache directory.//ww w . j ava 2s . c om * * @param cacheDir The directory in which the cache should be stored * @param maxSize The size limit for the cache. */ public OkHttpDownloaderWithSetting(final File cacheDir, final long maxSize) { this(new OkHttpClient()); try { urlFactory.client().setCache(new com.squareup.okhttp.Cache(cacheDir, maxSize)); } catch (IOException ignored) { } }
From source file:com.startechup.tools.http.SSLHttpStack.java
License:Apache License
public SSLHttpStack(InputStream inputClientKey, InputStream inputTrustKey) { mInputClientKey = inputClientKey;//from w w w . j a v a 2 s .c o m mInputTrustKey = inputTrustKey; OkHttpClient okHttpClient = new OkHttpClient(); okHttpClient.setSslSocketFactory(createSSLContext().getSocketFactory()); okHttpClient.setHostnameVerifier(new HostnameVerifier() { @Override public boolean verify(String hostname, SSLSession session) { // I have to override this method or our mutual SSL authentication will fail. return true; } }); mOkUrlFactory = new OkUrlFactory(okHttpClient); }
From source file:com.stockbrowser.search.OpenSearchSearchEngine.java
License:Apache License
public OpenSearchSearchEngine(Context context, SearchEngineInfo searchEngineInfo) { mSearchEngineInfo = searchEngineInfo; // mHttpClient = AndroidHttpClient.newInstance(USER_AGENT); // HttpParams params = mHttpClient.getParams(); // params.setLongParameter(HTTP_TIMEOUT, HTTP_TIMEOUT_MS); mOkHttpClient = new OkHttpClient(); mOkHttpClient.setConnectTimeout(HTTP_TIMEOUT_MS, TimeUnit.MILLISECONDS); }
From source file:com.supremainc.biostar2.sdk.volley.toolbox.OkHttpStack.java
License:Apache License
public OkHttpStack(CookieManager cookieManager) { this(new OkHttpClient(), cookieManager); }
From source file:com.survivingwithandroid.ubiapp.UbidotsClient.java
License:Apache License
public void handleUbidots(String varId, String apiKey, final UbiListener listener) { final List<Value> results = new ArrayList<>(); OkHttpClient client = new OkHttpClient(); Request req = new Request.Builder().addHeader("X-Auth-Token", apiKey) .url("http://things.ubidots.com/api/v1.6/variables/" + varId + "/values").build(); client.newCall(req).enqueue(new Callback() { @Override//from w w w .j a v a 2s . c o m public void onFailure(Request request, IOException e) { Log.d("Chart", "Network error"); e.printStackTrace(); } @Override public void onResponse(Response response) throws IOException { String body = response.body().string(); Log.d("Chart", body); try { JSONObject jObj = new JSONObject(body); JSONArray jRes = jObj.getJSONArray("results"); for (int i = 0; i < jRes.length(); i++) { JSONObject obj = jRes.getJSONObject(i); Value val = new Value(); val.timestamp = obj.getLong("timestamp"); val.value = (float) obj.getDouble("value"); results.add(val); } listener.onDataReady(results); } catch (JSONException jse) { jse.printStackTrace(); } } }); }
From source file:com.thanksmister.btcblue.data.api.ApiModule.java
License:Apache License
@Provides @Singleton// w w w. j a v a2 s . c o m Client provideClient(OkHttpClient client) { client = new OkHttpClient(); client.setConnectTimeout(30, TimeUnit.SECONDS); // connect timeout client.setReadTimeout(30, TimeUnit.SECONDS); // socket timeout client.setConnectionPool(new ConnectionPool(0, 5 * 60 * 1000)); return new OkClient(client); }
From source file:com.thanksmister.btcblue.data.DataModule.java
License:Apache License
static OkHttpClient createOkHttpClient(BaseApplication app) { OkHttpClient client = new OkHttpClient(); // Install an HTTP cache in the application cache directory. try {//from ww w . jav a 2s .c o m File cacheDir = new File(app.getCacheDir(), "http"); Cache cache = new Cache(cacheDir, DISK_CACHE_SIZE); client.setCache(cache); } catch (Exception e) { Timber.e(e, "Unable to install disk cache."); } return client; }
From source file:com.tinder.picassowebp.picasso.OkHttpDownloader.java
License:Apache License
/** * Create new downloader that uses OkHttp. This will install an image cache into your application * cache directory.//from www . j ava 2s . c o m * * @param cacheDir The directory in which the cache should be stored * @param maxSize The size limit for the cache. */ public OkHttpDownloader(final File cacheDir, final long maxSize) { this(new OkHttpClient()); try { client.setResponseCache(new HttpResponseCache(cacheDir, maxSize)); } catch (IOException ignored) { } }
From source file:com.tr8n.core.HttpClient.java
License:Open Source License
/** * Instantiates and return OkHttp Client * @return//from w w w . j ava 2 s .c o m */ private OkHttpClient getOkHttpClient() { if (client == null) { client = new OkHttpClient(); } return client; }