Class: Atol::Transaction::GetDocumentState

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

Instance Method Summary collapse

Constructor Details

#initialize(uuid:, token:, config: nil) ⇒ GetDocumentState

Returns a new instance of GetDocumentState.



9
10
11
12
13
# File 'lib/atol/transaction/get_document_state.rb', line 9

def initialize(uuid:, token:, config: nil)
  @config = config || Atol.config
  raise(Atol::ConfigExpectedError) unless @config.is_a?(Atol::Config)
  @params = { uuid: uuid, token: token, config: @config }
end

Instance Method Details

#callObject



15
16
17
18
19
20
21
22
23
24
25
26
27
28
# File 'lib/atol/transaction/get_document_state.rb', line 15

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

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