Example usage for com.squareup.okhttp HttpUrl parse

List of usage examples for com.squareup.okhttp HttpUrl parse

Introduction

In this page you can find the example usage for com.squareup.okhttp HttpUrl parse.

Prototype

public static HttpUrl parse(String url) 

Source Link

Document

Returns a new HttpUrl representing url if it is a well-formed HTTP or HTTPS URL, or null if it isn't.

Usage

From source file:com.auth0.android.management.UsersAPIClient.java

License:Open Source License

/**
 * Link a user identity calling <a href="https://auth0.com/docs/link-accounts#the-api">'/api/v2/users/:primaryUserId/identities'</a> endpoint
 * Example usage:/* www. ja v a 2 s.  com*/
 * <pre>
 * {@code
 * client.link("{auth0 primary user id}", "{user secondary token}")
 *      .start(new BaseCallback<List<UserIdentity>, ManagementException>() {
 *          {@literal}Override
 *          public void onSuccess(List<UserIdentity> payload) {}
 *
 *          {@literal}Override
 *          public void onFailure(ManagementException error) {}
 *      });
 * }
 * </pre>
 *
 * @param primaryUserId  of the identity to link
 * @param secondaryToken of the secondary identity obtained after login
 * @return a request to start
 */
@SuppressWarnings("WeakerAccess")
public Request<List<UserIdentity>, ManagementException> link(String primaryUserId, String secondaryToken) {
    HttpUrl url = HttpUrl.parse(auth0.getDomainUrl()).newBuilder().addPathSegment(API_PATH)
            .addPathSegment(V2_PATH).addPathSegment(USERS_PATH).addPathSegment(primaryUserId)
            .addPathSegment(IDENTITIES_PATH).build();

    final Map<String, Object> parameters = ParameterBuilder.newBuilder().set(LINK_WITH_KEY, secondaryToken)
            .asDictionary();

    TypeToken<List<UserIdentity>> typeToken = new TypeToken<List<UserIdentity>>() {
    };
    return factory.POST(url, client, gson, typeToken, mgmtErrorBuilder).addParameters(parameters);
}

From source file:com.auth0.android.management.UsersAPIClient.java

License:Open Source License

/**
 * Unlink a user identity calling <a href="https://auth0.com/docs/link-accounts#unlinking-accounts">'/api/v2/users/:primaryToken/identities/secondaryProvider/secondaryUserId'</a> endpoint
 * Example usage:/*from  ww w  .  j  a v a  2s.  co  m*/
 * <pre>
 * {@code
 * client.unlink("{auth0 primary user id}", {auth0 secondary user id}, "{secondary provider}")
 *      .start(new BaseCallback<List<UserIdentity>, ManagementException>() {
 *          {@literal}Override
 *          public void onSuccess(List<UserIdentity> payload) {}
 *
 *          {@literal}Override
 *          public void onFailure(ManagementException error) {}
 *      });
 * }
 * </pre>
 *
 * @param primaryUserId     of the primary identity to unlink
 * @param secondaryUserId   of the secondary identity you wish to unlink from the main one.
 * @param secondaryProvider of the secondary identity you wish to unlink from the main one.
 * @return a request to start
 */
@SuppressWarnings("WeakerAccess")
public Request<List<UserIdentity>, ManagementException> unlink(String primaryUserId, String secondaryUserId,
        String secondaryProvider) {
    HttpUrl url = HttpUrl.parse(auth0.getDomainUrl()).newBuilder().addPathSegment(API_PATH)
            .addPathSegment(V2_PATH).addPathSegment(USERS_PATH).addPathSegment(primaryUserId)
            .addPathSegment(IDENTITIES_PATH).addPathSegment(secondaryProvider).addPathSegment(secondaryUserId)
            .build();

    TypeToken<List<UserIdentity>> typeToken = new TypeToken<List<UserIdentity>>() {
    };
    return factory.DELETE(url, client, gson, typeToken, mgmtErrorBuilder);
}

From source file:com.auth0.android.management.UsersAPIClient.java

License:Open Source License

