use of okhttp3.HttpUrl in project BoltBot by DiscordBolt.
the class TwitchUser method getUserData.
public Optional<TwitchUserData> getUserData(String username) throws IOException {
HttpUrl userURL = HttpUrl.parse(USER_INFO_URL).newBuilder().addQueryParameter("login", username).build();
Request request = new Request.Builder().url(userURL).addHeader("Client-ID", api.getClientID()).addHeader("Accept", "application/vnd.twitchtv.v5+json").build();
try (Response response = api.getClient().newCall(request).execute()) {
TwitchUserDataResponse users = api.getGson().fromJson(response.body().string(), TwitchUserDataResponse.class);
return users.getUsers().stream().findFirst();
}
}
use of okhttp3.HttpUrl in project vimeo-networking-java by vimeo.
the class VimeoClient method getCodeGrantAuthorizationURI.
// </editor-fold>
// -----------------------------------------------------------------------------------------------------
// Authentication
// -----------------------------------------------------------------------------------------------------
// <editor-fold desc="Authentication">
/**
* Provides a URI that can be opened in a web view that will prompt for login and permissions
* or used currently logged in users credentials.
* <p>
* If the user accepts your app, they are redirected to your redirect_uri along with two parameters:
* {@link Vimeo#CODE_GRANT_RESPONSE_TYPE} or {@link Vimeo#CODE_GRANT_STATE}
*
* @return The URI that should be opened in a web view
* @see <a href="https://developer.vimeo.com/api/authentication#generate-redirect">Vimeo API Docs</a>
*/
@SuppressWarnings("WeakerAccess")
public String getCodeGrantAuthorizationURI() {
mCurrentCodeGrantState = UUID.randomUUID().toString();
// Will look like the following: https://api.vimeo.com/oauth/authorize?<UTF8 encoded params>
final HttpUrl baseUrl = HttpUrl.parse(mConfiguration.getBaseUrl());
final HttpUrl uri = new HttpUrl.Builder().scheme(baseUrl.scheme()).host(baseUrl.host()).encodedPath(Vimeo.CODE_GRANT_PATH).addQueryParameter(Vimeo.PARAMETER_REDIRECT_URI, mConfiguration.mCodeGrantRedirectURI).addQueryParameter(Vimeo.PARAMETER_RESPONSE_TYPE, Vimeo.CODE_GRANT_RESPONSE_TYPE).addQueryParameter(Vimeo.PARAMETER_STATE, mCurrentCodeGrantState).addQueryParameter(Vimeo.PARAMETER_SCOPE, mConfiguration.mScope).addQueryParameter(Vimeo.PARAMETER_CLIENT_ID, mConfiguration.mClientID).build();
return uri.toString();
}
use of okhttp3.HttpUrl in project vimeo-networking-java by vimeo.
the class LoggingInterceptor method intercept.
@Override
public Response intercept(Chain chain) throws IOException {
if (ClientLogger.getLogLevel().ordinal() <= LogLevel.DEBUG.ordinal()) {
Request request = chain.request();
HttpUrl httpUrl = request.url();
long t1 = System.nanoTime();
ClientLogger.d("--------- REQUEST ---------");
ClientLogger.d("METHOD: " + request.method());
ClientLogger.d("ENDPOINT: " + httpUrl.encodedPath());
try {
if (request.body() != null && shouldLogVerbose()) {
ClientLogger.v("QUERY: " + httpUrl.query());
ClientLogger.v("--------- REQUEST BODY ---------");
Request copy = request.newBuilder().build();
Buffer requestBuffer = new Buffer();
copy.body().writeTo(requestBuffer);
verboseLogLongJson(requestBuffer.readUtf8());
ClientLogger.v("--------- REQUEST BODY END ---------");
}
} catch (Exception e) {
ClientLogger.e("Exception in LoggingInterceptor", e);
}
ClientLogger.d("--------- REQUEST END ---------");
Response response = chain.proceed(request);
long t2 = System.nanoTime();
ClientLogger.d("--------- RESPONSE ---------");
ClientLogger.d("ENDPOINT: " + httpUrl.encodedPath());
ClientLogger.d("STATUS CODE: " + response.code());
ClientLogger.d(String.format("REQUEST TIME: %.1fms", (t2 - t1) / 1e6d));
String responseBodyString = response.body().string();
if (shouldLogVerbose()) {
ClientLogger.v("--------- RESPONSE BODY ---------");
verboseLogLongJson(responseBodyString);
ClientLogger.v("--------- RESPONSE BODY END ---------");
}
ClientLogger.d("--------- RESPONSE END ---------");
// You need to reconstruct the body because it can only be read once 1/27/16 [KV]
return response.newBuilder().body(ResponseBody.create(response.body().contentType(), responseBodyString)).build();
} else {
return chain.proceed(chain.request());
}
}
use of okhttp3.HttpUrl in project vimeo-networking-java by vimeo.
the class BaseUrlInterceptorTest method test_includeThenExcludePathsForBaseUrl_Reset_Exclues.
@Test
public void test_includeThenExcludePathsForBaseUrl_Reset_Exclues() throws Exception {
HttpUrl httpUrl = HttpUrl.parse("http://localhost");
mBaseUrlInterceptor.includePathsForBaseUrl(httpUrl, "/me", "/you");
mBaseUrlInterceptor.resetBaseUrl();
mBaseUrlInterceptor.excludePathsForBaseUrl(httpUrl, "/me", "/you");
mBaseUrlInterceptor.intercept(createVerificationChain(createTestUrlForPath("/me"), createTestUrlForPath(null)));
mBaseUrlInterceptor.intercept(createVerificationChain(createTestUrlForPath("/you"), createTestUrlForPath(null)));
mBaseUrlInterceptor.intercept(createVerificationChain(createTestUrlForPath("/them"), httpUrl));
}
use of okhttp3.HttpUrl in project vimeo-networking-java by vimeo.
the class BaseUrlInterceptorTest method test_includePathsForBaseUrl_PreSanitizedPaths_SuccessfullyIntercepts.
@Test
public void test_includePathsForBaseUrl_PreSanitizedPaths_SuccessfullyIntercepts() throws Exception {
HttpUrl httpUrl = HttpUrl.parse("http://localhost");
mBaseUrlInterceptor.includePathsForBaseUrl(httpUrl, "/me", "/you");
mBaseUrlInterceptor.intercept(createVerificationChain(createTestUrlForPath("/me"), httpUrl));
mBaseUrlInterceptor.intercept(createVerificationChain(createTestUrlForPath("/you"), httpUrl));
mBaseUrlInterceptor.intercept(createVerificationChain(createTestUrlForPath("/them"), createTestUrlForPath(null)));
}
Aggregations