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;
}
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));
}
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();
}
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;
}
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);
}
}));
}
Aggregations