class LineNotify::Response
## LineNotify::Response
A class for response data returned from API.
Constants
- HTTP_STATUS_BAD_REQUEST
- HTTP_STATUS_INTERNAL_ERROR
- HTTP_STATUS_SUCCESS
- HTTP_STATUS_TOKEN_EXPIRED
Public Class Methods
# File lib/line_notify_client/response.rb, line 13 def initialize(faraday_response) @raw_body = faraday_response.body @raw_headers = faraday_response.headers @raw_status = faraday_response.status end
Public Instance Methods
# File lib/line_notify_client/response.rb, line 87 def bad_request? status == HTTP_STATUS_BAD_REQUEST end
### LineNotify::Response#body
Returns response body returned from API as a `Hash`.
“`rb response.body #=> { … } “`
# File lib/line_notify_client/response.rb, line 26 def body @raw_body end
### LineNotify::Response#status
Returns response status from API as a `TrueClass` or `FalseClass`.
“`rb response.success? #=> true “`
# File lib/line_notify_client/response.rb, line 83 def error? !success? end
### LineNotify::Response#headers
Returns response headers returned from API as a `Hash`.
“`rb response.headers #=> { “Content-Type” => “application/json” } “`
# File lib/line_notify_client/response.rb, line 37 def headers @headers ||= @raw_headers.inject({}) do |result, (key, value)| result.merge(key.split("-").map(&:capitalize).join("-") => value) end end
# File lib/line_notify_client/response.rb, line 95 def internal_error? status == HTTP_STATUS_INTERNAL_ERROR end
### LineNotify::Response#status
Returns response status code returned from API as a `Integer`.
“`rb response.status #=> 200 “`
# File lib/line_notify_client/response.rb, line 50 def status @raw_status end
### LineNotify::Response#status_message
Returns response status message returned from API as a `String`.
“`rb response.status_message #=> “OK” “`
# File lib/line_notify_client/response.rb, line 61 def status_message Rack::Utils::HTTP_STATUS_CODES[status] end
### LineNotify::Response#success?
Returns success boolean value from API as a `TrueClass` or `FalseClass`.
“`rb response.success? #=> true “`
# File lib/line_notify_client/response.rb, line 72 def success? status == HTTP_STATUS_SUCCESS end
# File lib/line_notify_client/response.rb, line 91 def token_expired? status == HTTP_STATUS_TOKEN_EXPIRED end