Class: Lifestream::Request
- Inherits:
-
Object
- Object
- Lifestream::Request
- Defined in:
- lib/lifestream/request.rb
Defined Under Namespace
Classes: TooManyRedirects
Instance Attribute Summary collapse
-
#max_redirects ⇒ Object
Returns the value of attribute max_redirects.
-
#url ⇒ Object
Returns the value of attribute url.
Instance Method Summary collapse
- #get(url = @url) ⇒ Object
-
#initialize(url, options = {}) ⇒ Request
constructor
A new instance of Request.
Constructor Details
#initialize(url, options = {}) ⇒ Request
Returns a new instance of Request.
6 7 8 9 10 |
# File 'lib/lifestream/request.rb', line 6 def initialize(url, = {}) @url = url [:max_redirects] ||= 5 @max_redirects = [:max_redirects] end |
Instance Attribute Details
#max_redirects ⇒ Object
Returns the value of attribute max_redirects.
4 5 6 |
# File 'lib/lifestream/request.rb', line 4 def max_redirects @max_redirects end |
#url ⇒ Object
Returns the value of attribute url.
4 5 6 |
# File 'lib/lifestream/request.rb', line 4 def url @url end |
Instance Method Details
#get(url = @url) ⇒ Object
12 13 14 15 16 17 18 19 20 21 22 23 24 |
# File 'lib/lifestream/request.rb', line 12 def get(url = @url) check_max_redirects url, request = build_request(url) response = Net::HTTP.start(url.host, url.port) do |http| http.request(request) end if response.kind_of?(Net::HTTPRedirection) @redirect += 1 get(response.header['location']) else response end end |