Class: Telegrammer::ApiResponse
- Inherits:
-
Object
- Object
- Telegrammer::ApiResponse
- Defined in:
- lib/telegrammer/api_response.rb
Instance Attribute Summary collapse
-
#body ⇒ Object
readonly
Returns the value of attribute body.
-
#result ⇒ Object
readonly
Returns the value of attribute result.
-
#success ⇒ Object
(also: #success?)
readonly
Returns the value of attribute success.
Instance Method Summary collapse
-
#initialize(response, fail_silently = false) ⇒ ApiResponse
constructor
A new instance of ApiResponse.
Constructor Details
#initialize(response, fail_silently = false) ⇒ ApiResponse
Returns a new instance of ApiResponse.
7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 |
# File 'lib/telegrammer/api_response.rb', line 7 def initialize(response,fail_silently = false) if response.status < 500 @body = response.body data = MultiJson.load(@body) @success = data['ok'] if @success @result = data['result'] else if !fail_silently fail Telegrammer::Errors::BadRequestError.new(data['error_code'], data['description']) end end else if !fail_silently fail Telegrammer::Errors::ServiceUnavailableError.new(response.status) end end end |
Instance Attribute Details
#body ⇒ Object (readonly)
Returns the value of attribute body.
3 4 5 |
# File 'lib/telegrammer/api_response.rb', line 3 def body @body end |
#result ⇒ Object (readonly)
Returns the value of attribute result.
4 5 6 |
# File 'lib/telegrammer/api_response.rb', line 4 def result @result end |
#success ⇒ Object (readonly) Also known as: success?
Returns the value of attribute success.
5 6 7 |
# File 'lib/telegrammer/api_response.rb', line 5 def success @success end |