Class: Botz::Connector::Html

Inherits:
Object
  • Object
show all
Includes:
Field
Defined in:
lib/botz/connector/html.rb

Overview

Mechanize wrapper

Defined Under Namespace

Modules: Field

Constant Summary collapse

USER_AGENT =
[
  'Mozilla/5.0',
  '(Macintosh; Intel Mac OS X 10_12_6)',
  'AppleWebKit/537.36',
  '(KHTML, like Gecko)',
  'Chrome/64.0.3282.186',
  'Safari/537.36'
].join(' ')

Instance Attribute Summary collapse

Instance Method Summary collapse

Methods included from Field

#field

Constructor Details

#initialize(start_url: nil, encoding: nil) ⇒ Html

Returns a new instance of Html.



33
34
35
36
37
38
39
40
41
# File 'lib/botz/connector/html.rb', line 33

def initialize(start_url: nil, encoding: nil)
  @start_url = start_url
  @agent = Mechanize.new
  if encoding
    @agent.default_encoding = encoding
    @agent.force_default_encoding = true
  end
  @agent.user_agent = USER_AGENT
end

Instance Attribute Details

#agentObject (readonly)

Returns the value of attribute agent.



31
32
33
# File 'lib/botz/connector/html.rb', line 31

def agent
  @agent
end

#start_urlObject (readonly)

Returns the value of attribute start_url.



30
31
32
# File 'lib/botz/connector/html.rb', line 30

def start_url
  @start_url
end

Instance Method Details

#call(url = @start_url, &block) ⇒ Object



43
44
45
46
47
# File 'lib/botz/connector/html.rb', line 43

def call(url = @start_url, &block)
  fail 'URL is undefined' if url.blank?

  agent.get(url, &block)
end