Class: PushBot::Response

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

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(request) ⇒ Response

Returns a new instance of Response.



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

def initialize(request)
  @raw_response = request.run

  @success = raw_response.success?
rescue => e
  @error = e
end

Instance Attribute Details

#errorObject (readonly)

Returns the value of attribute error.



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

def error
  @error
end

#raw_responseObject (readonly)

Returns the value of attribute raw_response.



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

def raw_response
  @raw_response
end

Instance Method Details

#bodyObject

The raw response body string



28
29
30
# File 'lib/push_bot/response.rb', line 28

def body
  raw_response.try(:body)
end

#error?Boolean

Did the response complete with an error

Returns:

  • (Boolean)


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

def error?
  defined?(@error) && @error
end

#inspectObject



13
14
15
# File 'lib/push_bot/response.rb', line 13

def inspect
  "#<#{self.class}:#{object_id} @success=#{success?} @json=#{json}>"
end

#jsonHash, Array

The result of the request as a JSON Object

Returns:

  • (Hash, Array)

    the JSON Object



35
36
37
# File 'lib/push_bot/response.rb', line 35

def json
  @json ||= body.present? ? JSON.parse(body) : {}
end

#success?Boolean

Did the request complete successfully or have issues

Returns:

  • (Boolean)


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

def success?
  defined?(@success) && @success
end