Class: Atol::Transaction::PostDocument

Inherits:
Object
  • Object
show all
Defined in:
lib/atol/transaction/post_document.rb

Instance Method Summary collapse

Constructor Details

#initialize(operation:, token:, body:, config: nil, req_logger: nil, res_logger: nil) ⇒ PostDocument

Returns a new instance of PostDocument.



7
8
9
10
11
12
13
14
15
16
17
18
# File 'lib/atol/transaction/post_document.rb', line 7

def initialize(operation:, token:, body:, config: nil, req_logger: nil, res_logger: nil)
  @config = config || Atol.config
  raise(Atol::ConfigExpectedError) unless @config.is_a?(Atol::Config)
  @params = Hash[
    operation: operation,
    token: token,
    body: body,
    config: config,
    req_logger: req_logger,
    res_logger: res_logger
  ]
end

Instance Method Details

#callObject



20
21
22
23
24
25
26
27
28
29
30
31
32
33
# File 'lib/atol/transaction/post_document.rb', line 20

def call
  request = Atol::Request::PostDocument.new(params)
  response = request.call
  encoded_body = response.body.force_encoding(Atol::ENCODING)
  json = JSON.parse(encoded_body)

  if response.code == '200' && json['error'].nil?
    json
  elsif ERRORS[json['error']['code']]
    raise(ERRORS[json['error']['code']], encoded_body)
  else
    raise(encoded_body)
  end
end