Class: Bitreserve::Request

Inherits:
Object
  • Object
show all
Includes:
HTTParty
Defined in:
lib/bitreserve/request.rb

Defined Under Namespace

Classes: APIError

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(request_data) ⇒ Request

Returns a new instance of Request.



24
25
26
27
28
# File 'lib/bitreserve/request.rb', line 24

def initialize(request_data)
  @path = request_data.endpoint
  @data = request_data.payload
  @headers = request_data.headers
end

Class Method Details

.perform_with_object(http_method, request_data) ⇒ Object



16
17
18
19
20
21
22
# File 'lib/bitreserve/request.rb', line 16

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) ⇒ Object



8
9
10
11
12
13
14
# File 'lib/bitreserve/request.rb', line 8

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

Instance Method Details

#getObject



30
31
32
33
34
# File 'lib/bitreserve/request.rb', line 30

def get
  response = self.class.get(path, options)
  log_request_info(:get, response)
  response
end

#postObject



36
37
38
39
40
# File 'lib/bitreserve/request.rb', line 36

def post
  response = self.class.post(path, options)
  log_request_info(:post, response)
  response
end