Class: Checkmobi::SDK::Response

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

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(response) ⇒ Response

Returns a new instance of Response.



7
8
9
10
# File 'lib/checkmobi/response.rb', line 7

def initialize(response)
  @body = response.body
  @code = response.code
end

Instance Attribute Details

#bodyObject

Returns the value of attribute body.



5
6
7
# File 'lib/checkmobi/response.rb', line 5

def body
  @body
end

#codeObject

Returns the value of attribute code.



5
6
7
# File 'lib/checkmobi/response.rb', line 5

def code
  @code
end

Instance Method Details

#to_hObject



12
13
14
15
16
# File 'lib/checkmobi/response.rb', line 12

def to_h
  JSON.parse(@body)
rescue => err
  raise err
end

#to_h!Hash

Replace @body with Ruby Hash

Returns:

  • (Hash)

    A standard Ruby Hash containing the HTTP result.



21
22
23
24
25
# File 'lib/checkmobi/response.rb', line 21

def to_h!
  @body = JSON.parse(@body)
rescue => err
  raise ParseError.new(err), err
end

#to_yamlString

Return response as Yaml

Returns:

  • (String)

    A string containing response as YAML



30
31
32
33
34
# File 'lib/checkmobi/response.rb', line 30

def to_yaml
  YAML.dump(to_h)
rescue => err
  raise err
end

#to_yaml!String

Replace @body with YAML

Returns:

  • (String)

    A string containing response as YAML



39
40
41
42
43
# File 'lib/checkmobi/response.rb', line 39

def to_yaml!
  @body = YAML.dump(to_h)
rescue => err
  raise ParseError.new(err), err
end