Module: Sunbro
- Included in:
- Connection
- Defined in:
- lib/sunbro.rb,
lib/sunbro/http.rb,
lib/sunbro/page.rb,
lib/sunbro/version.rb,
lib/sunbro/settings.rb,
lib/sunbro/dynamic_http.rb
Defined Under Namespace
Modules: Settings
Classes: DynamicHTTP, HTTP, Page
Constant Summary
collapse
- MAX_RETRIES =
5
- VERSION =
"0.0.1"
Instance Method Summary
collapse
Instance Method Details
#close_http_connections ⇒ Object
39
40
41
42
43
|
# File 'lib/sunbro.rb', line 39
def close_http_connections
@http.close if @http
@dhttp.close if @dhttp
rescue IOError
end
|
#fetch_with_connection(conn, link, opts) ⇒ Object
29
30
31
32
33
34
35
36
37
|
# File 'lib/sunbro.rb', line 29
def fetch_with_connection(conn, link, opts)
page, tries = nil, MAX_RETRIES
begin
page = conn.fetch_page(link, opts)
sleep 1
end until page.try(:present?) || (tries -= 1).zero?
page.discard_doc! unless page.is_valid?
page
end
|
#get_page(link, opts = {}) ⇒ Object
19
20
21
22
|
# File 'lib/sunbro.rb', line 19
def get_page(link, opts={})
@http ||= HTTP.new
fetch_with_connection(@http, link, opts)
end
|
#render_page(link, opts = {}) ⇒ Object
24
25
26
27
|
# File 'lib/sunbro.rb', line 24
def render_page(link, opts={})
@dhttp ||= DynamicHTTP.new
fetch_with_connection(@dhttp, link, opts)
end
|