/**
 * Update the user_metadata calling <a href="https://auth0.com/docs/api/management/v2#!/Users/patch_users_by_id">'/api/v2/users/:userId'</a> endpoint
 * Example usage:/*from  w ww .  j  ava 2  s  .c  om*/
 * <pre>
 * {@code
 * client.updateMetadata("{user id}", "{user metadata}")
 *      .start(new BaseCallback<UserProfile, ManagementException>() {
 *          {@literal}Override
 *          public void onSuccess(UserProfile payload) {}
 *
 *          {@literal}Override
 *          public void onFailure(ManagementException error) {}
 *      });
 * }
 * </pre>
 *
 * @param userId       of the primary identity to unlink
 * @param userMetadata to merge with the existing one
 * @return a request to start
 */
@SuppressWarnings("WeakerAccess")
public Request<UserProfile, ManagementException> updateMetadata(String userId,
        Map<String, Object> userMetadata) {
    HttpUrl url = HttpUrl.parse(auth0.getDomainUrl()).newBuilder().addPathSegment(API_PATH)
            .addPathSegment(V2_PATH).addPathSegment(USERS_PATH).addPathSegment(userId).build();

    return factory.PATCH(url, client, gson, UserProfile.class, mgmtErrorBuilder).addParameter(USER_METADATA_KEY,
            userMetadata);
}

From source file:com.auth0.android.management.UsersAPIClient.java

License:Open Source License

/**
 * Get the User Profile calling <a href="https://auth0.com/docs/api/management/v2#!/Users/get_users_by_id">'/api/v2/users/:userId'</a> endpoint
 * Example usage://w w  w .j  av a2s.  co  m
 * <pre>
 * {@code
 * client.getProfile("{user id}")
 *      .start(new BaseCallback<UserProfile, ManagementException>() {
 *          {@literal}Override
 *          public void onSuccess(UserProfile payload) {}
 *
 *          {@literal}Override
 *          public void onFailure(ManagementException error) {}
 *      });
 * }
 * </pre>
 *
 * @param userId identity of the user
 * @return a request to start
 */
@SuppressWarnings("WeakerAccess")
public Request<UserProfile, ManagementException> getProfile(String userId) {
    HttpUrl url = HttpUrl.parse(auth0.getDomainUrl()).newBuilder().addPathSegment(API_PATH)
            .addPathSegment(V2_PATH).addPathSegment(USERS_PATH).addPathSegment(userId).build();

    return factory.GET(url, client, gson, UserProfile.class, mgmtErrorBuilder);
}

From source file:com.auth0.api.AuthenticatedAPIClient.java

License:Open Source License

/**
 * Creates a user and request a SMS code using a configured SMS connection
 * @param phoneNumber phone number that will receive the SMS code.
 * @param callback callback when the SMS is sent or with the failure reason.
 * @deprecated Use passwordless endpoints from {@link APIClient}
 *//*w w  w.ja  v  a  2s.  c  om*/
public void requestSmsCode(String phoneNumber, final BaseCallback<Void> callback) {
    HttpUrl url = HttpUrl.parse(getBaseURL()).newBuilder().addPathSegment("api").addPathSegment("v2")
            .addPathSegment("users").build();
    Map<String, Object> params = ParameterBuilder.newBuilder().clearAll().setConnection("sms")
            .set("email_verified", false).set("phone_number", phoneNumber).asDictionary();

    Log.v(TAG, "Requesting SMS code for phone " + phoneNumber);

    RequestFactory.POST(url, newClient, new Handler(Looper.getMainLooper()), new ObjectMapper(), jwt)
            .addParameters(params).start(callback);
}

From source file:com.auth0.api.internal.BaseRequestTest.java

License:Open Source License

@Before
public void setUp() throws Exception {
    MockitoAnnotations.initMocks(this);
    HttpUrl url = HttpUrl.parse("https://auth0.com");
    baseRequest = new BaseRequest<String>(handler, url, client, reader, writer, callback) {
        @Override//from   ww w.j  a  va 2s  .  c  o  m
        protected Request doBuildRequest(Request.Builder builder) {
            return null;
        }

        @Override
        public void onResponse(Response response) throws IOException {

        }

        @Override
        public void start(BaseCallback callback) {

        }

        @Override
        public ParameterizableRequest<String> addParameters(Map parameters) {
            return null;
        }
    };
}

From source file:com.auth0.Auth0.java

License:Open Source License

