class Bitreserve::Request
Attributes
auth[R]
data[R]
headers[R]
path[R]
Public Class Methods
new(request_data)
click to toggle source
# File lib/bitreserve/request.rb, line 28 def initialize(request_data) @path = request_data.endpoint @data = request_data.payload @headers = request_data.headers end
perform_with_object(http_method, request_data)
click to toggle source
# File lib/bitreserve/request.rb, line 20 def self.perform_with_object(http_method, request_data) response = new(request_data).public_send(http_method) with_valid_response(response) do request_data.entity.new(response.parsed_response) end end
perform_with_objects(http_method, request_data)
click to toggle source
# File lib/bitreserve/request.rb, line 12 def self.perform_with_objects(http_method, request_data) response = new(request_data).public_send(http_method) with_valid_response(response) do request_data.entity.from_collection(response.parsed_response, response.headers['content-range']) end end
update_base_uri()
click to toggle source
# File lib/bitreserve/request.rb, line 5 def self.update_base_uri base_uri "#{Bitreserve.api_base}/v#{Bitreserve.api_version}" end
Private Class Methods
with_valid_response(response) { || ... }
click to toggle source
# File lib/bitreserve/request.rb, line 50 def self.with_valid_response(response) return yield unless response.code >= 400 if response['error_description'] Entities::OAuthError.new(response) else Entities::Error.new(response) end end
Public Instance Methods
get()
click to toggle source
# File lib/bitreserve/request.rb, line 34 def get response = self.class.get(path, options) log_request_info(:get, response) response end
post()
click to toggle source
# File lib/bitreserve/request.rb, line 40 def post response = self.class.post(path, options) log_request_info(:post, response) response end
Private Instance Methods
log_request_info(http_method, response)
click to toggle source
# File lib/bitreserve/request.rb, line 65 def log_request_info(http_method, response) Bitreserve.logger.info "[Bitreserve] #{http_method.to_s.upcase} #{self.class.base_uri}#{path} #{options[:headers]} #{response.code}" Bitreserve.logger.debug response.parsed_response end
options()
click to toggle source
# File lib/bitreserve/request.rb, line 60 def options { body: data, headers: headers }. reject { |_k, v| v.nil? } end