Class: Oja::Response

Inherits:
Object
  • Object
show all
Defined in:
lib/oja/response.rb

Constant Summary collapse

STATUS =
{
  0     => :active,
  21000 => :bad_json,
  21002 => :malformed,
  21003 => :authentication_error,
  21004 => :authentication_failed,
  21005 => :service_unavailable,
  21006 => :inactive,
  21007 => :sandbox_receipt_in_production,
  21008 => :production_receipt_in_sandbox
}
HUMANIZED_STATUS =
{
  0     => 'Active',
  21000 => 'Bad JSON',
  21002 => 'Malformed',
  21003 => 'Authentication Error',
  21004 => 'Authentication Failed',
  21005 => 'Service Unavailable',
  21006 => 'Inactive',
  21007 => 'Sandbox Receipt in Production',
  21008 => 'Production Receipt in Sandbox'
}

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(data) ⇒ Response

Returns a new instance of Response.



29
30
31
# File 'lib/oja/response.rb', line 29

def initialize(data)
  self.data = data
end

Instance Attribute Details

#receipt_dataObject (readonly)

Returns the value of attribute receipt_data.



27
28
29
# File 'lib/oja/response.rb', line 27

def receipt_data
  @receipt_data
end

#status_codeObject (readonly)

Returns the value of attribute status_code.



27
28
29
# File 'lib/oja/response.rb', line 27

def status_code
  @status_code
end

Class Method Details

.status_code(needle) ⇒ Object



52
53
54
55
56
57
# File 'lib/oja/response.rb', line 52

def self.status_code(needle)
  needle = needle.to_sym
  STATUS.each do |status_code, status|
    return status_code if needle == status
  end; nil
end

Instance Method Details

#data=(data) ⇒ Object



33
34
35
36
# File 'lib/oja/response.rb', line 33

def data=(data)
  @status_code  = data['status'].to_i
  @receipt_data = data['receipt']
end

#humanized_statusObject



42
43
44
# File 'lib/oja/response.rb', line 42

def humanized_status
  HUMANIZED_STATUS[status_code]
end

#statusObject



38
39
40
# File 'lib/oja/response.rb', line 38

def status
  STATUS[status_code]
end