Package com.fitbit.api.model

Source Code of com.fitbit.api.model.ApiRateLimitStatus

package com.fitbit.api.model;

import com.fitbit.api.FitbitAPIException;
import com.fitbit.api.client.http.Response;
import org.joda.time.DateTime;
import org.joda.time.format.ISODateTimeFormat;
import org.json.JSONException;
import org.json.JSONObject;

public class ApiRateLimitStatus {
    int remainingHits;
    int hourlyLimit;
    DateTime resetTime;

    public ApiRateLimitStatus(int remainingHits, int hourlyLimit, DateTime resetTime) {
        this.remainingHits = remainingHits;
        this.hourlyLimit = hourlyLimit;
        this.resetTime = resetTime;
    }

    public ApiRateLimitStatus(Response res) throws FitbitAPIException {
        try {
            JSONObject rateLimitStatus = res.asJSONObject().getJSONObject("rateLimitStatus");
            remainingHits = rateLimitStatus.getInt("remainingHits");
            hourlyLimit = rateLimitStatus.getInt("hourlyLimit");
            resetTime = ISODateTimeFormat.dateTime().parseDateTime(rateLimitStatus.getString("resetTime"));
         } catch (JSONException e) {
            throw new FitbitAPIException(e.getMessage() + ':' + res.asString(), e);
        }
    }
   
    public int getRemainingHits() {
        return remainingHits;
    }

    public int getHourlyLimit() {
        return hourlyLimit;
    }

    public DateTime getResetTime() {
        return resetTime;
    }
}
TOP

Related Classes of com.fitbit.api.model.ApiRateLimitStatus

TOP
Copyright © 2018 www.massapi.com. 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.