Class: Cangrejo::Session
- Inherits:
-
Object
- Object
- Cangrejo::Session
- Defined in:
- lib/cangrejo/session.rb
Constant Summary collapse
- WAIT_STEP =
Ruby sockets automatically timeout after 60 secs
45.0
Instance Attribute Summary collapse
-
#doc ⇒ Object
readonly
Returns the value of attribute doc.
-
#state_name ⇒ Object
readonly
Returns the value of attribute state_name.
-
#state_params ⇒ Object
readonly
Returns the value of attribute state_params.
Class Method Summary collapse
Instance Method Summary collapse
- #crawl(_state, _params = {}) ⇒ Object (also: #navigate)
- #elapsed ⇒ Object
-
#initialize(_name_or_config) ⇒ Session
constructor
A new instance of Session.
- #raw_doc ⇒ Object
- #release ⇒ Object
- #start ⇒ Object
- #started? ⇒ Boolean
Constructor Details
#initialize(_name_or_config) ⇒ Session
Returns a new instance of Session.
21 22 23 24 25 26 27 28 29 30 31 |
# File 'lib/cangrejo/session.rb', line 21 def initialize(_name_or_config) = if _name_or_config.is_a? Hash @name = nil _name_or_config else @name = _name_or_config Cangrejo.config.crawlers.fetch(_name_or_config, {}) end select_mode end |
Instance Attribute Details
#doc ⇒ Object (readonly)
Returns the value of attribute doc.
9 10 11 |
# File 'lib/cangrejo/session.rb', line 9 def doc @doc end |
#state_name ⇒ Object (readonly)
Returns the value of attribute state_name.
9 10 11 |
# File 'lib/cangrejo/session.rb', line 9 def state_name @state_name end |
#state_params ⇒ Object (readonly)
Returns the value of attribute state_params.
9 10 11 |
# File 'lib/cangrejo/session.rb', line 9 def state_params @state_params end |
Class Method Details
Instance Method Details
#crawl(_state, _params = {}) ⇒ Object Also known as:
51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 |
# File 'lib/cangrejo/session.rb', line 51 def crawl(_state, _params={}) raise ConfigurationError.new 'Session not started' if @rest.nil? params = (_params) begin while_times_out do @rest.put(name: _state, params: params, wait: WAIT_STEP) @state_name = _state @state_params = _params end rescue RestClient::InternalServerError => exc raise unwrap_packed_exception exc end wrap_response_doc self end |
#elapsed ⇒ Object
43 44 45 |
# File 'lib/cangrejo/session.rb', line 43 def elapsed @rest.elapsed end |
#raw_doc ⇒ Object
47 48 49 |
# File 'lib/cangrejo/session.rb', line 47 def raw_doc @rest.doc end |
#release ⇒ Object
72 73 74 75 76 |
# File 'lib/cangrejo/session.rb', line 72 def release @mode.release @rest = nil self end |
#start ⇒ Object
37 38 39 40 41 |
# File 'lib/cangrejo/session.rb', line 37 def start raise ConfigurationError.new 'Session already started' unless @rest.nil? @rest = @mode.setup self end |
#started? ⇒ Boolean
33 34 35 |
# File 'lib/cangrejo/session.rb', line 33 def started? not @rest.nil? end |