Class: Instamojo::Response

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

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(hash) ⇒ Response

Returns a new instance of Response.



5
6
7
8
9
10
11
12
13
14
15
16
# File 'lib/response.rb', line 5

def initialize(hash)
  @code = hash.status
  if hash.body
    begin
      @body = JSON.parse(hash.body)
    rescue JSON::ParserError
      @body = {:client_error => "Something went wrong", :original => hash.body.to_s}
    end
    @body.symbolize_keys!
    @status = @body[:success]
  end
end

Instance Attribute Details

#bodyObject (readonly)

Returns the value of attribute body.



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

def body
  @body
end

#codeObject (readonly)

Returns the value of attribute code.



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

def code
  @code
end

Instance Method Details

#response_success?Boolean

Returns:

  • (Boolean)


18
19
20
# File 'lib/response.rb', line 18

def response_success?
  [200, 201, 202, 203, 204].include? @code
end

#success?Boolean

Returns:

  • (Boolean)


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

def success?
  (@status && (@status.eql?(true) || @status.downcase == 'success')) || response_success?
end