Class: Cashbox::Request

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

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(method, path, options = {}) ⇒ Request

Returns a new instance of Request.



7
8
9
10
11
# File 'lib/cashbox/request.rb', line 7

def initialize(method, path, options = {})
  @method  = method
  @path    = path
  @options = options
end

Class Method Details

.after_request_log(&block) ⇒ Object



13
14
15
# File 'lib/cashbox/request.rb', line 13

def self.after_request_log(&block)
  @@after_request_log = block if block_given?
end

.after_request_log_blockObject



17
18
19
# File 'lib/cashbox/request.rb', line 17

def self.after_request_log_block
  @@after_request_log ||= nil
end

Instance Method Details

#responseObject



21
22
23
24
25
26
27
28
29
30
31
# File 'lib/cashbox/request.rb', line 21

def response
  resp = self.class.send(@method, @path, @options.merge(default_options))

  if self.class.after_request_log_block
    resp.tap do |r|
      self.class.after_request_log_block.call(@method, @path, @options, r)
    end
  end

  Hashie::Mash.new(resp)
end