Package com.fitbit.api

Examples of com.fitbit.api.FitbitAPIException


    public AccessToken getOAuthAccessToken(TempCredentials token) throws FitbitAPIException {
        try {
            oauthToken = token;
            oauthToken = new AccessToken(httpRequest(HttpMethod.POST, accessTokenURL, PostParameter.EMPTY_ARRAY, true));
        } catch (FitbitAPIException te) {
            throw new FitbitAPIException("The user has not given access to the account.", te, te.getStatusCode());
        }
        return (AccessToken) oauthToken;
    }
View Full Code Here


    public AccessToken getOAuthAccessToken(TempCredentials token, String pin) throws FitbitAPIException {
        try {
            oauthToken = token;
            oauthToken = new AccessToken(httpRequest(HttpMethod.POST, accessTokenURL, new PostParameter[]{new PostParameter("oauth_verifier", pin)}, true));
        } catch (FitbitAPIException te) {
            throw new FitbitAPIException("The user has not given access to the account.", te, te.getStatusCode());
        }
        return (AccessToken) oauthToken;
    }
View Full Code Here

            oauthToken = new OAuthToken(token, tokenSecret) {
            };
            oauthToken = new AccessToken(httpRequest(HttpMethod.POST, accessTokenURL,
                    new PostParameter[]{new PostParameter("oauth_verifier", oauth_verifier)}, true));
        } catch (FitbitAPIException te) {
            throw new FitbitAPIException("The user has not given access to the account.", te, te.getStatusCode());
        }
        return (AccessToken) oauthToken;
    }
View Full Code Here

                   
                    if (responseCode >= 200 && responseCode < 300) {
                      break;
                    } else {
                        if (responseCode < INTERNAL_SERVER_ERROR || retriedCount == retryCount) {
                            throw new FitbitAPIException(getCause(responseCode), res);
                        }
                        // will retry if the status code is INTERNAL_SERVER_ERROR
                    }
                } finally {
                    try {
                        osw.close();
                    } catch (Exception ignore) {
                    }
                }
            } catch (IOException ioe) {
                // connection timeout or read timeout
                if (retriedCount == retryCount) {
                    throw new FitbitAPIException(ioe.getMessage(), ioe, responseCode);
                }
            }
            try {
              if (log.isDebugEnabled() && null!=res) {
                    res.asString();
View Full Code Here

            List<ActivityLog> activities = jsonArrayToActivityList(res.asJSONObject().getJSONArray("activities"));
            JSONObject goalsJson = res.asJSONObject().optJSONObject("goals");
            ActivityGoals activityGoals = goalsJson != null ? new ActivityGoals(goalsJson) : null;
            return new Activities(summary, activities, activityGoals);
         } catch (JSONException e) {
            throw new FitbitAPIException(e.getMessage() + ':' + res.asString(), e);
        }       
    }
View Full Code Here

            JSONObject goalsJSON = json.optJSONObject("goals");
            FoodsGoals foodsGoals = goalsJSON != null ? new FoodsGoals(goalsJSON) : null;
            List<FoodLog> foods = jsonArrayToFoodLogList(json.getJSONArray("foods"));
            return new Foods(summary, foods, foodsGoals);
         } catch (JSONException e) {
            throw new FitbitAPIException(e.getMessage() + ':' + res.asString(), e);
        }
    }
View Full Code Here

    public static List<FoodLog> constructFoodLogList(Response res, String arrayName) throws FitbitAPIException {
        try {
            JSONObject json = res.asJSONObject();
            return jsonArrayToFoodLogList(json.getJSONArray(arrayName));
         } catch (JSONException e) {
            throw new FitbitAPIException(e.getMessage() + ':' + res.asString(), e);
        }
    }
View Full Code Here

                stream.close();
                disconnect();
                streamConsumed = true;
            } catch (NullPointerException npe) {
                // don't remember in which case npe can be thrown
                throw new FitbitAPIException(npe.getMessage(), npe);
            } catch (IOException ioe) {
                throw new FitbitAPIException(ioe.getMessage(), ioe);
            }
        }
        return responseAsString;
    }
View Full Code Here

            try {
                // it should be faster to read the inputstream directly.
                // but makes it difficult to troubleshoot
                responseAsDocument = builders.get().parse(new ByteArrayInputStream(asString().getBytes("UTF-8")));
            } catch (SAXException saxe) {
                throw new FitbitAPIException("The response body was not well-formed:\n" + responseAsString, saxe);
            } catch (IOException ioe) {
                throw new FitbitAPIException("There's something with the connection.", ioe);
            }
        }
        return responseAsDocument;
    }
View Full Code Here

     */
    public JSONObject asJSONObject() throws FitbitAPIException {
        try {
            return new JSONObject(asString());
        } catch (JSONException jsone) {
            throw new FitbitAPIException(jsone.getMessage() + ':' + responseAsString, jsone);
        }
    }
View Full Code Here

TOP

Related Classes of com.fitbit.api.FitbitAPIException

Copyright © 2018 www.massapicom. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.