Class: Foto::Requests::Response
- Inherits:
-
Object
- Object
- Foto::Requests::Response
- Defined in:
- lib/foto/requests/response.rb
Defined Under Namespace
Classes: InvalidResponse
Instance Attribute Summary collapse
-
#body ⇒ Object
readonly
Returns the value of attribute body.
-
#code ⇒ Object
readonly
Returns the value of attribute code.
Instance Method Summary collapse
-
#initialize(http_response) ⇒ Response
constructor
A new instance of Response.
- #message ⇒ Object
- #successful? ⇒ Boolean
Constructor Details
#initialize(http_response) ⇒ Response
Returns a new instance of Response.
8 9 10 11 |
# File 'lib/foto/requests/response.rb', line 8 def initialize(http_response) @body = http_response.body @code = http_response.code end |
Instance Attribute Details
#body ⇒ Object (readonly)
Returns the value of attribute body.
4 5 6 |
# File 'lib/foto/requests/response.rb', line 4 def body @body end |
#code ⇒ Object (readonly)
Returns the value of attribute code.
4 5 6 |
# File 'lib/foto/requests/response.rb', line 4 def code @code end |
Instance Method Details
#message ⇒ Object
13 14 15 16 17 18 |
# File 'lib/foto/requests/response.rb', line 13 def doc = Nokogiri::HTML(body) doc.xpath('/html/body/p').first.content rescue NoMethodError => e raise InvalidResponse, "The response from FOTO could not be parsed.\nHTTP #{code} : #{body}" end |
#successful? ⇒ Boolean
20 21 22 |
# File 'lib/foto/requests/response.rb', line 20 def successful? code == '200' end |