Class: GitMarkdown::Api::Response
- Inherits:
-
Object
- Object
- GitMarkdown::Api::Response
- Defined in:
- lib/git/markdown/api/response.rb
Instance Attribute Summary collapse
-
#raw_response ⇒ Object
readonly
Returns the value of attribute raw_response.
Instance Method Summary collapse
- #data ⇒ Object
- #error_message ⇒ Object
-
#initialize(response) ⇒ Response
constructor
A new instance of Response.
- #not_found? ⇒ Boolean
- #success? ⇒ Boolean
- #unauthorized? ⇒ Boolean
Constructor Details
#initialize(response) ⇒ Response
Returns a new instance of Response.
8 9 10 |
# File 'lib/git/markdown/api/response.rb', line 8 def initialize(response) @raw_response = response end |
Instance Attribute Details
#raw_response ⇒ Object (readonly)
Returns the value of attribute raw_response.
6 7 8 |
# File 'lib/git/markdown/api/response.rb', line 6 def raw_response @raw_response end |
Instance Method Details
#data ⇒ Object
24 25 26 27 28 29 30 |
# File 'lib/git/markdown/api/response.rb', line 24 def data return nil unless @raw_response.body JSON.parse(@raw_response.body) rescue JSON::ParserError nil end |
#error_message ⇒ Object
32 33 34 35 36 37 38 39 40 |
# File 'lib/git/markdown/api/response.rb', line 32 def return nil if success? if data && data["message"] data["message"] else "HTTP #{@raw_response.code}: #{@raw_response.}" end end |
#not_found? ⇒ Boolean
16 17 18 |
# File 'lib/git/markdown/api/response.rb', line 16 def not_found? @raw_response.is_a?(Net::HTTPNotFound) end |
#success? ⇒ Boolean
12 13 14 |
# File 'lib/git/markdown/api/response.rb', line 12 def success? @raw_response.is_a?(Net::HTTPSuccess) end |
#unauthorized? ⇒ Boolean
20 21 22 |
# File 'lib/git/markdown/api/response.rb', line 20 def @raw_response.is_a?(Net::HTTPUnauthorized) end |