Module: GithubPivotalFlow::GitHubAPI::HttpMethods::ResponseMethods
- Defined in:
- lib/github_pivotal_flow/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
81 |
# File 'lib/github_pivotal_flow/github_api.rb', line 81 def data() @data ||= MultiJson.load(body) end |
#data? ⇒ Boolean
80 |
# File 'lib/github_pivotal_flow/github_api.rb', line 80 def data?() content_type =~ /\bjson\b/ end |
#error_message ⇒ Object
83 |
# File 'lib/github_pivotal_flow/github_api.rb', line 83 def () error_sentences || data['message'] end |
#error_message? ⇒ Boolean
82 |
# File 'lib/github_pivotal_flow/github_api.rb', line 82 def () data? and data['errors'] || data['message'] end |
#error_sentences ⇒ Object
85 86 87 88 89 90 91 92 93 94 95 96 97 |
# File 'lib/github_pivotal_flow/github_api.rb', line 85 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 '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
79 |
# File 'lib/github_pivotal_flow/github_api.rb', line 79 def status() code.to_i end |
#success? ⇒ Boolean
84 |
# File 'lib/github_pivotal_flow/github_api.rb', line 84 def success?() Net::HTTPSuccess === self end |