class BeerList::Scraper

Constants

USER_AGENT

Public Class Methods

new() click to toggle source
# File lib/beer_list/scraper.rb, line 9
def initialize
  @agent = Mechanize.new
  set_user_agent
end

Public Instance Methods

beer_list(establishment) click to toggle source
# File lib/beer_list/scraper.rb, line 14
def beer_list(establishment)
  visit establishment
  establishment.list
end
send_json(url, json) click to toggle source
# 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) click to toggle source
# File lib/beer_list/scraper.rb, line 19
def visit(visitable)
  visitable.page = agent.get(visitable.url)
end

Private Instance Methods

agent() click to toggle source
# File lib/beer_list/scraper.rb, line 35
def agent
  @agent
end
set_user_agent() click to toggle source
# File lib/beer_list/scraper.rb, line 31
def set_user_agent
  agent.user_agent_alias = USER_AGENT
end