Class: Wayfarer::Networking::NetHTTP
- Inherits:
-
Object
- Object
- Wayfarer::Networking::NetHTTP
- Includes:
- Singleton
- Defined in:
- lib/wayfarer/networking/net_http.rb
Instance Attribute Summary collapse
-
#body ⇒ Object
readonly
Returns the value of attribute body.
-
#conn ⇒ Object
readonly
Returns the value of attribute conn.
Class Method Summary collapse
Instance Method Summary collapse
- #browser ⇒ Object
- #capybara ⇒ Object
- #fetch(url) ⇒ Object
- #free ⇒ Object
-
#initialize ⇒ NetHTTP
constructor
A new instance of NetHTTP.
- #live(current_page) ⇒ Object
- #renew ⇒ Object
Constructor Details
#initialize ⇒ NetHTTP
Returns a new instance of NetHTTP.
15 16 17 18 19 20 21 |
# File 'lib/wayfarer/networking/net_http.rb', line 15 def initialize @conn = Net::HTTP::Persistent.new("wayfarer-#{SecureRandom.uuid}") Wayfarer.config.http_headers.each do |key, val| conn.override_headers[key] = val end end |
Instance Attribute Details
#body ⇒ Object (readonly)
Returns the value of attribute body.
12 13 14 |
# File 'lib/wayfarer/networking/net_http.rb', line 12 def body @body end |
#conn ⇒ Object (readonly)
Returns the value of attribute conn.
12 13 14 |
# File 'lib/wayfarer/networking/net_http.rb', line 12 def conn @conn end |
Class Method Details
.renew_on ⇒ Object
8 9 10 |
# File 'lib/wayfarer/networking/net_http.rb', line 8 def self.renew_on [] end |
Instance Method Details
#browser ⇒ Object
25 |
# File 'lib/wayfarer/networking/net_http.rb', line 25 def browser; end |
#capybara ⇒ Object
27 |
# File 'lib/wayfarer/networking/net_http.rb', line 27 def ; end |
#fetch(url) ⇒ Object
29 30 31 32 33 34 35 36 37 38 39 40 41 |
# File 'lib/wayfarer/networking/net_http.rb', line 29 def fetch(url) res = conn.request(URI(url)) return Result::Redirect.new(url, res["location"]) if res.is_a?(Net::HTTPRedirection) @body = res.body page = Wayfarer::Page.new(url: url, status_code: res.code.to_i, body: body, headers: res.to_hash) Result::Success.new(page) end |
#free ⇒ Object
47 48 49 |
# File 'lib/wayfarer/networking/net_http.rb', line 47 def free conn.shutdown end |
#live(current_page) ⇒ Object
43 44 45 |
# File 'lib/wayfarer/networking/net_http.rb', line 43 def live(current_page) current_page end |
#renew ⇒ Object
23 |
# File 'lib/wayfarer/networking/net_http.rb', line 23 def renew; end |