Module: LCBO

Defined in:
lib/lcbo.rb,
lib/lcbo/ext.rb,
lib/lcbo/helpers.rb,
lib/lcbo/version.rb,
lib/lcbo/crawlkit.rb,
lib/lcbo/crawlkit/page.rb,
lib/lcbo/crawlkit/crawler.rb,
lib/lcbo/crawlkit/request.rb,
lib/lcbo/pages/store_page.rb,
lib/lcbo/crawlkit/response.rb,
lib/lcbo/crawlkit/eventable.rb,
lib/lcbo/pages/product_page.rb,
lib/lcbo/crawlkit/tag_helper.rb,
lib/lcbo/pages/inventory_page.rb,
lib/lcbo/crawlkit/phone_helper.rb,
lib/lcbo/pages/store_list_page.rb,
lib/lcbo/crawlkit/volume_helper.rb,
lib/lcbo/crawlkit/caption_helper.rb,
lib/lcbo/pages/product_list_page.rb,
lib/lcbo/crawlkit/fastdate_helper.rb,
lib/lcbo/crawlkit/titlecase_helper.rb,
lib/lcbo/crawlkit/request_prototype.rb

Defined Under Namespace

Modules: CrawlKit, HashExt Classes: InventoryPage, ProductListPage, ProductPage, StoreListPage, StorePage

Constant Summary collapse

DEFAULT_CONFIG =
{
  :user_agent  => nil, # Use the default User-Agent by default
  :max_retries => 8,   # Number of times to retry a request that fails
  :timeout     => 2    # Seconds to wait for a request before timing out
}.freeze
PAGE_TYPES =
{
  :product      => 'ProductPage',
  :product_list => 'ProductListPage',
  :store_list   => 'StoreListPage',
  :store        => 'StorePage',
  :inventory    => 'InventoryPage'
}
VERSION =
'1.2.3'

Class Method Summary collapse

Class Method Details

.configObject


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

def self.config
  reset_config! unless @config
  @config
end

.inventory(product_id) ⇒ Object


27
28
29
# File 'lib/lcbo/helpers.rb', line 27

def self.inventory(product_id)
  InventoryPage.process(:product_id => product_id).as_hash
end

.page(type) ⇒ Object


11
12
13
# File 'lib/lcbo/helpers.rb', line 11

def self.page(type)
  Object.const_get(PAGE_TYPES[type.to_sym])
end

.parse(page_type, response) ⇒ Object


15
16
17
# File 'lib/lcbo/helpers.rb', line 15

def self.parse(page_type, response)
  page[page_type].parse(response)
end

.product(id) ⇒ Object


19
20
21
# File 'lib/lcbo/helpers.rb', line 19

def self.product(id)
  ProductPage.process(:id => id).as_hash
end

.product_list(page_num) ⇒ Object


31
32
33
# File 'lib/lcbo/helpers.rb', line 31

def self.product_list(page_num)
  ProductListPage.process({}, :page => page_num).as_hash
end

.reset_config!Object


14
15
16
# File 'lib/lcbo.rb', line 14

def self.reset_config!
  @config = DEFAULT_CONFIG.dup
end

.store(id) ⇒ Object


23
24
25
# File 'lib/lcbo/helpers.rb', line 23

def self.store(id)
  StorePage.process(:id => id).as_hash
end

.store_listObject


35
36
37
# File 'lib/lcbo/helpers.rb', line 35

def self.store_list
  StoreListPage.process({}, {}).as_hash
end