Sha256: 4ba6d2fd0ddf6a7cb1423195c3167632f263c438221db31a6adba04e83bc0725
Contents?: true
Size: 947 Bytes
Versions: 1
Compression:
Stored size: 947 Bytes
Contents
require 'nokogiri' require 'capybara/poltergeist' require 'rest-client' require 'webrick/cookie' require 'active_support/all' require 'retryable' %w( sunbro/version sunbro/settings sunbro/dynamic_http sunbro/http sunbro/page sunbro/initialize ).each do |f| require f end module Sunbro MAX_RETRIES = 5 def get_page(link, opts={}) fetch_with_connection(http, link, opts) end def render_page(link, opts={}) fetch_with_connection(dhttp, link, opts) end 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 def http @http ||= HTTP.new end def dhttp @dhttp ||= DynamicHTTP.new end def close_http_connections @http.close if @http @dhttp.close if @dhttp rescue IOError end end
Version data entries
1 entries across 1 versions & 1 rubygems
Version | Path |
---|---|
sunbro-0.1.2 | lib/sunbro.rb |