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

new(faraday_response) click to toggle source
# 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

bad_request?() click to toggle source
# File lib/line_notify_client/response.rb, line 87
def bad_request?
  status == HTTP_STATUS_BAD_REQUEST
end
body() click to toggle source

### 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
error?() click to toggle source

### 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
headers() click to toggle source

### 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
internal_error?() click to toggle source
# File lib/line_notify_client/response.rb, line 95
def internal_error?
  status == HTTP_STATUS_INTERNAL_ERROR
end
status() click to toggle source

### 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
status_message() click to toggle source

### 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
success?() click to toggle source

### 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
token_expired?() click to toggle source
# File lib/line_notify_client/response.rb, line 91
def token_expired?
  status == HTTP_STATUS_TOKEN_EXPIRED
end