Class: FbResource::Http
- Inherits:
-
Object
- Object
- FbResource::Http
- Defined in:
- lib/http/http.rb
Instance Attribute Summary collapse
-
#body ⇒ Object
Returns the value of attribute body.
-
#request ⇒ Object
Returns the value of attribute request.
-
#response ⇒ Object
Returns the value of attribute response.
Class Method Summary collapse
Instance Method Summary collapse
-
#initialize(body, request, response) ⇒ Http
constructor
A new instance of Http.
- #run ⇒ Object
- #success? ⇒ Boolean
Constructor Details
#initialize(body, request, response) ⇒ Http
Returns a new instance of Http.
19 20 21 |
# File 'lib/http/http.rb', line 19 def initialize(body, request, response) @body, @request, @response = body, request, response end |
Instance Attribute Details
#body ⇒ Object
Returns the value of attribute body.
17 18 19 |
# File 'lib/http/http.rb', line 17 def body @body end |
#request ⇒ Object
Returns the value of attribute request.
17 18 19 |
# File 'lib/http/http.rb', line 17 def request @request end |
#response ⇒ Object
Returns the value of attribute response.
17 18 19 |
# File 'lib/http/http.rb', line 17 def response @response end |
Class Method Details
.get(url, headers) ⇒ Object
7 8 9 10 11 12 13 14 15 |
# File 'lib/http/http.rb', line 7 def self.get(url, headers) i = self.new(nil, nil, nil) RestClient.get(url, headers) do |a, b, c| i.body, i.request, i.response = a, b, c i.run end rescue => e BadHttpResp.new(e, e, e) # ? end |
Instance Method Details
#run ⇒ Object
23 24 25 |
# File 'lib/http/http.rb', line 23 def run (success? ? GoodHttpResp : BadHttpResp).new(body, request, response) end |
#success? ⇒ Boolean
27 28 29 |
# File 'lib/http/http.rb', line 27 def success? response.code[0].to_i == 2 end |