Class: BeerList::Scraper

Inherits:
Object
  • Object
show all
Includes:
Singleton
Defined in:
lib/beer_list/scraper.rb

Constant Summary collapse

USER_AGENT =
'Mac Safari'

Instance Method Summary collapse

Constructor Details

#initializeScraper

Returns a new instance of Scraper.



9
10
11
12
# File 'lib/beer_list/scraper.rb', line 9

def initialize
  @agent = Mechanize.new
  set_user_agent
end

Instance Method Details

#beer_list(establishment) ⇒ Object



14
15
16
17
# File 'lib/beer_list/scraper.rb', line 14

def beer_list(establishment)
  visit establishment
  establishment.list
end

#send_json(url, json) ⇒ Object



23
24
25
26
27
# File 'lib/beer_list/scraper.rb', line 23

def send_json(url, json)
  url = "http://#{url}" unless url.start_with? 'http://'
  agent.post url, "{\"beer_list\": #{json}}", 'Content-Type' => 'application/json'
  true
end

#visit(visitable) ⇒ Object



19
20
21
# File 'lib/beer_list/scraper.rb', line 19

def visit(visitable)
  visitable.page = agent.get(visitable.url)
end