Class: Unfuddle::Response
- Inherits:
-
Object
- Object
- Unfuddle::Response
- Defined in:
- lib/unfuddle/response.rb
Class Method Summary collapse
Instance Method Summary collapse
- #body ⇒ Object
-
#initialize(faraday_response) ⇒ Response
constructor
A new instance of Response.
- #json ⇒ Object
- #location ⇒ Object
- #server_error? ⇒ Boolean
- #status ⇒ Object
- #unauthorized? ⇒ Boolean
Constructor Details
#initialize(faraday_response) ⇒ Response
Returns a new instance of Response.
8 9 10 |
# File 'lib/unfuddle/response.rb', line 8 def initialize(faraday_response) @faraday_response = faraday_response end |
Class Method Details
.normalized_body(body) ⇒ Object
39 40 41 |
# File 'lib/unfuddle/response.rb', line 39 def self.normalized_body(body) body.gsub(/\u0000/, "").strip end |
Instance Method Details
#body ⇒ Object
24 25 26 |
# File 'lib/unfuddle/response.rb', line 24 def body faraday_response.body end |
#json ⇒ Object
32 33 34 35 36 37 |
# File 'lib/unfuddle/response.rb', line 32 def json @json ||= begin json = self.class.normalized_body(body) json.empty? ? {} : JSON.load(json) end end |
#location ⇒ Object
28 29 30 |
# File 'lib/unfuddle/response.rb', line 28 def location faraday_response["location"] end |
#server_error? ⇒ Boolean
16 17 18 |
# File 'lib/unfuddle/response.rb', line 16 def server_error? status == 500 end |
#status ⇒ Object
12 13 14 |
# File 'lib/unfuddle/response.rb', line 12 def status faraday_response.status end |
#unauthorized? ⇒ Boolean
20 21 22 |
# File 'lib/unfuddle/response.rb', line 20 def status == 401 end |