Sha256: 6efaecb66f5a8d4e8506a0e74aa7ba4f73c0c33551d38746deec011f89f401da

Contents?: true

Size: 893 Bytes

Versions: 3

Compression:

Stored size: 893 Bytes

Contents

require 'atol'
require 'atol/errors'
require 'net/http'

module Atol
  module Request
    class GetToken
      PATH = '/getToken'.freeze

      def initialize(config: nil)
        @config = config || Atol.config
        raise(Atol::ConfigExpectedError) unless @config.is_a?(Atol::Config)

        if @config.login.nil? || @config.login.empty?
          raise(Atol::MissingConfigError, 'login missing')
        else
          @login = @config.login
        end

        if @config.password.nil? || @config.login.empty?
          raise(Atol::MissingConfigError, 'password missing')
        else
          @password = @config.password
        end
      end

      def call
        uri = URI(Atol::URL + PATH)
        uri.query = URI.encode_www_form(login: login, pass: password)

        Net::HTTP.get_response(uri)
      end

      private

      attr_reader :login, :password
    end
  end
end

Version data entries

3 entries across 3 versions & 1 rubygems

Version Path
atol-0.1.2 lib/atol/request/get_token.rb
atol-0.1.1 lib/atol/request/get_token.rb
atol-0.1 lib/atol/request/get_token.rb