Class: Atol::Request::GetToken

Inherits:
Object
  • Object
show all
Defined in:
lib/atol/request/get_token.rb

Constant Summary collapse

PATH =
'/getToken'

Instance Method Summary collapse

Constructor Details

#initialize(config: nil) ⇒ GetToken

Returns a new instance of GetToken.



11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
# File 'lib/atol/request/get_token.rb', line 11

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

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

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

  @http_client = @config.http_client
end

Instance Method Details

#callObject



30
31
32
33
34
35
36
37
# File 'lib/atol/request/get_token.rb', line 30

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

  http = @http_client.new(uri.host, uri.port)
  http.use_ssl = true
  http.get(uri.request_uri)
end