Class: Scruber::Helpers::FetcherAgentAdapters::AbstractAdapter
- Defined in:
- lib/scruber/helpers/fetcher_agent_adapters/abstract_adapter.rb
Direct Known Subclasses
Instance Attribute Summary collapse
-
#cookie_jar ⇒ Object
Returns the value of attribute cookie_jar.
-
#created_at ⇒ Object
Returns the value of attribute created_at.
-
#disable_proxy ⇒ Object
Returns the value of attribute disable_proxy.
-
#headers ⇒ Object
Returns the value of attribute headers.
-
#id ⇒ Object
Returns the value of attribute id.
-
#jar ⇒ Object
readonly
Returns the value of attribute jar.
-
#proxy_id ⇒ Object
Returns the value of attribute proxy_id.
-
#updated_at ⇒ Object
Returns the value of attribute updated_at.
-
#user_agent ⇒ Object
Returns the value of attribute user_agent.
Class Method Summary collapse
Instance Method Summary collapse
- #cookie_for(uri_or_url) ⇒ Object
- #delete ⇒ Object
-
#initialize(options = {}) ⇒ AbstractAdapter
constructor
A new instance of AbstractAdapter.
- #parse_cookies_from_page!(page) ⇒ Object
- #proxy ⇒ Object
- #save ⇒ Object
- #serialize_cookies ⇒ Object
Constructor Details
#initialize(options = {}) ⇒ AbstractAdapter
Returns a new instance of AbstractAdapter.
8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 |
# File 'lib/scruber/helpers/fetcher_agent_adapters/abstract_adapter.rb', line 8 def initialize(={}) @id = .fetch(:id) { nil } @user_agent = .fetch(:user_agent) { nil } @proxy_id = .fetch(:proxy_id) { nil } @headers = .fetch(:headers) { {} } @cookie_jar = .fetch(:cookie_jar) { {} } @disable_proxy = .fetch(:disable_proxy) { false } @updated_at = .fetch(:updated_at) { Time.now } @created_at = .fetch(:created_at) { Time.now } @jar = HTTP::CookieJar.new if @cookie_jar.is_a?(String) @jar.load(StringIO.new(@cookie_jar)) end @_proxy = false end |
Instance Attribute Details
#cookie_jar ⇒ Object
Returns the value of attribute cookie_jar.
5 6 7 |
# File 'lib/scruber/helpers/fetcher_agent_adapters/abstract_adapter.rb', line 5 def @cookie_jar end |
#created_at ⇒ Object
Returns the value of attribute created_at.
5 6 7 |
# File 'lib/scruber/helpers/fetcher_agent_adapters/abstract_adapter.rb', line 5 def created_at @created_at end |
#disable_proxy ⇒ Object
Returns the value of attribute disable_proxy.
5 6 7 |
# File 'lib/scruber/helpers/fetcher_agent_adapters/abstract_adapter.rb', line 5 def disable_proxy @disable_proxy end |
#headers ⇒ Object
Returns the value of attribute headers.
5 6 7 |
# File 'lib/scruber/helpers/fetcher_agent_adapters/abstract_adapter.rb', line 5 def headers @headers end |
#id ⇒ Object
Returns the value of attribute id.
5 6 7 |
# File 'lib/scruber/helpers/fetcher_agent_adapters/abstract_adapter.rb', line 5 def id @id end |
#jar ⇒ Object (readonly)
Returns the value of attribute jar.
6 7 8 |
# File 'lib/scruber/helpers/fetcher_agent_adapters/abstract_adapter.rb', line 6 def jar @jar end |
#proxy_id ⇒ Object
Returns the value of attribute proxy_id.
5 6 7 |
# File 'lib/scruber/helpers/fetcher_agent_adapters/abstract_adapter.rb', line 5 def proxy_id @proxy_id end |
#updated_at ⇒ Object
Returns the value of attribute updated_at.
5 6 7 |
# File 'lib/scruber/helpers/fetcher_agent_adapters/abstract_adapter.rb', line 5 def updated_at @updated_at end |
#user_agent ⇒ Object
Returns the value of attribute user_agent.
5 6 7 |
# File 'lib/scruber/helpers/fetcher_agent_adapters/abstract_adapter.rb', line 5 def user_agent @user_agent end |
Class Method Details
.find(id) ⇒ Object
61 62 63 |
# File 'lib/scruber/helpers/fetcher_agent_adapters/abstract_adapter.rb', line 61 def find(id) raise NotImplementedError end |
Instance Method Details
#cookie_for(uri_or_url) ⇒ Object
45 46 47 48 49 50 |
# File 'lib/scruber/helpers/fetcher_agent_adapters/abstract_adapter.rb', line 45 def (uri_or_url) if uri_or_url.is_a?(String) uri_or_url = URI(uri_or_url) end HTTP::Cookie.(@jar.(uri_or_url)) end |
#delete ⇒ Object
56 57 58 |
# File 'lib/scruber/helpers/fetcher_agent_adapters/abstract_adapter.rb', line 56 def delete raise NotImplementedError end |
#parse_cookies_from_page!(page) ⇒ Object
32 33 34 35 36 37 |
# File 'lib/scruber/helpers/fetcher_agent_adapters/abstract_adapter.rb', line 32 def (page) = page. .each do || @jar.parse(, URI(page.url)) end end |
#proxy ⇒ Object
24 25 26 27 28 29 30 |
# File 'lib/scruber/helpers/fetcher_agent_adapters/abstract_adapter.rb', line 24 def proxy if @_proxy == false @_proxy = (@proxy_id ? Scruber::Helpers::ProxyRotator.find(@proxy_id) : nil) else @_proxy end end |
#save ⇒ Object
52 53 54 |
# File 'lib/scruber/helpers/fetcher_agent_adapters/abstract_adapter.rb', line 52 def save raise NotImplementedError end |
#serialize_cookies ⇒ Object
39 40 41 42 43 |
# File 'lib/scruber/helpers/fetcher_agent_adapters/abstract_adapter.rb', line 39 def io = StringIO.new @jar.save(io) @cookie_jar = io.string end |