barnie 0.1.3
Sign up to get free protection for your applications and to get access to all the features.
- data/.gitignore +5 -0
- data/.rspec +1 -0
- data/Gemfile +2 -0
- data/LICENSE +22 -0
- data/README.md +4 -0
- data/Rakefile +12 -0
- data/barnie.gemspec +33 -0
- data/benchmarks/bm_helper.rb +5 -0
- data/benchmarks/stress_test.rb +28 -0
- data/lib/barnie.rb +16 -0
- data/lib/barnie/client.rb +57 -0
- data/lib/barnie/error.rb +7 -0
- data/lib/barnie/helpers.rb +56 -0
- data/lib/barnie/version.rb +3 -0
- data/rvmrc.example +2 -0
- data/spec/acceptance/availability_spec.rb +43 -0
- data/spec/acceptance/smokescreen_spec.rb +18 -0
- data/spec/fixtures/asins.txt +10000 -0
- data/spec/fixtures/barnie_availability.yml +507 -0
- data/spec/fixtures/barnie_client.yml +347 -0
- data/spec/fixtures/barnie_helpers.yml +231 -0
- data/spec/fixtures/barnie_smokescreen.yml +112 -0
- data/spec/fixtures/bug.yml +248 -0
- data/spec/spec_helper.rb +7 -0
- data/spec/support/isbns.rb +12 -0
- data/spec/support/show_me_the_page.rb +15 -0
- data/spec/support/vcr.rb +8 -0
- data/spec/unit/barnie/client_spec.rb +122 -0
- data/spec/unit/barnie/helpers_spec.rb +100 -0
- data/spec/unit/barnie_spec.rb +9 -0
- metadata +187 -0
@@ -0,0 +1,100 @@
|
|
1
|
+
# encoding: utf-8
|
2
|
+
require "spec_helper"
|
3
|
+
|
4
|
+
module Barnie
|
5
|
+
describe Helpers do
|
6
|
+
before do
|
7
|
+
@client = Barnie.new("company details")
|
8
|
+
end
|
9
|
+
|
10
|
+
it "sanitizes string" do
|
11
|
+
@client.sanitize_string('"I am" a book \r\n "').should eql 'I am" a book'
|
12
|
+
end
|
13
|
+
|
14
|
+
it "extract price" do
|
15
|
+
@client.extract_price('$14.95 abc').should eql 1495
|
16
|
+
@client.extract_price(nil).should eql 0
|
17
|
+
@client.extract_price('').should eql 0
|
18
|
+
end
|
19
|
+
|
20
|
+
it "extracts ISBN" do
|
21
|
+
@client.extract_isbn('http://search.barnesandnoble.com/Best-of-Waffles-Pancakes/Jane-Stacey/e/9780002554756/?itm=1').should eql "9780002554756"
|
22
|
+
@client.extract_isbn('http://music.barnesandnoble.com/Live/Brian-Regan/e/706442377723/?itm=1').should eql "0706442377723"
|
23
|
+
@client.extract_isbn('"http://music.barnesandnoble.com/Getting-a-Good-Nights-Sleep/John-Selby/e/52296602529/?itm=1"').should eql "0052296602529"
|
24
|
+
@client.extract_isbn(nil).should be_nil
|
25
|
+
@client.extract_isbn('').should be_nil
|
26
|
+
end
|
27
|
+
|
28
|
+
it "extracts binding" do
|
29
|
+
@client.extract_binding(' Paperback ').should eql "Paperback"
|
30
|
+
@client.extract_binding(nil).should be_nil
|
31
|
+
@client.extract_binding('').should be_nil
|
32
|
+
end
|
33
|
+
|
34
|
+
it "extracts maximum shipping hours" do
|
35
|
+
@client.extract_ships_in('Usually ships within 24 hours').should eql 24
|
36
|
+
@client.extract_ships_in('Usually ships within 2-3 days').should eql 3 * 24
|
37
|
+
@client.extract_ships_in('Usually ships within 7 days').should eql 7 * 24
|
38
|
+
@client.extract_ships_in('Usually ships within 7 days').should eql 7 * 24
|
39
|
+
@client.extract_ships_in('A new copy is not available from Barnes & Noble.com at this time.').should be_nil
|
40
|
+
@client.extract_ships_in(nil).should be_nil
|
41
|
+
@client.extract_ships_in('').should be_nil
|
42
|
+
end
|
43
|
+
|
44
|
+
context "requiring real HTML objects" do
|
45
|
+
before do
|
46
|
+
VCR.insert_cassette('barnie_helpers')
|
47
|
+
end
|
48
|
+
|
49
|
+
after do
|
50
|
+
VCR.eject_cassette
|
51
|
+
end
|
52
|
+
|
53
|
+
context "ebook" do
|
54
|
+
before do
|
55
|
+
@client.isbns = ["9781400826094"]
|
56
|
+
@html = @client.request.search("#prod-container").first
|
57
|
+
end
|
58
|
+
|
59
|
+
it "returns title as XML NodeSet" do
|
60
|
+
@client.title(@html).should be_an_instance_of Nokogiri::XML::NodeSet
|
61
|
+
end
|
62
|
+
|
63
|
+
it "extracts title" do
|
64
|
+
@client.extract_title(@client.title(@html)).should eql "Birth of the Symbol : Ancient Readers at the Limits of Their Texts"
|
65
|
+
end
|
66
|
+
|
67
|
+
it "extracts link" do
|
68
|
+
@client.extract_link(@client.title(@html)).should eql "http://search.barnesandnoble.com/Birth-of-the-Symbol/Peter-T-Struck/e/9781400826094/?itm=1"
|
69
|
+
end
|
70
|
+
|
71
|
+
it "extracts authors" do
|
72
|
+
@client.extract_authors(@html).should =~ ["Peter T. Struck"]
|
73
|
+
end
|
74
|
+
end
|
75
|
+
|
76
|
+
context "paperback" do
|
77
|
+
before do
|
78
|
+
@client.isbns = ["9780816614028"]
|
79
|
+
@html = @client.request.search("#prod-container").first
|
80
|
+
end
|
81
|
+
|
82
|
+
it "returns title as XML NodeSet" do
|
83
|
+
@client.title(@html).should be_an_instance_of Nokogiri::XML::NodeSet
|
84
|
+
end
|
85
|
+
|
86
|
+
it "extracts title" do
|
87
|
+
@client.extract_title(@client.title(@html)).should eql "A Thousand Plateaus : Capitalism and Schizophrenia"
|
88
|
+
end
|
89
|
+
|
90
|
+
it "extracts link" do
|
91
|
+
@client.extract_link(@client.title(@html)).should eql "http://search.barnesandnoble.com/A-Thousand-Plateaus/Gilles-Deleuze/e/9780816614028/?itm=1"
|
92
|
+
end
|
93
|
+
|
94
|
+
it "extracts authors" do
|
95
|
+
@client.extract_authors(@html).should =~ ["Felix Guattari", "Gilles Deleuze"]
|
96
|
+
end
|
97
|
+
end
|
98
|
+
end
|
99
|
+
end
|
100
|
+
end
|
metadata
ADDED
@@ -0,0 +1,187 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: barnie
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
prerelease:
|
5
|
+
version: 0.1.3
|
6
|
+
platform: ruby
|
7
|
+
authors:
|
8
|
+
- Paper Cavalier
|
9
|
+
autorequire:
|
10
|
+
bindir: bin
|
11
|
+
cert_chain: []
|
12
|
+
|
13
|
+
date: 2011-02-08 00:00:00 +00:00
|
14
|
+
default_executable:
|
15
|
+
dependencies:
|
16
|
+
- !ruby/object:Gem::Dependency
|
17
|
+
name: mechanize
|
18
|
+
prerelease: false
|
19
|
+
requirement: &id001 !ruby/object:Gem::Requirement
|
20
|
+
none: false
|
21
|
+
requirements:
|
22
|
+
- - ~>
|
23
|
+
- !ruby/object:Gem::Version
|
24
|
+
version: 1.0.0
|
25
|
+
type: :runtime
|
26
|
+
version_requirements: *id001
|
27
|
+
- !ruby/object:Gem::Dependency
|
28
|
+
name: bookland
|
29
|
+
prerelease: false
|
30
|
+
requirement: &id002 !ruby/object:Gem::Requirement
|
31
|
+
none: false
|
32
|
+
requirements:
|
33
|
+
- - "="
|
34
|
+
- !ruby/object:Gem::Version
|
35
|
+
version: 0.3.1
|
36
|
+
type: :development
|
37
|
+
version_requirements: *id002
|
38
|
+
- !ruby/object:Gem::Dependency
|
39
|
+
name: launchy
|
40
|
+
prerelease: false
|
41
|
+
requirement: &id003 !ruby/object:Gem::Requirement
|
42
|
+
none: false
|
43
|
+
requirements:
|
44
|
+
- - ~>
|
45
|
+
- !ruby/object:Gem::Version
|
46
|
+
version: 0.3.7
|
47
|
+
type: :development
|
48
|
+
version_requirements: *id003
|
49
|
+
- !ruby/object:Gem::Dependency
|
50
|
+
name: rspec
|
51
|
+
prerelease: false
|
52
|
+
requirement: &id004 !ruby/object:Gem::Requirement
|
53
|
+
none: false
|
54
|
+
requirements:
|
55
|
+
- - ~>
|
56
|
+
- !ruby/object:Gem::Version
|
57
|
+
version: 2.1.0
|
58
|
+
type: :development
|
59
|
+
version_requirements: *id004
|
60
|
+
- !ruby/object:Gem::Dependency
|
61
|
+
name: throttler
|
62
|
+
prerelease: false
|
63
|
+
requirement: &id005 !ruby/object:Gem::Requirement
|
64
|
+
none: false
|
65
|
+
requirements:
|
66
|
+
- - ~>
|
67
|
+
- !ruby/object:Gem::Version
|
68
|
+
version: 0.2.1
|
69
|
+
type: :development
|
70
|
+
version_requirements: *id005
|
71
|
+
- !ruby/object:Gem::Dependency
|
72
|
+
name: vcr
|
73
|
+
prerelease: false
|
74
|
+
requirement: &id006 !ruby/object:Gem::Requirement
|
75
|
+
none: false
|
76
|
+
requirements:
|
77
|
+
- - ~>
|
78
|
+
- !ruby/object:Gem::Version
|
79
|
+
version: 1.3.1
|
80
|
+
type: :development
|
81
|
+
version_requirements: *id006
|
82
|
+
- !ruby/object:Gem::Dependency
|
83
|
+
name: webmock
|
84
|
+
prerelease: false
|
85
|
+
requirement: &id007 !ruby/object:Gem::Requirement
|
86
|
+
none: false
|
87
|
+
requirements:
|
88
|
+
- - ~>
|
89
|
+
- !ruby/object:Gem::Version
|
90
|
+
version: 1.6.1
|
91
|
+
type: :development
|
92
|
+
version_requirements: *id007
|
93
|
+
- !ruby/object:Gem::Dependency
|
94
|
+
name: ruby-debug19
|
95
|
+
prerelease: false
|
96
|
+
requirement: &id008 !ruby/object:Gem::Requirement
|
97
|
+
none: false
|
98
|
+
requirements:
|
99
|
+
- - ~>
|
100
|
+
- !ruby/object:Gem::Version
|
101
|
+
version: 0.11.0
|
102
|
+
type: :development
|
103
|
+
version_requirements: *id008
|
104
|
+
description: A fake API to a well-known bookstore
|
105
|
+
email:
|
106
|
+
- code@papercavalier.com
|
107
|
+
executables: []
|
108
|
+
|
109
|
+
extensions: []
|
110
|
+
|
111
|
+
extra_rdoc_files: []
|
112
|
+
|
113
|
+
files:
|
114
|
+
- .gitignore
|
115
|
+
- .rspec
|
116
|
+
- Gemfile
|
117
|
+
- LICENSE
|
118
|
+
- README.md
|
119
|
+
- Rakefile
|
120
|
+
- barnie.gemspec
|
121
|
+
- benchmarks/bm_helper.rb
|
122
|
+
- benchmarks/stress_test.rb
|
123
|
+
- lib/barnie.rb
|
124
|
+
- lib/barnie/client.rb
|
125
|
+
- lib/barnie/error.rb
|
126
|
+
- lib/barnie/helpers.rb
|
127
|
+
- lib/barnie/version.rb
|
128
|
+
- rvmrc.example
|
129
|
+
- spec/acceptance/availability_spec.rb
|
130
|
+
- spec/acceptance/smokescreen_spec.rb
|
131
|
+
- spec/fixtures/asins.txt
|
132
|
+
- spec/fixtures/barnie_availability.yml
|
133
|
+
- spec/fixtures/barnie_client.yml
|
134
|
+
- spec/fixtures/barnie_helpers.yml
|
135
|
+
- spec/fixtures/barnie_smokescreen.yml
|
136
|
+
- spec/fixtures/bug.yml
|
137
|
+
- spec/spec_helper.rb
|
138
|
+
- spec/support/isbns.rb
|
139
|
+
- spec/support/show_me_the_page.rb
|
140
|
+
- spec/support/vcr.rb
|
141
|
+
- spec/unit/barnie/client_spec.rb
|
142
|
+
- spec/unit/barnie/helpers_spec.rb
|
143
|
+
- spec/unit/barnie_spec.rb
|
144
|
+
has_rdoc: true
|
145
|
+
homepage: http://gloss.papercavalier.com/barnie
|
146
|
+
licenses: []
|
147
|
+
|
148
|
+
post_install_message:
|
149
|
+
rdoc_options: []
|
150
|
+
|
151
|
+
require_paths:
|
152
|
+
- lib
|
153
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
154
|
+
none: false
|
155
|
+
requirements:
|
156
|
+
- - ">="
|
157
|
+
- !ruby/object:Gem::Version
|
158
|
+
version: "0"
|
159
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
160
|
+
none: false
|
161
|
+
requirements:
|
162
|
+
- - ">="
|
163
|
+
- !ruby/object:Gem::Version
|
164
|
+
version: "0"
|
165
|
+
requirements: []
|
166
|
+
|
167
|
+
rubyforge_project: barnie
|
168
|
+
rubygems_version: 1.5.0
|
169
|
+
signing_key:
|
170
|
+
specification_version: 3
|
171
|
+
summary: A fake API to a well-known bookstore
|
172
|
+
test_files:
|
173
|
+
- spec/acceptance/availability_spec.rb
|
174
|
+
- spec/acceptance/smokescreen_spec.rb
|
175
|
+
- spec/fixtures/asins.txt
|
176
|
+
- spec/fixtures/barnie_availability.yml
|
177
|
+
- spec/fixtures/barnie_client.yml
|
178
|
+
- spec/fixtures/barnie_helpers.yml
|
179
|
+
- spec/fixtures/barnie_smokescreen.yml
|
180
|
+
- spec/fixtures/bug.yml
|
181
|
+
- spec/spec_helper.rb
|
182
|
+
- spec/support/isbns.rb
|
183
|
+
- spec/support/show_me_the_page.rb
|
184
|
+
- spec/support/vcr.rb
|
185
|
+
- spec/unit/barnie/client_spec.rb
|
186
|
+
- spec/unit/barnie/helpers_spec.rb
|
187
|
+
- spec/unit/barnie_spec.rb
|