lcbo 0.9.0
Sign up to get free protection for your applications and to get access to all the features.
- data/.gitignore +1 -0
- data/CHANGELOG.md +3 -0
- data/Gemfile +6 -0
- data/Gemfile.lock +18 -0
- data/LICENSE +18 -0
- data/README.md +29 -0
- data/Rakefile +62 -0
- data/lcbo.gemspec +29 -0
- data/lib/lcbo.rb +23 -0
- data/lib/lcbo/crawlers.rb +4 -0
- data/lib/lcbo/crawlers/inventories_crawler.rb +15 -0
- data/lib/lcbo/crawlers/product_lists_crawler.rb +23 -0
- data/lib/lcbo/crawlers/products_crawler.rb +16 -0
- data/lib/lcbo/crawlers/stores_crawler.rb +16 -0
- data/lib/lcbo/crawlkit.rb +24 -0
- data/lib/lcbo/crawlkit/eventable.rb +56 -0
- data/lib/lcbo/crawlkit/fastdate_helper.rb +40 -0
- data/lib/lcbo/crawlkit/page.rb +141 -0
- data/lib/lcbo/crawlkit/request.rb +51 -0
- data/lib/lcbo/crawlkit/request_prototype.rb +31 -0
- data/lib/lcbo/crawlkit/response.rb +48 -0
- data/lib/lcbo/crawlkit/titlecase_helper.rb +97 -0
- data/lib/lcbo/crawlkit/volume_helper.rb +46 -0
- data/lib/lcbo/ext.rb +13 -0
- data/lib/lcbo/helpers.rb +34 -0
- data/lib/lcbo/pages.rb +4 -0
- data/lib/lcbo/pages/inventory_page.rb +60 -0
- data/lib/lcbo/pages/product_list_page.rb +85 -0
- data/lib/lcbo/pages/product_page.rb +296 -0
- data/lib/lcbo/pages/store_page.rb +196 -0
- data/lib/lcbo/version.rb +3 -0
- data/spec/crawlkit/eventable_spec.rb +23 -0
- data/spec/crawlkit/fastdate_helper_spec.rb +18 -0
- data/spec/crawlkit/page_spec.rb +114 -0
- data/spec/crawlkit/request_prototype_spec.rb +5 -0
- data/spec/crawlkit/request_spec.rb +41 -0
- data/spec/crawlkit/response_spec.rb +5 -0
- data/spec/crawlkit/titlecase_helper_spec.rb +30 -0
- data/spec/crawlkit/volume_helper_spec.rb +21 -0
- data/spec/crawlkit_spec.rb +5 -0
- data/spec/lcbo_spec.rb +38 -0
- data/spec/pages/inventory_pages.yml +1685 -0
- data/spec/pages/inventory_pages/1.html +11649 -0
- data/spec/pages/inventory_pages/2.html +495 -0
- data/spec/pages/product_list_pages.yml +108 -0
- data/spec/pages/product_list_pages/1.html +4866 -0
- data/spec/pages/product_pages.yml +258 -0
- data/spec/pages/product_pages/1.html +1319 -0
- data/spec/pages/product_pages/2.html +1343 -0
- data/spec/pages/product_pages/3.html +1336 -0
- data/spec/pages/product_pages/4.html +1319 -0
- data/spec/pages/product_pages/5.html +1324 -0
- data/spec/pages/product_pages/6.html +1319 -0
- data/spec/pages/product_pages/7.html +1314 -0
- data/spec/pages/store_pages.yml +80 -0
- data/spec/pages/store_pages/1.html +592 -0
- data/spec/pages/store_pages/2.html +592 -0
- data/spec/pages_spec.rb +34 -0
- data/spec/spec_helper.rb +77 -0
- metadata +205 -0
data/spec/pages_spec.rb
ADDED
@@ -0,0 +1,34 @@
|
|
1
|
+
require 'spec_helper'
|
2
|
+
require 'yaml'
|
3
|
+
|
4
|
+
{ :product_pages => LCBO::ProductPage,
|
5
|
+
:store_pages => LCBO::StorePage,
|
6
|
+
:inventory_pages => LCBO::InventoryPage,
|
7
|
+
:product_list_pages => LCBO::ProductListPage
|
8
|
+
}.each_pair do |type, page|
|
9
|
+
|
10
|
+
describe(page) do
|
11
|
+
requests = YAML.load_file("spec/pages/#{type}.yml")
|
12
|
+
|
13
|
+
requests.each do |req|
|
14
|
+
body = File.read("spec/pages/#{type}/#{req[:file]}")
|
15
|
+
req[:body] = body
|
16
|
+
SpecHelper.hydrastub(req[:method], req[:uri], :body => req[:body])
|
17
|
+
end
|
18
|
+
|
19
|
+
requests.each do |req|
|
20
|
+
context "given a #{req[:desc]}" do
|
21
|
+
before :all do
|
22
|
+
@page = page.process(req[:query_params], req[:body_params])
|
23
|
+
end
|
24
|
+
|
25
|
+
req[:expectation].each_pair do |key, value|
|
26
|
+
it "should have the expected value for :#{key}" do
|
27
|
+
@page[key].should == value
|
28
|
+
end
|
29
|
+
end
|
30
|
+
end
|
31
|
+
end
|
32
|
+
end
|
33
|
+
|
34
|
+
end
|
data/spec/spec_helper.rb
ADDED
@@ -0,0 +1,77 @@
|
|
1
|
+
gem 'rspec', '1.3.0'
|
2
|
+
|
3
|
+
require 'spec'
|
4
|
+
require 'lcbo'
|
5
|
+
|
6
|
+
BRO_HTML = '<h1>Carsten</h1><p>Carsten is a bro.</p>'
|
7
|
+
BRO_SEARCH_HTML = '<ul><li>Carsten</li><li>Kevin</li><li>Kieran</li></ul>'
|
8
|
+
BRO_ICE_HTML = '<h1>Bro!</h1><p>Yall just icy yo fellow bros!</p>'
|
9
|
+
|
10
|
+
module SpecHelper
|
11
|
+
|
12
|
+
def self.hydrastub(method, uri, response_opts = {})
|
13
|
+
response_params = {
|
14
|
+
:code => 200,
|
15
|
+
:headers => '',
|
16
|
+
:body => '',
|
17
|
+
:time => 0.3
|
18
|
+
}.merge(response_opts)
|
19
|
+
response = Typhoeus::Response.new(response_params)
|
20
|
+
Typhoeus::Hydra.hydra.stub(method, uri).and_return(response)
|
21
|
+
end
|
22
|
+
|
23
|
+
class Evented
|
24
|
+
include LCBO::CrawlKit::Eventable
|
25
|
+
on :before_request, :set_test_1
|
26
|
+
on :before_request, :set_test_2
|
27
|
+
on :after_request, :set_test_3
|
28
|
+
attr_reader :test_1, :test_2, :test_3, :requested
|
29
|
+
def set_test_1; @test_1 = true; end
|
30
|
+
def set_test_2; @test_2 = true; end
|
31
|
+
def set_test_3; @test_3 = true; end
|
32
|
+
def request!
|
33
|
+
fire(:before_request)
|
34
|
+
@requested = true
|
35
|
+
fire(:after_request)
|
36
|
+
end
|
37
|
+
end
|
38
|
+
|
39
|
+
class GetPage
|
40
|
+
include LCBO::CrawlKit::Page
|
41
|
+
uri 'http://bros.local/bros/{bro_no}'
|
42
|
+
emits(:bro_no) { query_params[:bro_no].to_i }
|
43
|
+
emits(:name) { doc.css('h1')[0].content }
|
44
|
+
emits(:desc) { doc.css('p')[0].content }
|
45
|
+
end
|
46
|
+
|
47
|
+
class PostPage
|
48
|
+
include LCBO::CrawlKit::Page
|
49
|
+
http_method :post
|
50
|
+
uri 'http://bros.local/search'
|
51
|
+
default_body_params :q => '', :type => 'all'
|
52
|
+
emits(:q) { body_params[:q].to_s }
|
53
|
+
emits(:type) { body_params[:type].to_s }
|
54
|
+
emits(:names) { doc.css('li').map(&:content) }
|
55
|
+
end
|
56
|
+
|
57
|
+
class EventedPage
|
58
|
+
include LCBO::CrawlKit::Page
|
59
|
+
attr_reader :before_parse, :after_parse, :before_request, :after_request
|
60
|
+
on :before_parse, :set_before_parse
|
61
|
+
on :after_parse, :set_after_parse
|
62
|
+
on :before_request, :set_before_request
|
63
|
+
on :after_request, :set_after_request
|
64
|
+
http_method :put
|
65
|
+
uri 'http://bros.local/ice/{bro_no}'
|
66
|
+
emits(:message) { doc.css('p')[0].content }
|
67
|
+
def set_before_parse; @before_parse = true; end
|
68
|
+
def set_after_parse; @after_parse = true; end
|
69
|
+
def set_before_request; @before_request = true; end
|
70
|
+
def set_after_request; @after_request = true; end
|
71
|
+
end
|
72
|
+
|
73
|
+
end
|
74
|
+
|
75
|
+
SpecHelper.hydrastub :get, /http\:\/\/bros\.local\/bros\/.+/, :body => BRO_HTML
|
76
|
+
SpecHelper.hydrastub :post, /http\:\/\/bros\.local\/search/, :body => BRO_SEARCH_HTML
|
77
|
+
SpecHelper.hydrastub :put, /http\:\/\/bros\.local\/ice\/.+/, :body => BRO_ICE_HTML
|
metadata
ADDED
@@ -0,0 +1,205 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: lcbo
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
prerelease: false
|
5
|
+
segments:
|
6
|
+
- 0
|
7
|
+
- 9
|
8
|
+
- 0
|
9
|
+
version: 0.9.0
|
10
|
+
platform: ruby
|
11
|
+
authors:
|
12
|
+
- Carsten Nielsen
|
13
|
+
autorequire:
|
14
|
+
bindir: bin
|
15
|
+
cert_chain: []
|
16
|
+
|
17
|
+
date: 2010-09-23 00:00:00 -04:00
|
18
|
+
default_executable:
|
19
|
+
dependencies:
|
20
|
+
- !ruby/object:Gem::Dependency
|
21
|
+
name: typhoeus
|
22
|
+
prerelease: false
|
23
|
+
requirement: &id001 !ruby/object:Gem::Requirement
|
24
|
+
none: false
|
25
|
+
requirements:
|
26
|
+
- - ">="
|
27
|
+
- !ruby/object:Gem::Version
|
28
|
+
segments:
|
29
|
+
- 0
|
30
|
+
version: "0"
|
31
|
+
type: :runtime
|
32
|
+
version_requirements: *id001
|
33
|
+
- !ruby/object:Gem::Dependency
|
34
|
+
name: addressable
|
35
|
+
prerelease: false
|
36
|
+
requirement: &id002 !ruby/object:Gem::Requirement
|
37
|
+
none: false
|
38
|
+
requirements:
|
39
|
+
- - ">="
|
40
|
+
- !ruby/object:Gem::Version
|
41
|
+
segments:
|
42
|
+
- 0
|
43
|
+
version: "0"
|
44
|
+
type: :runtime
|
45
|
+
version_requirements: *id002
|
46
|
+
- !ruby/object:Gem::Dependency
|
47
|
+
name: nokogiri
|
48
|
+
prerelease: false
|
49
|
+
requirement: &id003 !ruby/object:Gem::Requirement
|
50
|
+
none: false
|
51
|
+
requirements:
|
52
|
+
- - ">="
|
53
|
+
- !ruby/object:Gem::Version
|
54
|
+
segments:
|
55
|
+
- 0
|
56
|
+
version: "0"
|
57
|
+
type: :runtime
|
58
|
+
version_requirements: *id003
|
59
|
+
- !ruby/object:Gem::Dependency
|
60
|
+
name: rspec
|
61
|
+
prerelease: false
|
62
|
+
requirement: &id004 !ruby/object:Gem::Requirement
|
63
|
+
none: false
|
64
|
+
requirements:
|
65
|
+
- - "="
|
66
|
+
- !ruby/object:Gem::Version
|
67
|
+
segments:
|
68
|
+
- 1
|
69
|
+
- 3
|
70
|
+
- 0
|
71
|
+
version: 1.3.0
|
72
|
+
type: :development
|
73
|
+
version_requirements: *id004
|
74
|
+
description: Request and parse product, store, inventory, and product search pages directly from the official LCBO website.
|
75
|
+
email:
|
76
|
+
- heycarsten@gmail.com
|
77
|
+
executables: []
|
78
|
+
|
79
|
+
extensions: []
|
80
|
+
|
81
|
+
extra_rdoc_files: []
|
82
|
+
|
83
|
+
files:
|
84
|
+
- .gitignore
|
85
|
+
- CHANGELOG.md
|
86
|
+
- Gemfile
|
87
|
+
- Gemfile.lock
|
88
|
+
- LICENSE
|
89
|
+
- README.md
|
90
|
+
- Rakefile
|
91
|
+
- lcbo.gemspec
|
92
|
+
- lib/lcbo.rb
|
93
|
+
- lib/lcbo/crawlers.rb
|
94
|
+
- lib/lcbo/crawlers/inventories_crawler.rb
|
95
|
+
- lib/lcbo/crawlers/product_lists_crawler.rb
|
96
|
+
- lib/lcbo/crawlers/products_crawler.rb
|
97
|
+
- lib/lcbo/crawlers/stores_crawler.rb
|
98
|
+
- lib/lcbo/crawlkit.rb
|
99
|
+
- lib/lcbo/crawlkit/eventable.rb
|
100
|
+
- lib/lcbo/crawlkit/fastdate_helper.rb
|
101
|
+
- lib/lcbo/crawlkit/page.rb
|
102
|
+
- lib/lcbo/crawlkit/request.rb
|
103
|
+
- lib/lcbo/crawlkit/request_prototype.rb
|
104
|
+
- lib/lcbo/crawlkit/response.rb
|
105
|
+
- lib/lcbo/crawlkit/titlecase_helper.rb
|
106
|
+
- lib/lcbo/crawlkit/volume_helper.rb
|
107
|
+
- lib/lcbo/ext.rb
|
108
|
+
- lib/lcbo/helpers.rb
|
109
|
+
- lib/lcbo/pages.rb
|
110
|
+
- lib/lcbo/pages/inventory_page.rb
|
111
|
+
- lib/lcbo/pages/product_list_page.rb
|
112
|
+
- lib/lcbo/pages/product_page.rb
|
113
|
+
- lib/lcbo/pages/store_page.rb
|
114
|
+
- lib/lcbo/version.rb
|
115
|
+
- spec/crawlkit/eventable_spec.rb
|
116
|
+
- spec/crawlkit/fastdate_helper_spec.rb
|
117
|
+
- spec/crawlkit/page_spec.rb
|
118
|
+
- spec/crawlkit/request_prototype_spec.rb
|
119
|
+
- spec/crawlkit/request_spec.rb
|
120
|
+
- spec/crawlkit/response_spec.rb
|
121
|
+
- spec/crawlkit/titlecase_helper_spec.rb
|
122
|
+
- spec/crawlkit/volume_helper_spec.rb
|
123
|
+
- spec/crawlkit_spec.rb
|
124
|
+
- spec/lcbo_spec.rb
|
125
|
+
- spec/pages/inventory_pages.yml
|
126
|
+
- spec/pages/inventory_pages/1.html
|
127
|
+
- spec/pages/inventory_pages/2.html
|
128
|
+
- spec/pages/product_list_pages.yml
|
129
|
+
- spec/pages/product_list_pages/1.html
|
130
|
+
- spec/pages/product_pages.yml
|
131
|
+
- spec/pages/product_pages/1.html
|
132
|
+
- spec/pages/product_pages/2.html
|
133
|
+
- spec/pages/product_pages/3.html
|
134
|
+
- spec/pages/product_pages/4.html
|
135
|
+
- spec/pages/product_pages/5.html
|
136
|
+
- spec/pages/product_pages/6.html
|
137
|
+
- spec/pages/product_pages/7.html
|
138
|
+
- spec/pages/store_pages.yml
|
139
|
+
- spec/pages/store_pages/1.html
|
140
|
+
- spec/pages/store_pages/2.html
|
141
|
+
- spec/pages_spec.rb
|
142
|
+
- spec/spec_helper.rb
|
143
|
+
has_rdoc: true
|
144
|
+
homepage: http://github.com/heycarsten/lcbo
|
145
|
+
licenses: []
|
146
|
+
|
147
|
+
post_install_message:
|
148
|
+
rdoc_options: []
|
149
|
+
|
150
|
+
require_paths:
|
151
|
+
- lib
|
152
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
153
|
+
none: false
|
154
|
+
requirements:
|
155
|
+
- - ">="
|
156
|
+
- !ruby/object:Gem::Version
|
157
|
+
segments:
|
158
|
+
- 0
|
159
|
+
version: "0"
|
160
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
161
|
+
none: false
|
162
|
+
requirements:
|
163
|
+
- - ">="
|
164
|
+
- !ruby/object:Gem::Version
|
165
|
+
segments:
|
166
|
+
- 1
|
167
|
+
- 3
|
168
|
+
- 6
|
169
|
+
version: 1.3.6
|
170
|
+
requirements: []
|
171
|
+
|
172
|
+
rubyforge_project: lcbo
|
173
|
+
rubygems_version: 1.3.7
|
174
|
+
signing_key:
|
175
|
+
specification_version: 3
|
176
|
+
summary: A library for parsing HTML pages from http://lcbo.com
|
177
|
+
test_files:
|
178
|
+
- spec/crawlkit/eventable_spec.rb
|
179
|
+
- spec/crawlkit/fastdate_helper_spec.rb
|
180
|
+
- spec/crawlkit/page_spec.rb
|
181
|
+
- spec/crawlkit/request_prototype_spec.rb
|
182
|
+
- spec/crawlkit/request_spec.rb
|
183
|
+
- spec/crawlkit/response_spec.rb
|
184
|
+
- spec/crawlkit/titlecase_helper_spec.rb
|
185
|
+
- spec/crawlkit/volume_helper_spec.rb
|
186
|
+
- spec/crawlkit_spec.rb
|
187
|
+
- spec/lcbo_spec.rb
|
188
|
+
- spec/pages/inventory_pages.yml
|
189
|
+
- spec/pages/inventory_pages/1.html
|
190
|
+
- spec/pages/inventory_pages/2.html
|
191
|
+
- spec/pages/product_list_pages.yml
|
192
|
+
- spec/pages/product_list_pages/1.html
|
193
|
+
- spec/pages/product_pages.yml
|
194
|
+
- spec/pages/product_pages/1.html
|
195
|
+
- spec/pages/product_pages/2.html
|
196
|
+
- spec/pages/product_pages/3.html
|
197
|
+
- spec/pages/product_pages/4.html
|
198
|
+
- spec/pages/product_pages/5.html
|
199
|
+
- spec/pages/product_pages/6.html
|
200
|
+
- spec/pages/product_pages/7.html
|
201
|
+
- spec/pages/store_pages.yml
|
202
|
+
- spec/pages/store_pages/1.html
|
203
|
+
- spec/pages/store_pages/2.html
|
204
|
+
- spec/pages_spec.rb
|
205
|
+
- spec/spec_helper.rb
|