use of okhttp3.HttpUrl in project zipkin by openzipkin.
the class ZipkinDispatcherTest method toQueryRequest_parseAnnotations.
@Test
public void toQueryRequest_parseAnnotations() {
HttpUrl url = baseUrl.newBuilder().addQueryParameter("serviceName", "zipkin-server").addQueryParameter("annotationQuery", "error and finagle.timeout").build();
QueryRequest request = ZipkinDispatcher.toQueryRequest(url);
assertThat(request.annotations).containsExactly(Constants.ERROR, "finagle.timeout");
}
use of okhttp3.HttpUrl in project Pokemap by omkarmoghe.
the class GoogleManager method refreshToken.
public void refreshToken(String refreshToken, final RefreshListener listener) {
HttpUrl url = HttpUrl.parse(OAUTH_TOKEN_ENDPOINT).newBuilder().addQueryParameter("client_id", CLIENT_ID).addQueryParameter("client_secret", SECRET).addQueryParameter("refresh_token", refreshToken).addQueryParameter("grant_type", "refresh_token").build();
Callback<GoogleService.TokenResponse> googleCallback = new Callback<GoogleService.TokenResponse>() {
@Override
public void onResponse(Call<GoogleService.TokenResponse> call, Response<GoogleService.TokenResponse> response) {
if (response != null && response.body() != null) {
listener.refreshSuccessful(response.body().getIdToken(), response.body().getRefreshToken());
} else {
listener.refreshFailed("Failed on requesting the id token");
}
}
@Override
public void onFailure(Call<GoogleService.TokenResponse> call, Throwable t) {
t.printStackTrace();
listener.refreshFailed("Failed on requesting the id token");
}
};
if (mGoogleService != null) {
Call<GoogleService.TokenResponse> call = mGoogleService.requestToken(url.toString());
call.enqueue(googleCallback);
}
}
use of okhttp3.HttpUrl in project Pokemap by omkarmoghe.
the class NianticManager method loginPTC.
private void loginPTC(final String username, final String password, NianticService.LoginValues values, final LoginListener loginListener) {
HttpUrl url = HttpUrl.parse(LOGIN_URL).newBuilder().addQueryParameter("lt", values.getLt()).addQueryParameter("execution", values.getExecution()).addQueryParameter("_eventId", "submit").addQueryParameter("username", username).addQueryParameter("password", password).build();
OkHttpClient client = mClient.newBuilder().followRedirects(false).followSslRedirects(false).build();
NianticService service = new Retrofit.Builder().baseUrl(BASE_URL).addConverterFactory(GsonConverterFactory.create()).client(client).build().create(NianticService.class);
Callback<NianticService.LoginResponse> loginCallback = new Callback<NianticService.LoginResponse>() {
@Override
public void onResponse(Call<NianticService.LoginResponse> call, Response<NianticService.LoginResponse> response) {
String location = response.headers().get("location");
if (location != null && location.split("ticket=").length > 0) {
String ticket = location.split("ticket=")[1];
requestToken(ticket, loginListener);
} else {
Log.e(TAG, "PTC login failed via loginPTC(). There was no location header in response.");
loginListener.authFailed("Pokemon Trainer Club Login Failed");
}
}
@Override
public void onFailure(Call<NianticService.LoginResponse> call, Throwable t) {
t.printStackTrace();
Log.e(TAG, "PTC login failed via loginPTC(). loginCallback.onFailure() threw: " + t.getMessage());
loginListener.authFailed("Pokemon Trainer Club Login Failed");
}
};
Call<NianticService.LoginResponse> call = service.login(url.toString());
call.enqueue(loginCallback);
}
use of okhttp3.HttpUrl in project muzei by romannurik.
the class FiveHundredPxExampleArtSource method onTryUpdate.
@Override
protected void onTryUpdate(@UpdateReason int reason) throws RetryException {
String currentToken = (getCurrentArtwork() != null) ? getCurrentArtwork().getToken() : null;
OkHttpClient okHttpClient = new OkHttpClient.Builder().addInterceptor(new Interceptor() {
@Override
public Response intercept(final Chain chain) throws IOException {
Request request = chain.request();
HttpUrl url = request.url().newBuilder().addQueryParameter("consumer_key", Config.CONSUMER_KEY).build();
request = request.newBuilder().url(url).build();
return chain.proceed(request);
}
}).build();
Retrofit retrofit = new Retrofit.Builder().baseUrl("https://api.500px.com/").client(okHttpClient).addConverterFactory(GsonConverterFactory.create()).build();
FiveHundredPxService service = retrofit.create(FiveHundredPxService.class);
PhotosResponse response;
try {
response = service.getPopularPhotos().execute().body();
} catch (IOException e) {
Log.w(TAG, "Error reading 500px response", e);
throw new RetryException();
}
if (response == null || response.photos == null) {
throw new RetryException();
}
if (response.photos.size() == 0) {
Log.w(TAG, "No photos returned from API.");
scheduleUpdate(System.currentTimeMillis() + ROTATE_TIME_MILLIS);
return;
}
Random random = new Random();
Photo photo;
String token;
while (true) {
photo = response.photos.get(random.nextInt(response.photos.size()));
token = Integer.toString(photo.id);
if (response.photos.size() <= 1 || !TextUtils.equals(token, currentToken)) {
break;
}
}
publishArtwork(new Artwork.Builder().title(photo.name).byline(photo.user.fullname).imageUri(Uri.parse(photo.image_url)).token(token).viewIntent(new Intent(Intent.ACTION_VIEW, Uri.parse("http://500px.com/photo/" + photo.id))).build());
scheduleUpdate(System.currentTimeMillis() + ROTATE_TIME_MILLIS);
}
use of okhttp3.HttpUrl in project okhttp by square.
the class CacheTest method assertConditionallyCached.
/** @return the request with the conditional get headers. */
private RecordedRequest assertConditionallyCached(MockResponse response) throws Exception {
// scenario 1: condition succeeds
server.enqueue(response.setBody("A").setStatus("HTTP/1.1 200 A-OK"));
server.enqueue(new MockResponse().setResponseCode(HttpURLConnection.HTTP_NOT_MODIFIED));
// scenario 2: condition fails
server.enqueue(response.setBody("B").setStatus("HTTP/1.1 200 B-OK"));
server.enqueue(new MockResponse().setStatus("HTTP/1.1 200 C-OK").setBody("C"));
HttpUrl valid = server.url("/valid");
Response response1 = get(valid);
assertEquals("A", response1.body().string());
assertEquals(HttpURLConnection.HTTP_OK, response1.code());
assertEquals("A-OK", response1.message());
Response response2 = get(valid);
assertEquals("A", response2.body().string());
assertEquals(HttpURLConnection.HTTP_OK, response2.code());
assertEquals("A-OK", response2.message());
HttpUrl invalid = server.url("/invalid");
Response response3 = get(invalid);
assertEquals("B", response3.body().string());
assertEquals(HttpURLConnection.HTTP_OK, response3.code());
assertEquals("B-OK", response3.message());
Response response4 = get(invalid);
assertEquals("C", response4.body().string());
assertEquals(HttpURLConnection.HTTP_OK, response4.code());
assertEquals("C-OK", response4.message());
// regular get
server.takeRequest();
// conditional get
return server.takeRequest();
}
Aggregations