lib/fitbit_api/client.rb in fitbit_api-0.11.0 vs lib/fitbit_api/client.rb in fitbit_api-0.12.0

- old
+ new

@@ -5,10 +5,11 @@ require 'fitbit_api/alarms' require 'fitbit_api/body' require 'fitbit_api/devices' require 'fitbit_api/food' require 'fitbit_api/friends' +require 'fitbit_api/meals' require 'fitbit_api/sleep' require 'fitbit_api/subscriptions' require 'fitbit_api/user' require 'fitbit_api/water' @@ -45,20 +46,20 @@ on_token_refresh.call(@token) if on_token_refresh.respond_to?(:call) @token end - def get(path, params={}, opts={}) - request(:get, path, opts.merge(params: params)) + def get(path, params={}, opts={}, &block) + request(:get, path, opts.merge(params: params), &block) end - def post(path, body={}, opts={}) - request(:post, path, opts.merge(body: body)) + def post(path, body={}, opts={}, &block) + request(:post, path, opts.merge(body: body), &block) end - def delete(path, params={}, opts={}) - request(:delete, path, opts.merge(params: params)) + def delete(path, params={}, opts={}, &block) + request(:delete, path, opts.merge(params: params), &block) end private def validate_args(opts) @@ -113,20 +114,20 @@ ) refresh_token! if @token.token.empty? end - def request(verb, path, opts={}) + def request(verb, path, opts={}, &block) request_path = "#{@api_version}/#{path}" request_headers = default_request_headers.merge(opts[:headers] || {}) request_options = opts.merge(headers: request_headers) deep_keys_to_camel_case!(request_options[:params]) deep_keys_to_camel_case!(request_options[:body]) refresh_token! if auto_refresh_token && token.expired? - response = token.public_send(verb, request_path, request_options).response + response = token.public_send(verb, request_path, request_options, &block).response response_body = MultiJson.load(response.body) unless response.status == 204 process_keys!(response_body) end