Sha256: e3960d220cdf42fef12dcbff2d603e066d96abd1b122b6766e6373ce7d63e25c

Contents?: true

Size: 1013 Bytes

Versions: 4

Compression:

Stored size: 1013 Bytes

Contents

require 'atol/request/post_document'
require 'atol/errors'

module Atol
  module Transaction
    class PostDocument
      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 = {
          operation: operation,
          token: token,
          body: body,
          config: config,
          req_logger: req_logger,
          res_logger: res_logger
        }
      end

      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
    end
  end
end

Version data entries

4 entries across 4 versions & 1 rubygems

Version Path
atol-0.5.0 lib/atol/transaction/post_document.rb
atol-0.4.2 lib/atol/transaction/post_document.rb
atol-0.4.1 lib/atol/transaction/post_document.rb
atol-0.4 lib/atol/transaction/post_document.rb