Search in sources :

Example 26 with Response

use of org.scribe.model.Response in project data-transfer-project by google.

the class SmugMugInterface method getImageAsStream.

public InputStream getImageAsStream(String urlStr) {
    OAuthRequest request = new OAuthRequest(Verb.GET, urlStr);
    oAuthService.signRequest(accessToken, request);
    final Response response = request.send();
    return response.getStream();
}
Also used : OAuthRequest(org.scribe.model.OAuthRequest) Response(org.scribe.model.Response)

Example 27 with Response

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

the class FitBitSyncService method syncWeight.

@Override
public boolean syncWeight(float weight) {
    try {
        SimpleDateFormat tsFormat = new SimpleDateFormat("yyyy-MM-dd", Locale.ENGLISH);
        String timestamp = tsFormat.format(new Date());
        OAuthRequest request = new OAuthRequest(Verb.POST, API_BASE + "/user/-/body.json");
        request.addBodyParameter("weight", String.format("%.2f", weight));
        request.addBodyParameter("date", timestamp);
        oaService.signRequest(oaToken, request);
        Response response = request.send();
        int code = response.getCode();
        if (DEBUG) {
            Log.d(TAG, "Response code " + code);
            try {
                Log.d(TAG, "Response body " + response.getBody());
            } catch (Exception ex) {
                Log.e(TAG, "Response body error", ex);
            }
        }
        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 28 with Response

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

the class RunKeeperSyncService method postOAuth.

@Override
protected void postOAuth() {
    try {
        OAuthRequest request = new OAuthRequest(Verb.GET, API_BASE + "/profile");
        request.addHeader("Accept", "application/vnd.com.runkeeper.Profile+json");
        oaService.signRequest(oaToken, request);
        Response response = request.send();
        String body = response.getBody();
        if (DEBUG)
            Log.d(TAG, "Got profile body " + body);
        JSONObject json = new JSONObject(body);
        user = json.getString("name");
    } catch (Exception ex) {
        user = "unknown";
    }
}
Also used : OAuthRequest(org.scribe.model.OAuthRequest) Response(org.scribe.model.Response) JSONObject(org.json.JSONObject)

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