lib/fitbit_api/client.rb in fitbit_api-0.14.1 vs lib/fitbit_api/client.rb in fitbit_api-0.14.2
- old
+ new
@@ -29,46 +29,74 @@
assign_attrs(opts)
set_client
establish_token(opts)
end
+ # Returns the authorize endpoint URL of the OAuth2 provider.
+
def auth_url
@client.auth_code.authorize_url(redirect_uri: @redirect_uri, scope: @scope)
end
+ # Returns an OAuth2::AccessToken instance obtained from the given authorization code.
+ #
+ # @param auth_code [String] An authorization code
+
def get_token(auth_code)
@token = @client.auth_code.get_token(
auth_code,
redirect_uri: @redirect_uri,
headers: auth_headers
)
@user_id = @token.params['user_id']
@token
end
+ # Refreshes the current Access Token.
+
def refresh_token!
@token = @token.refresh!(headers: auth_headers)
@user_id ||= @token.params['user_id']
on_token_refresh.call(@token) if on_token_refresh.respond_to?(:call)
@token
end
+ # Revokes the user's authorizations and all associated tokens.
+
def revoke_token!
body = { token: token.token }
headers = default_request_headers.merge(auth_headers)
response = token.post('oauth2/revoke', { headers: headers, body: body }).response
process_keys!(MultiJson.load(response.body))
end
+ # Performs an authorized GET request to the configured API namespace.
+ #
+ # @param path [String] The request path
+ # @param params [Hash] The query parameters
+ # @param opts [Hash] Additional request options (e.g. headers)
+
def get(path, params={}, opts={}, &block)
request(:get, path, opts.merge(params: params), &block)
end
+ # Performs an authorized POST request to the configured API namespace.
+ #
+ # @param path [String] The request path
+ # @param body [Hash] The request body
+ # @param opts [Hash] Additional request options (e.g. headers)
+
def post(path, body={}, opts={}, &block)
request(:post, path, opts.merge(body: body), &block)
end
+
+ # Performs an authorized DELETE request to the configured API namespace.
+ #
+ # @param path [String] The request path
+ # @param params [Hash] The query parameters
+ # @param opts [Hash] Additional request options (e.g. headers)
def delete(path, params={}, opts={}, &block)
request(:delete, path, opts.merge(params: params), &block)
end