/**
 * @return Url to perform the web flow of OAuth
 *//*  www .  ja  va  2s  .c  o m*/
public String getAuthorizeUrl() {
    return HttpUrl.parse(domainUrl).newBuilder().addEncodedPathSegment("authorize").build().toString();
}

From source file:com.auth0.Auth0.java

License:Open Source License

private String resolveConfiguration(String configurationDomain, String domainUrl) {
    String url = ensureUrlString(configurationDomain);
    if (configurationDomain == null && domainUrl != null) {
        final HttpUrl domainUri = HttpUrl.parse(domainUrl);
        final String host = domainUri.host();
        if (host.endsWith(DOT_AUTH0_DOT_COM)) {
            String[] parts = host.split("\\.");
            if (parts.length > 3) {
                url = "https://cdn." + parts[parts.length - 3] + DOT_AUTH0_DOT_COM;
            } else {
                url = AUTH0_US_CDN_URL;
            }/*from   w ww  .ja v  a  2  s  . com*/
        } else {
            url = domainUrl;
        }
    }
    return url;
}

From source file:com.auth0.authentication.AuthenticationAPIClient.java

License:Open Source License

/**
 * Log in a user with a OAuth 'access_token' of a Identity Provider like Facebook or Twitter using <a href="https://auth0.com/docs/auth-api#!#post--oauth-access_token">'\oauth\access_token' endpoint</a>
 * Example usage:/* w w  w .  j  a v  a  2 s. c  o  m*/
 * <pre><code>
 * client.loginWithOAuthAccessToken("{token}", "{connection name}")
 *      .setConnection("second-database")
 *      .start(new BaseCallback<Credentials>() {
 *          {@literal}Override
 *          public void onSuccess(Credentials payload) { }
 *
 *          {@literal}Override
 *          public void onFailure(Auth0Exception error) { }
 *      });
 * </code></pre>
 *
 * @param token      obtained from the IdP
 * @param connection that will be used to authenticate the user, e.g. 'facebook'
 * @return a request to configure and start that will yield {@link Credentials}
 */
public AuthenticationRequest loginWithOAuthAccessToken(String token, String connection) {
    HttpUrl url = HttpUrl.parse(auth0.getDomainUrl()).newBuilder().addPathSegment(OAUTH_PATH)
            .addPathSegment(ACCESS_TOKEN_PATH).build();

    Map<String, Object> parameters = ParameterBuilder.newAuthenticationBuilder().setClientId(getClientId())
            .setConnection(connection).setAccessToken(token).asDictionary();

    return factory.authenticationPOST(url, client, mapper).addAuthenticationParameters(parameters);
}

From source file:com.auth0.authentication.AuthenticationAPIClient.java

License:Open Source License

/**
 * Creates a user in a DB connection using <a href="https://auth0.com/docs/auth-api#!#post--dbconnections-signup">'/dbconnections/signup' endpoint</a>
 * Example usage://from w ww  .ja  va2 s.com
 * <pre><code>
 * client.createUser("{email}", "{password}", "{username}")
 *      .setConnection("{connection name}")
 *      .start(new BaseCallback<DatabaseUser>() {
 *          {@literal}Override
 *          public void onSuccess(DatabaseUser payload) { }
 *
 *          {@literal}@Override
 *          public void onFailure(Auth0Exception error) { }
 *      });
 * </code></pre>
 *
 * @param email    of the user and must be non null
 * @param password of the user and must be non null
 * @param username of the user and must be non null
 * @return a request to start
 */
public DatabaseConnectionRequest<DatabaseUser> createUser(String email, String password, String username) {
    HttpUrl url = HttpUrl.parse(auth0.getDomainUrl()).newBuilder().addPathSegment(DB_CONNECTIONS_PATH)
            .addPathSegment(SIGN_UP_PATH).build();

    Map<String, Object> parameters = ParameterBuilder.newBuilder().set(USERNAME_KEY, username)
            .set(EMAIL_KEY, email).set(PASSWORD_KEY, password).setConnection(defaultDatabaseConnection)
            .setClientId(getClientId()).asDictionary();
    final ParameterizableRequest<DatabaseUser> request = factory.POST(url, client, mapper, DatabaseUser.class)
            .addParameters(parameters);
    return new DatabaseConnectionRequest<>(request);
}