lcbo 0.9.0 → 0.9.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- data/CHANGELOG.md +5 -0
- data/Gemfile +2 -4
- data/Gemfile.lock +3 -7
- data/README.md +6 -0
- data/Rakefile +7 -8
- data/lcbo.gemspec +0 -3
- data/lib/lcbo/crawlkit.rb +0 -2
- data/lib/lcbo/crawlkit/page.rb +5 -1
- data/lib/lcbo/crawlkit/request.rb +4 -1
- data/lib/lcbo/crawlkit/request_prototype.rb +1 -1
- data/lib/lcbo/version.rb +1 -1
- data/spec/crawlkit/eventable_spec.rb +8 -8
- data/spec/crawlkit/fastdate_helper_spec.rb +1 -1
- data/spec/crawlkit/page_spec.rb +47 -35
- data/spec/crawlkit/request_spec.rb +9 -9
- data/spec/crawlkit/titlecase_helper_spec.rb +2 -2
- data/spec/crawlkit/volume_helper_spec.rb +1 -1
- data/spec/lcbo_spec.rb +10 -10
- data/spec/pages_spec.rb +7 -3
- data/spec/spec_helper.rb +69 -66
- metadata +4 -32
data/CHANGELOG.md
CHANGED
data/Gemfile
CHANGED
data/Gemfile.lock
CHANGED
@@ -1,18 +1,14 @@
|
|
1
1
|
GEM
|
2
2
|
remote: http://rubygems.org/
|
3
3
|
specs:
|
4
|
-
addressable (2.1.2)
|
5
4
|
nokogiri (1.4.3.1)
|
6
5
|
rack (1.2.1)
|
7
|
-
|
8
|
-
typhoeus (0.1.29)
|
6
|
+
typhoeus (0.1.31)
|
9
7
|
rack
|
10
8
|
|
11
9
|
PLATFORMS
|
12
10
|
ruby
|
13
11
|
|
14
12
|
DEPENDENCIES
|
15
|
-
|
16
|
-
|
17
|
-
rspec (= 1.3.0)
|
18
|
-
typhoeus (= 0.1.29)
|
13
|
+
nokogiri
|
14
|
+
typhoeus
|
data/README.md
CHANGED
@@ -22,6 +22,12 @@ This library is used to gather data for [LCBO API](http://lcboapi.com). It allow
|
|
22
22
|
|
23
23
|
Use Ruby Gems: `gem install lcbo`
|
24
24
|
|
25
|
+
## Notes
|
26
|
+
|
27
|
+
* Works with Ruby 1.9.2, not tested with 1.8.X or 1.9.1.
|
28
|
+
* Don't be evil, be nice.
|
29
|
+
* Lots of room to improve — fork your face off!
|
30
|
+
|
25
31
|
## Links
|
26
32
|
|
27
33
|
* [Issue tracker](http://github.com/heycarsten/lcbo/issues)
|
data/Rakefile
CHANGED
@@ -1,9 +1,6 @@
|
|
1
|
-
gem 'rspec', '1.3.0'
|
2
1
|
require 'rubygems/specification' unless defined?(Gem::Specification)
|
3
|
-
require 'spec/rake/spectask'
|
4
2
|
require 'rake/gempackagetask'
|
5
|
-
|
6
|
-
task :default => :spec
|
3
|
+
require 'rake/testtask'
|
7
4
|
|
8
5
|
def gemspec
|
9
6
|
@gemspec ||= begin
|
@@ -11,6 +8,8 @@ def gemspec
|
|
11
8
|
end
|
12
9
|
end
|
13
10
|
|
11
|
+
task :default => :spec
|
12
|
+
|
14
13
|
desc 'Start an irb console'
|
15
14
|
task :console do
|
16
15
|
system 'irb -I lib -r lcbo'
|
@@ -42,10 +41,10 @@ end
|
|
42
41
|
task :gem => :gemspec
|
43
42
|
task :package => :gemspec
|
44
43
|
|
45
|
-
|
46
|
-
|
47
|
-
t.
|
48
|
-
t.
|
44
|
+
Rake::TestTask.new(:spec) do |t|
|
45
|
+
t.libs += %w[lcbo spec]
|
46
|
+
t.test_files = FileList['spec/**/*.rb']
|
47
|
+
t.verbose = true
|
49
48
|
end
|
50
49
|
|
51
50
|
desc 'Download all HTML indicated in YAML assertion files'
|
data/lcbo.gemspec
CHANGED
@@ -15,11 +15,8 @@ Gem::Specification.new do |s|
|
|
15
15
|
s.rubyforge_project = 'lcbo'
|
16
16
|
|
17
17
|
s.add_dependency 'typhoeus'
|
18
|
-
s.add_dependency 'addressable'
|
19
18
|
s.add_dependency 'nokogiri'
|
20
19
|
|
21
|
-
s.add_development_dependency 'rspec', '1.3.0'
|
22
|
-
|
23
20
|
s.files = `git ls-files`.split(?\n)
|
24
21
|
s.test_files = `git ls-files -- {test,spec}/*`.split(?\n)
|
25
22
|
s.require_paths = ['lib']
|
data/lib/lcbo/crawlkit.rb
CHANGED
data/lib/lcbo/crawlkit/page.rb
CHANGED
@@ -126,7 +126,11 @@ module LCBO
|
|
126
126
|
|
127
127
|
def as_hash
|
128
128
|
@as_hash ||= begin
|
129
|
-
fields.reduce({})
|
129
|
+
fields.reduce({}) do |hsh, field|
|
130
|
+
value = send(field)
|
131
|
+
hsh[field] = value.is_a?(String) ? value.encode('utf-8') : value
|
132
|
+
hsh
|
133
|
+
end
|
130
134
|
end
|
131
135
|
end
|
132
136
|
|
@@ -31,7 +31,10 @@ module LCBO
|
|
31
31
|
end
|
32
32
|
|
33
33
|
def uri
|
34
|
-
request_prototype.uri_template.
|
34
|
+
template = request_prototype.uri_template.dup
|
35
|
+
query_params.reduce(template) do |mem, (key, value)|
|
36
|
+
mem.gsub("{#{key}}", value.to_s)
|
37
|
+
end
|
35
38
|
end
|
36
39
|
|
37
40
|
def run
|
data/lib/lcbo/version.rb
CHANGED
@@ -1,22 +1,22 @@
|
|
1
1
|
require 'spec_helper'
|
2
2
|
|
3
|
-
describe LCBO::CrawlKit::Eventable
|
3
|
+
describe LCBO::CrawlKit::Eventable do
|
4
4
|
|
5
5
|
it 'should have three callbacks' do
|
6
|
-
SpecHelper::Evented.callbacks.size.
|
6
|
+
SpecHelper::Evented.callbacks.size.must_equal 3
|
7
7
|
end
|
8
8
|
|
9
|
-
|
10
|
-
before
|
9
|
+
describe 'upon firing the events' do
|
10
|
+
before do
|
11
11
|
@evented = SpecHelper::Evented.new
|
12
12
|
@evented.request!
|
13
13
|
end
|
14
14
|
|
15
15
|
it 'should run all events and fire all callbacks' do
|
16
|
-
@evented.requested.
|
17
|
-
@evented.test_1.
|
18
|
-
@evented.test_2.
|
19
|
-
@evented.test_3.
|
16
|
+
@evented.requested.must_equal true
|
17
|
+
@evented.test_1.must_equal true
|
18
|
+
@evented.test_2.must_equal true
|
19
|
+
@evented.test_3.must_equal true
|
20
20
|
end
|
21
21
|
end
|
22
22
|
|
@@ -12,7 +12,7 @@ describe LCBO::CrawlKit::FastDateHelper do
|
|
12
12
|
|
13
13
|
@expectations.each_pair do |input, expectation|
|
14
14
|
it "should translate: #{input.inspect} to: #{expectation.inspect}" do
|
15
|
-
LCBO::CrawlKit::FastDateHelper[input].
|
15
|
+
LCBO::CrawlKit::FastDateHelper[input].must_equal expectation
|
16
16
|
end
|
17
17
|
end
|
18
18
|
end
|
data/spec/crawlkit/page_spec.rb
CHANGED
@@ -3,110 +3,122 @@ require 'spec_helper'
|
|
3
3
|
describe LCBO::CrawlKit::Page do
|
4
4
|
|
5
5
|
it 'should have a collection of emittable fields' do
|
6
|
-
SpecHelper::GetPage.fields
|
7
|
-
|
8
|
-
|
6
|
+
f = SpecHelper::GetPage.fields
|
7
|
+
f.must_include :bro_no
|
8
|
+
f.must_include :name
|
9
|
+
f.must_include :desc
|
10
|
+
f = SpecHelper::PostPage.fields
|
11
|
+
f.must_include :q
|
12
|
+
f.must_include :type
|
13
|
+
f.must_include :names
|
14
|
+
SpecHelper::EventedPage.fields.must_include :message
|
9
15
|
end
|
10
16
|
|
11
17
|
describe SpecHelper::GetPage do
|
12
18
|
it 'should default to a GET request' do
|
13
|
-
SpecHelper::GetPage.http_method.
|
19
|
+
SpecHelper::GetPage.http_method.must_equal :get
|
14
20
|
end
|
15
21
|
|
16
|
-
|
17
|
-
before
|
22
|
+
describe 'when requested' do
|
23
|
+
before do
|
18
24
|
@page = SpecHelper::GetPage.request(:bro_no => 1)
|
19
25
|
end
|
20
26
|
|
21
27
|
it 'should not be parsed' do
|
22
|
-
@page.is_parsed?.
|
28
|
+
@page.is_parsed?.must_equal false
|
23
29
|
end
|
24
30
|
|
25
31
|
it 'should have a valid response object' do
|
26
|
-
@page.response.
|
32
|
+
@page.response.must_be_instance_of LCBO::CrawlKit::Response
|
27
33
|
end
|
28
34
|
|
29
|
-
|
30
|
-
before
|
35
|
+
describe 'the response' do
|
36
|
+
before do
|
31
37
|
@page.process
|
32
38
|
end
|
33
39
|
|
34
40
|
it 'should be directly parsable' do
|
35
41
|
page = SpecHelper::GetPage.parse(@page.response)
|
36
|
-
page.as_hash.values.
|
42
|
+
@page.as_hash.values.each do |value|
|
43
|
+
page.as_hash.values.must_include value
|
44
|
+
end
|
37
45
|
end
|
38
46
|
|
39
47
|
it 'should be parsable from a hash representation' do
|
40
48
|
page = SpecHelper::GetPage.parse(@page.response.as_hash)
|
41
|
-
page.as_hash.values.
|
49
|
+
@page.as_hash.values.each do |value|
|
50
|
+
page.as_hash.values.must_include value
|
51
|
+
end
|
42
52
|
end
|
43
53
|
end
|
44
54
|
end
|
45
55
|
|
46
|
-
|
47
|
-
before
|
56
|
+
describe 'when processed' do
|
57
|
+
before do
|
48
58
|
@page = SpecHelper::GetPage.process(:bro_no => 1)
|
49
59
|
end
|
50
60
|
|
51
61
|
it 'should expand the URI template' do
|
52
|
-
@page.response.uri.
|
62
|
+
@page.response.uri.must_equal 'http://bros.local/bros/1'
|
53
63
|
end
|
54
64
|
|
55
65
|
it 'should emit expected values' do
|
56
|
-
@page.bro_no.
|
57
|
-
@page.name.
|
58
|
-
@page.desc.
|
66
|
+
@page.bro_no.must_equal 1
|
67
|
+
@page.name.must_equal 'Carsten'
|
68
|
+
@page.desc.must_equal 'Carsten is a bro.'
|
59
69
|
end
|
60
70
|
|
61
71
|
it 'should emit a hash of expected values' do
|
62
72
|
hsh = @page.as_hash
|
63
|
-
hsh[:bro_no].
|
64
|
-
hsh[:name].
|
65
|
-
hsh[:desc].
|
73
|
+
hsh[:bro_no].must_equal 1
|
74
|
+
hsh[:name].must_equal 'Carsten'
|
75
|
+
hsh[:desc].must_equal 'Carsten is a bro.'
|
66
76
|
end
|
67
77
|
end
|
68
78
|
end
|
69
79
|
|
70
80
|
describe SpecHelper::PostPage do
|
71
81
|
it 'should overide the default get http method with post' do
|
72
|
-
SpecHelper::PostPage.http_method.
|
82
|
+
SpecHelper::PostPage.http_method.must_equal :post
|
73
83
|
end
|
74
84
|
|
75
|
-
|
76
|
-
before
|
85
|
+
describe 'when processed' do
|
86
|
+
before do
|
77
87
|
@page = SpecHelper::PostPage.process(nil, :q => 'test', :type => 'test')
|
78
88
|
end
|
79
89
|
|
80
90
|
it 'should overide default body params with provided params' do
|
81
|
-
@page.body_params[:q].
|
82
|
-
@page.body_params[:type].
|
91
|
+
@page.body_params[:q].must_equal 'test'
|
92
|
+
@page.body_params[:type].must_equal 'test'
|
83
93
|
end
|
84
94
|
|
85
95
|
it 'should have a valid uri template' do
|
86
|
-
@page.response.uri.
|
96
|
+
@page.response.uri.must_equal 'http://bros.local/search'
|
87
97
|
end
|
88
98
|
|
89
99
|
it 'should parse the page' do
|
90
|
-
|
100
|
+
%w[Carsten Kieran Kevin].each do |name|
|
101
|
+
@page.as_hash[:names].must_include name
|
102
|
+
end
|
91
103
|
end
|
92
104
|
end
|
93
105
|
end
|
94
106
|
|
95
107
|
describe SpecHelper::EventedPage do
|
96
108
|
it 'should override the default http method with PUT' do
|
97
|
-
SpecHelper::EventedPage.http_method.
|
109
|
+
SpecHelper::EventedPage.http_method.must_equal :put
|
98
110
|
end
|
99
111
|
|
100
|
-
|
101
|
-
before
|
112
|
+
describe '(instantiated)' do
|
113
|
+
before do
|
102
114
|
@page = SpecHelper::EventedPage.process(:bro_no => 1)
|
103
115
|
end
|
104
116
|
|
105
117
|
it 'should fire the included events' do
|
106
|
-
@page.before_request.
|
107
|
-
@page.after_request.
|
108
|
-
@page.before_parse.
|
109
|
-
@page.after_parse.
|
118
|
+
@page.before_request.must_equal true
|
119
|
+
@page.after_request.must_equal true
|
120
|
+
@page.before_parse.must_equal true
|
121
|
+
@page.after_parse.must_equal true
|
110
122
|
end
|
111
123
|
end
|
112
124
|
end
|
@@ -2,27 +2,27 @@ require 'spec_helper'
|
|
2
2
|
|
3
3
|
describe LCBO::CrawlKit::Request do
|
4
4
|
|
5
|
-
|
6
|
-
before
|
5
|
+
describe 'GET request' do
|
6
|
+
before do
|
7
7
|
pro = LCBO::CrawlKit::RequestPrototype.new('http://bros.local/bros/{bro_no}')
|
8
8
|
@request = LCBO::CrawlKit::Request.new(pro, :bro_no => 1)
|
9
9
|
end
|
10
10
|
|
11
11
|
it 'should perform a get request' do
|
12
|
-
@request.config[:method].
|
12
|
+
@request.config[:method].must_equal :get
|
13
13
|
end
|
14
14
|
|
15
15
|
it 'should build a uri based on the query param input' do
|
16
|
-
@request.uri.
|
16
|
+
@request.uri.must_equal 'http://bros.local/bros/1'
|
17
17
|
end
|
18
18
|
|
19
19
|
it 'should perform the request' do
|
20
|
-
@request.run.body.
|
20
|
+
@request.run.body.must_equal SpecHelper::BRO_HTML
|
21
21
|
end
|
22
22
|
end
|
23
23
|
|
24
|
-
|
25
|
-
before
|
24
|
+
describe 'POST request' do
|
25
|
+
before do
|
26
26
|
pro = LCBO::CrawlKit::RequestPrototype.new(
|
27
27
|
'http://bros.local/search', :post,
|
28
28
|
{ :q => '', :type => 'all' })
|
@@ -31,11 +31,11 @@ describe LCBO::CrawlKit::Request do
|
|
31
31
|
end
|
32
32
|
|
33
33
|
it 'should build a uri appropriately' do
|
34
|
-
@request.uri.
|
34
|
+
@request.uri.must_equal 'http://bros.local/search'
|
35
35
|
end
|
36
36
|
|
37
37
|
it 'should perform the request' do
|
38
|
-
@request.run.body.
|
38
|
+
@request.run.body.must_equal SpecHelper::BRO_SEARCH_HTML
|
39
39
|
end
|
40
40
|
end
|
41
41
|
end
|
@@ -17,14 +17,14 @@ describe LCBO::CrawlKit::TitleCaseHelper do
|
|
17
17
|
|
18
18
|
@expectations.each_pair do |input, expectation|
|
19
19
|
it "should convert: #{input.inspect} to: #{expectation.inspect}" do
|
20
|
-
LCBO::CrawlKit::TitleCaseHelper[input].
|
20
|
+
LCBO::CrawlKit::TitleCaseHelper[input].must_equal expectation
|
21
21
|
end
|
22
22
|
end
|
23
23
|
|
24
24
|
it 'should translate lowercase characters to uppercase characters properly' do
|
25
25
|
upper = LCBO::CrawlKit::TitleCaseHelper::UPPER_CHARS
|
26
26
|
lower = LCBO::CrawlKit::TitleCaseHelper::LOWER_CHARS
|
27
|
-
LCBO::CrawlKit::TitleCaseHelper.upcase(lower).
|
27
|
+
LCBO::CrawlKit::TitleCaseHelper.upcase(lower).must_equal upper
|
28
28
|
end
|
29
29
|
|
30
30
|
end
|
@@ -15,7 +15,7 @@ describe LCBO::CrawlKit::VolumeHelper do
|
|
15
15
|
|
16
16
|
@expectations.each_pair do |input, expectation|
|
17
17
|
it "should convert: #{input.inspect} to: #{expectation.inspect}" do
|
18
|
-
LCBO::CrawlKit::VolumeHelper[input].
|
18
|
+
LCBO::CrawlKit::VolumeHelper[input].must_equal expectation
|
19
19
|
end
|
20
20
|
end
|
21
21
|
end
|
data/spec/lcbo_spec.rb
CHANGED
@@ -1,38 +1,38 @@
|
|
1
1
|
require 'spec_helper'
|
2
2
|
|
3
3
|
describe LCBO do
|
4
|
-
|
4
|
+
describe 'configuration' do
|
5
5
|
it 'should be a hash' do
|
6
|
-
LCBO.config.
|
6
|
+
LCBO.config.must_be_instance_of Hash
|
7
7
|
end
|
8
8
|
|
9
9
|
it 'should be configurable' do
|
10
10
|
LCBO.config[:user_agent] = 'Test'
|
11
|
-
LCBO.config[:user_agent].
|
11
|
+
LCBO.config[:user_agent].must_equal 'Test'
|
12
12
|
LCBO.reset_config!
|
13
|
-
LCBO.config[:user_agent].
|
13
|
+
LCBO.config[:user_agent].must_be_nil
|
14
14
|
end
|
15
15
|
end
|
16
16
|
|
17
|
-
|
17
|
+
describe 'helper methods' do
|
18
18
|
it 'provides LCBO.parse' do
|
19
|
-
LCBO.
|
19
|
+
LCBO.must_respond_to :parse
|
20
20
|
end
|
21
21
|
|
22
22
|
it 'provides LCBO.product' do
|
23
|
-
LCBO.
|
23
|
+
LCBO.must_respond_to :product
|
24
24
|
end
|
25
25
|
|
26
26
|
it 'provides LCBO.store' do
|
27
|
-
LCBO.
|
27
|
+
LCBO.must_respond_to :store
|
28
28
|
end
|
29
29
|
|
30
30
|
it 'provides LCBO.inventory' do
|
31
|
-
LCBO.
|
31
|
+
LCBO.must_respond_to :inventory
|
32
32
|
end
|
33
33
|
|
34
34
|
it 'provides LCBO.product_list' do
|
35
|
-
LCBO.
|
35
|
+
LCBO.must_respond_to :product_list
|
36
36
|
end
|
37
37
|
end
|
38
38
|
end
|
data/spec/pages_spec.rb
CHANGED
@@ -17,14 +17,18 @@ require 'yaml'
|
|
17
17
|
end
|
18
18
|
|
19
19
|
requests.each do |req|
|
20
|
-
|
21
|
-
before
|
20
|
+
describe "given a #{req[:desc]}" do
|
21
|
+
before do
|
22
22
|
@page = page.process(req[:query_params], req[:body_params])
|
23
23
|
end
|
24
24
|
|
25
25
|
req[:expectation].each_pair do |key, value|
|
26
26
|
it "should have the expected value for :#{key}" do
|
27
|
-
|
27
|
+
if (value.is_a?(String))
|
28
|
+
@page[key].must_equal value
|
29
|
+
else
|
30
|
+
@page[key].must_equal value
|
31
|
+
end
|
28
32
|
end
|
29
33
|
end
|
30
34
|
end
|
data/spec/spec_helper.rb
CHANGED
@@ -1,77 +1,80 @@
|
|
1
|
-
|
2
|
-
|
3
|
-
require 'spec'
|
1
|
+
require 'minitest/spec'
|
4
2
|
require 'lcbo'
|
5
3
|
|
6
|
-
|
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>'
|
4
|
+
MiniTest::Unit.autorun
|
9
5
|
|
10
|
-
|
6
|
+
unless defined? SpecHelper
|
7
|
+
module SpecHelper
|
8
|
+
BRO_HTML = '<h1>Carsten</h1><p>Carsten is a bro.</p>'
|
9
|
+
BRO_SEARCH_HTML = '<ul><li>Carsten</li><li>Kevin</li><li>Kieran</li></ul>'
|
10
|
+
BRO_ICE_HTML = '<h1>Bro!</h1><p>Yall just icy yo fellow bros!</p>'
|
11
11
|
|
12
|
-
|
13
|
-
|
14
|
-
|
15
|
-
|
16
|
-
|
17
|
-
|
18
|
-
|
19
|
-
|
20
|
-
|
21
|
-
|
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
22
|
|
23
|
-
|
24
|
-
|
25
|
-
|
26
|
-
|
27
|
-
|
28
|
-
|
29
|
-
|
30
|
-
|
31
|
-
|
32
|
-
|
33
|
-
|
34
|
-
|
35
|
-
|
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
|
36
37
|
end
|
37
|
-
end
|
38
38
|
|
39
|
-
|
40
|
-
|
41
|
-
|
42
|
-
|
43
|
-
|
44
|
-
|
45
|
-
|
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
46
|
|
47
|
-
|
48
|
-
|
49
|
-
|
50
|
-
|
51
|
-
|
52
|
-
|
53
|
-
|
54
|
-
|
55
|
-
|
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
56
|
|
57
|
-
|
58
|
-
|
59
|
-
|
60
|
-
|
61
|
-
|
62
|
-
|
63
|
-
|
64
|
-
|
65
|
-
|
66
|
-
|
67
|
-
|
68
|
-
|
69
|
-
|
70
|
-
|
71
|
-
|
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
72
|
|
73
|
+
SpecHelper.hydrastub :get, /http\:\/\/bros\.local\/bros\/.+/,
|
74
|
+
:body => BRO_HTML
|
75
|
+
SpecHelper.hydrastub :post, /http\:\/\/bros\.local\/search/,
|
76
|
+
:body => BRO_SEARCH_HTML
|
77
|
+
SpecHelper.hydrastub :put, /http\:\/\/bros\.local\/ice\/.+/,
|
78
|
+
:body => BRO_ICE_HTML
|
79
|
+
end
|
73
80
|
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
CHANGED
@@ -5,8 +5,8 @@ version: !ruby/object:Gem::Version
|
|
5
5
|
segments:
|
6
6
|
- 0
|
7
7
|
- 9
|
8
|
-
-
|
9
|
-
version: 0.9.
|
8
|
+
- 1
|
9
|
+
version: 0.9.1
|
10
10
|
platform: ruby
|
11
11
|
authors:
|
12
12
|
- Carsten Nielsen
|
@@ -14,7 +14,7 @@ autorequire:
|
|
14
14
|
bindir: bin
|
15
15
|
cert_chain: []
|
16
16
|
|
17
|
-
date: 2010-09-
|
17
|
+
date: 2010-09-24 00:00:00 -04:00
|
18
18
|
default_executable:
|
19
19
|
dependencies:
|
20
20
|
- !ruby/object:Gem::Dependency
|
@@ -31,7 +31,7 @@ dependencies:
|
|
31
31
|
type: :runtime
|
32
32
|
version_requirements: *id001
|
33
33
|
- !ruby/object:Gem::Dependency
|
34
|
-
name:
|
34
|
+
name: nokogiri
|
35
35
|
prerelease: false
|
36
36
|
requirement: &id002 !ruby/object:Gem::Requirement
|
37
37
|
none: false
|
@@ -43,34 +43,6 @@ dependencies:
|
|
43
43
|
version: "0"
|
44
44
|
type: :runtime
|
45
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
46
|
description: Request and parse product, store, inventory, and product search pages directly from the official LCBO website.
|
75
47
|
email:
|
76
48
|
- heycarsten@gmail.com
|