Search in sources :

Example 46 with Call

use of com.squareup.okhttp.Call in project casa by GluuFederation.

the class StytchService method sendSMS.

public StytchPhoneCredential sendSMS(String phoneNumber, String userId) {
    OkHttpClient httpClient = new OkHttpClient();
    String data = "{ \"phone_number\": \"+" + phoneNumber + "\"}";
    RequestBody body = RequestBody.create(MediaType.parse("application/json"), data);
    String asB64 = new String(new Base64().encode((properties.get("PROJECT_ID") + ":" + properties.get("SECRET")).getBytes(StandardCharsets.UTF_8)), StandardCharsets.UTF_8);
    String authHeader = "Basic " + new String(asB64);
    Request request = new Request.Builder().url(getScriptPropertyValue("ENROLL_ENDPOINT")).post(body).addHeader(HttpHeaders.AUTHORIZATION, authHeader).addHeader("Content-Type", "application/json").build();
    Call call = httpClient.newCall(request);
    logger.debug(request.toString() + "-" + request.headers() + "-" + request.body().toString());
    try {
        Response response = call.execute();
        if (response.code() == 200 || response.code() == 201) {
            String responseBody = response.body().string();
            Map<String, String> map = mapper.readValue(responseBody, Map.class);
            StytchPhoneCredential stytchPhoneCred = new StytchPhoneCredential();
            stytchPhoneCred.setStytchUserId(map.get("user_id"));
            stytchPhoneCred.setStytchPhoneId(map.get("phone_id"));
            return stytchPhoneCred;
        } else {
            logger.debug("Response for enrolling user was : " + response.code() + "---" + response.message());
            return null;
        }
    } catch (IOException e) {
        logger.error(e.getMessage(), e);
        return null;
    }
}
Also used : Response(com.squareup.okhttp.Response) Call(com.squareup.okhttp.Call) OkHttpClient(com.squareup.okhttp.OkHttpClient) Base64(org.apache.commons.codec.binary.Base64) StytchPhoneCredential(org.gluu.casa.plugins.stytch.model.StytchPhoneCredential) Request(com.squareup.okhttp.Request) IOException(java.io.IOException) RequestBody(com.squareup.okhttp.RequestBody)

Aggregations

Call (com.squareup.okhttp.Call)46 Type (java.lang.reflect.Type)28 Request (com.squareup.okhttp.Request)13 Response (com.squareup.okhttp.Response)13 OkHttpClient (com.squareup.okhttp.OkHttpClient)9 PaymentDetails (jp.ne.paypay.model.PaymentDetails)8 RequestBody (com.squareup.okhttp.RequestBody)5 IOException (java.io.IOException)5 HttpUrl (com.squareup.okhttp.HttpUrl)4 HashMap (java.util.HashMap)4 ReverseCashbackDetails (jp.ne.paypay.model.ReverseCashbackDetails)4 TypeToken (com.google.gson.reflect.TypeToken)3 NotDataResponse (jp.ne.paypay.model.NotDataResponse)3 Base64 (org.apache.commons.codec.binary.Base64)3 Pair (jp.ne.paypay.Pair)2 Request (com.android.volley.Request)1 ApiCommand (com.cloudera.api.swagger.model.ApiCommand)1 ApiCommandList (com.cloudera.api.swagger.model.ApiCommandList)1 ApiHost (com.cloudera.api.swagger.model.ApiHost)1 ApiHostList (com.cloudera.api.swagger.model.ApiHostList)1