Module: Hub::GitHubAPI::HttpMethods::ResponseMethods
- Defined in:
- lib/hub/github_api.rb
Overview
Decorator for Net::HTTPResponse
Instance Method Summary collapse
- #data ⇒ Object
- #data? ⇒ Boolean
- #error_message ⇒ Object
- #error_message? ⇒ Boolean
- #error_sentences ⇒ Object
- #status ⇒ Object
- #success? ⇒ Boolean
Instance Method Details
#data ⇒ Object
176 |
# File 'lib/hub/github_api.rb', line 176 def data() @data ||= JSON.parse(body) end |
#data? ⇒ Boolean
175 |
# File 'lib/hub/github_api.rb', line 175 def data?() content_type =~ /\bjson\b/ end |
#error_message ⇒ Object
178 |
# File 'lib/hub/github_api.rb', line 178 def () error_sentences || data['message'] end |
#error_message? ⇒ Boolean
177 |
# File 'lib/hub/github_api.rb', line 177 def () data? and data['errors'] || data['message'] end |
#error_sentences ⇒ Object
180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 |
# File 'lib/hub/github_api.rb', line 180 def error_sentences data['errors'].map do |err| case err['code'] when 'custom' then err['message'] when 'missing_field' %(Missing field: "%s") % err['field'] when 'already_exists' %(Duplicate value for "%s") % err['field'] when 'invalid' %(Invalid value for "%s": "%s") % [ err['field'], err['value'] ] when 'unauthorized' %(Not allowed to change field "%s") % err['field'] end end.compact if data['errors'] end |
#status ⇒ Object
174 |
# File 'lib/hub/github_api.rb', line 174 def status() code.to_i end |
#success? ⇒ Boolean
179 |
# File 'lib/hub/github_api.rb', line 179 def success?() Net::HTTPSuccess === self end |