Search in sources :

Example 11 with OkHttpClient

use of com.squareup.okhttp.OkHttpClient in project Android-CleanArchitecture by android10.

the class ApiConnection method createClient.

private OkHttpClient createClient() {
    final OkHttpClient okHttpClient = new OkHttpClient();
    okHttpClient.setReadTimeout(10000, TimeUnit.MILLISECONDS);
    okHttpClient.setConnectTimeout(15000, TimeUnit.MILLISECONDS);
    return okHttpClient;
}
Also used : OkHttpClient(com.squareup.okhttp.OkHttpClient)

Example 12 with OkHttpClient

use of com.squareup.okhttp.OkHttpClient in project MusicDNA by harjot-oberai.

the class ViewLyrics method search.

private static ArrayList<Lyrics> search(String searchQuery) throws IOException, ParserConfigurationException, SAXException, NoSuchAlgorithmException {
    OkHttpClient client = new OkHttpClient();
    client.setConnectTimeout(10, TimeUnit.SECONDS);
    client.setReadTimeout(30, TimeUnit.SECONDS);
    RequestBody body = RequestBody.create(MediaType.parse("application/text"), assembleQuery(searchQuery.getBytes("UTF-8")));
    Request request = new Request.Builder().header("User-Agent", clientUserAgent).post(body).url(url).build();
    Response response = client.newCall(request).execute();
    BufferedReader rd = new BufferedReader(new InputStreamReader(response.body().byteStream(), "ISO_8859_1"));
    // Get full result
    StringBuilder builder = new StringBuilder();
    char[] buffer = new char[8192];
    int read;
    while ((read = rd.read(buffer, 0, buffer.length)) > 0) {
        builder.append(buffer, 0, read);
    }
    String full = builder.toString();
    // Decrypt, parse, store, and return the result list
    return parseResultXML(decryptResultXML(full));
}
Also used : Response(com.squareup.okhttp.Response) OkHttpClient(com.squareup.okhttp.OkHttpClient) InputStreamReader(java.io.InputStreamReader) Request(com.squareup.okhttp.Request) BufferedReader(java.io.BufferedReader) RequestBody(com.squareup.okhttp.RequestBody)

Example 13 with OkHttpClient

use of com.squareup.okhttp.OkHttpClient in project MusicDNA by harjot-oberai.

the class Net method getUrlAsString.

public static String getUrlAsString(URL paramURL) throws IOException {
    Request request = new Request.Builder().header("User-Agent", USER_AGENT).url(paramURL).build();
    OkHttpClient client = new OkHttpClient();
    client.setConnectTimeout(10, TimeUnit.SECONDS);
    Response response = client.newCall(request).execute();
    return response.body().string();
}
Also used : Response(com.squareup.okhttp.Response) OkHttpClient(com.squareup.okhttp.OkHttpClient) Request(com.squareup.okhttp.Request)

Example 14 with OkHttpClient

use of com.squareup.okhttp.OkHttpClient in project weex-example by KalicyZhou.

the class WXOkHttpDispatcher method defaultOkHttpClient.

private static OkHttpClient defaultOkHttpClient() {
    OkHttpClient client = new OkHttpClient();
    client.setConnectTimeout(DEFAULT_CONNECT_TIMEOUT_MILLIS, TimeUnit.MILLISECONDS);
    client.setReadTimeout(DEFAULT_READ_TIMEOUT_MILLIS, TimeUnit.MILLISECONDS);
    client.setWriteTimeout(DEFAULT_WRITE_TIMEOUT_MILLIS, TimeUnit.MILLISECONDS);
    return client;
}
Also used : OkHttpClient(com.squareup.okhttp.OkHttpClient)

Example 15 with OkHttpClient

use of com.squareup.okhttp.OkHttpClient in project wh-app-android by WhiteHouse.

the class FeedManager method updateFeedFromServer.

public static void updateFeedFromServer(String url, String title, String viewType) {
    final BehaviorSubject<Observable<List<FeedItem>>> subject;
    final OkHttpClient client = getClient();
    final Request request = getBaseRequest().url(url).get().build();
    if (sFeedItemsSubject.get(url) == null) {
        sFeedItemsSubject.put(url, BehaviorSubject.create());
    }
    subject = sFeedItemsSubject.get(url);
    subject.onNext(Observable.create((Subscriber<? super List<FeedItem>> op) -> {
        Response response;
        try {
            response = client.newCall(request).execute();
            if (response.code() >= 400) {
                op.onError(new IOException("Response code " + Integer.toString(response.code())));
            } else {
                SAXParser parser = SAXParserFactory.newInstance().newSAXParser();
                FeedHandler handler = new FeedHandler(title, viewType);
                parser.parse(response.body().byteStream(), handler);
                op.onNext(handler.getFeedItems());
            }
            op.onCompleted();
        } catch (Exception e) {
            op.onError(e);
        }
    }));
}
Also used : Response(com.squareup.okhttp.Response) OkHttpClient(com.squareup.okhttp.OkHttpClient) FeedItem(gov.whitehouse.data.model.FeedItem) FeedHandler(gov.whitehouse.core.FeedHandler) Request(com.squareup.okhttp.Request) SAXParser(javax.xml.parsers.SAXParser) IOException(java.io.IOException) Observable(rx.Observable) IOException(java.io.IOException) FileNotFoundException(java.io.FileNotFoundException)

Aggregations

OkHttpClient (com.squareup.okhttp.OkHttpClient)47 Request (com.squareup.okhttp.Request)22 Response (com.squareup.okhttp.Response)18 IOException (java.io.IOException)15 RequestBody (com.squareup.okhttp.RequestBody)8 Provides (dagger.Provides)6 Gson (com.google.gson.Gson)5 Cache (com.squareup.okhttp.Cache)5 Singleton (javax.inject.Singleton)5 SpringAndroidSpiceRequest (com.octo.android.robospice.request.springandroid.SpringAndroidSpiceRequest)4 File (java.io.File)4 RestAdapter (retrofit.RestAdapter)4 OkClient (retrofit.client.OkClient)4 SSLContext (javax.net.ssl.SSLContext)3 X509TrustManager (javax.net.ssl.X509TrustManager)3 HttpResponse (org.apache.http.HttpResponse)3 Intent (android.content.Intent)2 SharedPreferences (android.content.SharedPreferences)2 Call (com.squareup.okhttp.Call)2 Dispatcher (com.squareup.okhttp.Dispatcher)2