Class: Atol::Transaction::GetToken
- Inherits:
-
Object
- Object
- Atol::Transaction::GetToken
- Defined in:
- lib/atol/transaction/get_token.rb
Instance Method Summary collapse
- #call ⇒ Object
-
#initialize(config: nil) ⇒ GetToken
constructor
A new instance of GetToken.
Constructor Details
Instance Method Details
#call ⇒ Object
14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 |
# File 'lib/atol/transaction/get_token.rb', line 14 def call @config.req_tries_number.times do request = Atol::Request::GetToken.new(config: @config) response = request.call encoded_body = response.body.dup.force_encoding(Atol::ENCODING) json = JSON.parse(encoded_body) case response.code when '200' return json['token'] when '400' raise Atol::AuthBadRequestError when '401' raise Atol::AuthUserOrPasswordError when '500' next end raise "#{response.code} #{response.body}" end end |