Class: Github::Client::Response
- Inherits:
-
Object
- Object
- Github::Client::Response
- Defined in:
- lib/github/client.rb
Constant Summary collapse
- SUCCESS_CODES =
[200, 201]
- FAILURE_CODES =
[400, 401, 422]
Class Method Summary collapse
Instance Method Summary collapse
- #data ⇒ Object
- #error? ⇒ Boolean
- #error_message ⇒ Object
- #errors ⇒ Object
-
#initialize(response) ⇒ Response
constructor
A new instance of Response.
- #location ⇒ Object
- #rate_limit ⇒ Object
- #rate_limit_remaining ⇒ Object
- #success? ⇒ Boolean
- #to_s ⇒ Object
Constructor Details
#initialize(response) ⇒ Response
Returns a new instance of Response.
61 62 63 |
# File 'lib/github/client.rb', line 61 def initialize(response) @response = response end |
Class Method Details
.can_handle?(response) ⇒ Boolean
65 66 67 |
# File 'lib/github/client.rb', line 65 def self.can_handle?(response) (SUCCESS_CODES + FAILURE_CODES).include?(response.code) end |
Instance Method Details
#data ⇒ Object
101 102 103 |
# File 'lib/github/client.rb', line 101 def data parsed_response end |
#error? ⇒ Boolean
77 78 79 |
# File 'lib/github/client.rb', line 77 def error? when_statuses_are *FAILURE_CODES end |
#error_message ⇒ Object
81 82 83 |
# File 'lib/github/client.rb', line 81 def parsed_response["message"] end |
#errors ⇒ Object
85 86 87 |
# File 'lib/github/client.rb', line 85 def errors parsed_response["errors"].map { |hash| EntityError.new(hash) } end |
#location ⇒ Object
97 98 99 |
# File 'lib/github/client.rb', line 97 def location @response.headers[:location] end |
#rate_limit ⇒ Object
89 90 91 |
# File 'lib/github/client.rb', line 89 def rate_limit @response.headers[:x_ratelimit_limit].to_i end |
#rate_limit_remaining ⇒ Object
93 94 95 |
# File 'lib/github/client.rb', line 93 def rate_limit_remaining @response.headers[:x_ratelimit_remaining].to_i end |
#success? ⇒ Boolean
73 74 75 |
# File 'lib/github/client.rb', line 73 def success? when_statuses_are *SUCCESS_CODES end |
#to_s ⇒ Object
69 70 71 |
# File 'lib/github/client.rb', line 69 def to_s "#{@response.description.strip} | Rate limit: #{rate_limit_remaining} / #{rate_limit_remaining}" end |