class Atol::Transaction::GetDocumentState

Public Class Methods

new(uuid:, token:, config: nil) click to toggle source
# 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

Public Instance Methods

call() click to toggle source
# File lib/atol/transaction/get_document_state.rb, line 16
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