Class: Kassa24::Result

Inherits:
Object
  • Object
show all
Defined in:
lib/kassa24/result.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(response) ⇒ Result

Returns a new instance of Result.



5
6
7
8
9
10
11
# File 'lib/kassa24/result.rb', line 5

def initialize(response)
  body = response.body.gsub(/Field "([a-zA-Z]+)"/, '\"\1\"') # unescape bad json
  @value = JSON.parse(body, symbolize_names: true)

  @error = [:bad_credentials, {}] if response.status == 401
  @error = [:bad_data, { message: @value[:error] }] if response.status == 400
end

Instance Attribute Details

#errorObject (readonly)

Returns the value of attribute error.



3
4
5
# File 'lib/kassa24/result.rb', line 3

def error
  @error
end

#valueObject (readonly)

Returns the value of attribute value.



3
4
5
# File 'lib/kassa24/result.rb', line 3

def value
  @value
end

Instance Method Details

#success?Boolean

Returns:

  • (Boolean)


13
14
15
# File 'lib/kassa24/result.rb', line 13

def success?
  @error.nil?
end