Search in sources :

Example 16 with Response

use of org.scribe.model.Response in project fitscales by paulburton.

the class FitBitSyncService method postOAuth.

@Override
protected void postOAuth() {
    try {
        OAuthRequest request = new OAuthRequest(Verb.GET, API_BASE + "/user/-/profile.json");
        oaService.signRequest(oaToken, request);
        Response response = request.send();
        if (DEBUG)
            Log.d(TAG, "Profile response code " + response.getCode());
        String body = response.getBody();
        if (DEBUG)
            Log.d(TAG, "Got profile body " + body);
        JSONObject json = new JSONObject(body);
        user = json.getJSONObject("user").getString("displayName");
    } catch (Exception ex) {
        if (DEBUG)
            Log.e(TAG, "Failed to get profile", ex);
        user = "unknown";
    }
}
Also used : OAuthRequest(org.scribe.model.OAuthRequest) Response(org.scribe.model.Response) JSONObject(org.json.JSONObject)

Example 17 with Response

use of org.scribe.model.Response in project fitscales by paulburton.

the class RunKeeperSyncService method syncWeight.

@Override
public boolean syncWeight(float weight) {
    try {
        SimpleDateFormat tsFormat = new SimpleDateFormat("EEE, d MMM yyyy HH:mm:ss", Locale.ENGLISH);
        String timestamp = tsFormat.format(new Date());
        String json = String.format("{\"weight\": %.2f,\"timestamp\": \"%s\" }", weight, timestamp);
        if (DEBUG)
            Log.d(TAG, "Posting weight " + json);
        OAuthRequest request = new OAuthRequest(Verb.POST, API_BASE + "/weight");
        request.addPayload(json);
        request.addHeader("Content-Type", "application/vnd.com.runkeeper.NewWeight+json");
        oaService.signRequest(oaToken, request);
        Response response = request.send();
        int code = response.getCode();
        if (DEBUG)
            Log.d(TAG, "Response code " + code);
        if (code == 200 || code == 201 || code == 204)
            return true;
        return false;
    } catch (Exception ex) {
        return false;
    }
}
Also used : OAuthRequest(org.scribe.model.OAuthRequest) Response(org.scribe.model.Response) SimpleDateFormat(java.text.SimpleDateFormat) Date(java.util.Date)

Example 18 with Response

use of org.scribe.model.Response in project sling by apache.

the class XingOauthAuthenticationHandler method fetchUser.

protected XingUser fetchUser(final Token accessToken) throws Exception {
    final OAuthRequest request = new OAuthRequest(Verb.GET, usersMeUrl);
    oAuthService.signRequest(accessToken, request);
    final Response response = request.send();
    final Gson gson = new GsonBuilder().setFieldNamingPolicy(FieldNamingPolicy.LOWER_CASE_WITH_UNDERSCORES).create();
    final Users users = gson.fromJson(response.getBody(), Users.class);
    return users.getUsers().get(0);
}
Also used : OAuthRequest(org.scribe.model.OAuthRequest) HttpServletResponse(javax.servlet.http.HttpServletResponse) Response(org.scribe.model.Response) GsonBuilder(com.google.gson.GsonBuilder) Gson(com.google.gson.Gson) Users(org.apache.sling.auth.xing.api.users.Users)

Example 19 with Response

use of org.scribe.model.Response in project OpenOLAT by OpenOLAT.

the class FacebookProvider method getUser.

@Override
public OAuthUser getUser(OAuthService service, Token accessToken) {
    OAuthRequest request = new OAuthRequest(Verb.GET, "https://graph.facebook.com/me");
    service.signRequest(accessToken, request);
    Response oauthResponse = request.send();
    String body = oauthResponse.getBody();
    return parseInfos(body);
}
Also used : OAuthRequest(org.scribe.model.OAuthRequest) Response(org.scribe.model.Response)

Example 20 with Response

use of org.scribe.model.Response in project muikku by otavanopisto.

the class PyramusApi20ServiceImpl method getAccessToken.

@Override
public Token getAccessToken(Token requestToken, Verifier verifier) {
    OAuthRequest request = new OAuthRequest(api.getAccessTokenVerb(), api.getAccessTokenEndpoint());
    request.addBodyParameter(OAuthConstants.CLIENT_ID, config.getApiKey());
    request.addBodyParameter(OAuthConstants.CLIENT_SECRET, config.getApiSecret());
    request.addBodyParameter(OAuthConstants.CODE, verifier.getValue());
    request.addBodyParameter(OAuthConstants.REDIRECT_URI, config.getCallback());
    request.addBodyParameter("grant_type", "authorization_code");
    if (config.hasScope())
        request.addBodyParameter(OAuthConstants.SCOPE, config.getScope());
    Response response = request.send();
    ObjectMapper objectMapper = new ObjectMapper();
    String tokenJson;
    try {
        tokenJson = objectMapper.writeValueAsString(objectMapper.readTree(response.getBody()));
    } catch (IOException e) {
        throw new OAuthException("Invalid Token JSON", e);
    }
    return api.getAccessTokenExtractor().extract(tokenJson);
}
Also used : OAuthRequest(org.scribe.model.OAuthRequest) Response(org.scribe.model.Response) OAuthException(org.scribe.exceptions.OAuthException) IOException(java.io.IOException) ObjectMapper(org.codehaus.jackson.map.ObjectMapper)

Aggregations

Response (org.scribe.model.Response)28 OAuthRequest (org.scribe.model.OAuthRequest)26 IOException (java.io.IOException)8 ObjectMapper (org.codehaus.jackson.map.ObjectMapper)6 Date (java.util.Date)5 AuthenticationResult (fi.otavanopisto.muikku.auth.AuthenticationResult)3 Calendar (java.util.Calendar)3 GregorianCalendar (java.util.GregorianCalendar)3 Token (org.scribe.model.Token)3 Verifier (org.scribe.model.Verifier)3 JsonObject (com.google.gson.JsonObject)2 JsonParser (com.google.gson.JsonParser)2 SimpleDateFormat (java.text.SimpleDateFormat)2 JSONObject (org.json.JSONObject)2 OAuthException (org.scribe.exceptions.OAuthException)2 Gson (com.google.gson.Gson)1 GsonBuilder (com.google.gson.GsonBuilder)1 JsonElement (com.google.gson.JsonElement)1 WhoAmI (fi.otavanopisto.pyramus.rest.model.WhoAmI)1 HashMap (java.util.HashMap)1