Class: Raven::Response

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

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(http, _code, _path, _params) ⇒ Response

Initializing response object to be returned from API calls, used internally.



11
12
13
14
# File 'lib/rb_raven_api/response.rb', line 11

def initialize(http, _code, _path, _params) # @private
  @success, @body, @errors = http.success, http.response, http.errors
  @code, @path, @params    = _code, _path, _params
end

Instance Attribute Details

#bodyObject (readonly)

Returns the value of attribute body.



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

def body
  @body
end

#codeObject (readonly)

Returns the value of attribute code.



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

def code
  @code
end

#errorsObject (readonly)

Returns the value of attribute errors.



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

def errors
  @errors
end

#paramsObject (readonly)

Returns the value of attribute params.



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

def params
  @params
end

#pathObject (readonly)

Returns the value of attribute path.



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

def path
  @path
end

#successObject (readonly)

Returns the value of attribute success.



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

def success
  @success
end

Instance Method Details

#parsed_bodyHashie::Mash

Parses JSON body of request and returns a Hashie::Mash

Returns:

  • (Hashie::Mash)


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

def parsed_body
  hash = JSON.parse(@body) rescue {}
  return hash if hash.is_a?(Array)
  Hashie::Mash.new hash
end

#success?Boolean

Convenience method to determine if request was successfull or not

Returns:

  • (Boolean)


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

def success?
  !!@success
end