reckless 0.1.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +7 -0
- data/.gitignore +18 -0
- data/.rspec +2 -0
- data/Gemfile +2 -0
- data/Gemfile.lock +44 -0
- data/LICENSE +20 -0
- data/README.md +70 -0
- data/Rakefile +10 -0
- data/lib/reckless/client.rb +38 -0
- data/lib/reckless/normalizer.rb +25 -0
- data/lib/reckless/results_parser.rb +61 -0
- data/lib/reckless/search.rb +48 -0
- data/lib/reckless/version.rb +3 -0
- data/lib/reckless.rb +18 -0
- data/reckless.gemspec +24 -0
- data/spec/fixtures/no_results.html +322 -0
- data/spec/fixtures/page_with_results.html +958 -0
- data/spec/fixtures/pagination.html +1 -0
- data/spec/fixtures/recent_arrivals.html +976 -0
- data/spec/fixtures/single_result.html +17 -0
- data/spec/reckless/client_spec.rb +55 -0
- data/spec/reckless/normalizer_spec.rb +42 -0
- data/spec/reckless/results_parser_spec.rb +54 -0
- data/spec/reckless/search_spec.rb +81 -0
- data/spec/reckless_spec.rb +22 -0
- data/spec/spec_helper.rb +15 -0
- metadata +163 -0
@@ -0,0 +1,17 @@
|
|
1
|
+
<table class="item">
|
2
|
+
<tbody><tr><td><span class="artist">10,000 MANIACS</span><br><span class="title">IN MY TRIBE </span></td>
|
3
|
+
</tr>
|
4
|
+
<tr><td><span class="label">ELEKTRA </span></td></tr>
|
5
|
+
<tr><td> with PEACE TRAIN!! only available on early pressings. like anybody cares about SALMON RUSHDIE anyway these days.... </td></tr><tr><td>Available at: <span style="color:#a33; font-weight: bold;">Broadway and Milwaukee Ave.</span></td></tr><tr><td><b>Used LP( Very Good Condition ) </b> $4.99 <form method="get" action="/index.php">
|
6
|
+
|
7
|
+
<input type="hidden" name="qry_str" value="page=1&keywords=&format=LP&cond=&store=&is_search=true&srch=Search">
|
8
|
+
<input type="hidden" name="qty" value="2">
|
9
|
+
<input type="hidden" name="item2add" value="6100548674C">
|
10
|
+
<input type="submit" name="action" value="buy">
|
11
|
+
<!--
|
12
|
+
or <a href="/index.php?item2add=6100548674C&action=buy">Add to cart?</a>
|
13
|
+
-->
|
14
|
+
</form>
|
15
|
+
</td>
|
16
|
+
</tr>
|
17
|
+
</tbody></table>
|
@@ -0,0 +1,55 @@
|
|
1
|
+
require "spec_helper"
|
2
|
+
|
3
|
+
describe Reckless::Client do
|
4
|
+
let(:client) { described_class.new }
|
5
|
+
|
6
|
+
describe "#search" do
|
7
|
+
let(:result) { client.search }
|
8
|
+
|
9
|
+
before do
|
10
|
+
Faraday.stub_chain(:get, :body) { fixture("page_with_results.html") }
|
11
|
+
end
|
12
|
+
|
13
|
+
it "returns a search result" do
|
14
|
+
expect(result).to be_a Reckless::Search
|
15
|
+
end
|
16
|
+
|
17
|
+
it "includes default search params" do
|
18
|
+
defaults = {
|
19
|
+
keywords: "",
|
20
|
+
format: "LP",
|
21
|
+
cond: "",
|
22
|
+
store: "",
|
23
|
+
page: 1,
|
24
|
+
is_search: true
|
25
|
+
}
|
26
|
+
|
27
|
+
expect(result.params).to eq defaults
|
28
|
+
end
|
29
|
+
end
|
30
|
+
|
31
|
+
describe "#recent_arrivals" do
|
32
|
+
let(:result) { client.recent_arrivals }
|
33
|
+
|
34
|
+
before do
|
35
|
+
Faraday.stub_chain(:get, :body) { fixture("recent_arrivals.html") }
|
36
|
+
end
|
37
|
+
|
38
|
+
it "returns a search result" do
|
39
|
+
expect(result).to be_a Reckless::Search
|
40
|
+
end
|
41
|
+
|
42
|
+
it "includes default search params" do
|
43
|
+
defaults = {
|
44
|
+
page: 1,
|
45
|
+
period: 1,
|
46
|
+
format: "LP",
|
47
|
+
cond: "",
|
48
|
+
store: "",
|
49
|
+
style: 0
|
50
|
+
}
|
51
|
+
|
52
|
+
expect(result.params).to eq defaults
|
53
|
+
end
|
54
|
+
end
|
55
|
+
end
|
@@ -0,0 +1,42 @@
|
|
1
|
+
require "spec_helper"
|
2
|
+
|
3
|
+
class NormalizerTest
|
4
|
+
include Reckless::Normalizer
|
5
|
+
end
|
6
|
+
|
7
|
+
describe Reckless::Normalizer do
|
8
|
+
let(:normalizer) { NormalizerTest.new }
|
9
|
+
|
10
|
+
describe "#normalize_text" do
|
11
|
+
let(:examples) do
|
12
|
+
{
|
13
|
+
"ALL CAPS TEXT" => "All Caps Text",
|
14
|
+
"all low text" => "All Low Text",
|
15
|
+
"13TH FLOOR ELEVATORS" => "13th Floor Elevators"
|
16
|
+
}
|
17
|
+
end
|
18
|
+
|
19
|
+
it "convert text into capitalized words" do
|
20
|
+
examples.each_pair do |before, after|
|
21
|
+
expect(normalizer.normalize_text(before)).to eq after
|
22
|
+
end
|
23
|
+
end
|
24
|
+
end
|
25
|
+
|
26
|
+
describe "#normalize_artist" do
|
27
|
+
let(:examples) do
|
28
|
+
{
|
29
|
+
"Beck, Jeff" => "Jeff Beck",
|
30
|
+
"Beck,Jeff" => "Jeff Beck",
|
31
|
+
"Astatke, Mulatu & Band" => "Mulatu Astatke & Band",
|
32
|
+
"10,000 Maniacs" => "10,000 Maniacs"
|
33
|
+
}
|
34
|
+
end
|
35
|
+
|
36
|
+
it "converts weird artist name into correct form" do
|
37
|
+
examples.each_pair do |before, after|
|
38
|
+
expect(normalizer.normalize_artist(before)).to eq after
|
39
|
+
end
|
40
|
+
end
|
41
|
+
end
|
42
|
+
end
|
@@ -0,0 +1,54 @@
|
|
1
|
+
require "spec_helper"
|
2
|
+
|
3
|
+
describe Reckless::ResultsParser do
|
4
|
+
describe "#parse" do
|
5
|
+
let(:parser) { described_class.new(body) }
|
6
|
+
let(:body) { fixture("page_with_results.html") }
|
7
|
+
let(:results) { parser.parse }
|
8
|
+
|
9
|
+
it "returns an array of results" do
|
10
|
+
expect(results).to be_an Array
|
11
|
+
end
|
12
|
+
|
13
|
+
it "returns result hashes" do
|
14
|
+
expect(results.all? { |r| r.kind_of?(Hash) }).to be_true
|
15
|
+
end
|
16
|
+
|
17
|
+
it "returns 30 results per page" do
|
18
|
+
expect(results.size).to eq 30
|
19
|
+
end
|
20
|
+
|
21
|
+
describe "record" do
|
22
|
+
let(:body) { fixture("single_result.html") }
|
23
|
+
let(:record) { results.first }
|
24
|
+
|
25
|
+
it "includes artist name" do
|
26
|
+
expect(record[:artist]).to eq "10,000 Maniacs"
|
27
|
+
end
|
28
|
+
|
29
|
+
it "includes record title" do
|
30
|
+
expect(record[:title]).to eq "In My Tribe"
|
31
|
+
end
|
32
|
+
|
33
|
+
it "includes label name" do
|
34
|
+
expect(record[:label]).to eq "Elektra"
|
35
|
+
end
|
36
|
+
|
37
|
+
it "includes price" do
|
38
|
+
expect(record[:price]).to eq 4.99
|
39
|
+
end
|
40
|
+
|
41
|
+
it "includes type" do
|
42
|
+
expect(record[:type]).to eq "Used LP"
|
43
|
+
end
|
44
|
+
|
45
|
+
it "includes condition" do
|
46
|
+
expect(record[:condition]).to eq "Very Good"
|
47
|
+
end
|
48
|
+
|
49
|
+
it "includes store name" do
|
50
|
+
expect(record[:store]).to eq "Broadway and Milwaukee Ave"
|
51
|
+
end
|
52
|
+
end
|
53
|
+
end
|
54
|
+
end
|
@@ -0,0 +1,81 @@
|
|
1
|
+
require "spec_helper"
|
2
|
+
|
3
|
+
describe Reckless::Search do
|
4
|
+
let(:search) { described_class.new("http://example.com") }
|
5
|
+
|
6
|
+
describe "#initialize" do
|
7
|
+
before do
|
8
|
+
Faraday.stub_chain(:get, :body) { "" }
|
9
|
+
end
|
10
|
+
|
11
|
+
it "assigns url" do
|
12
|
+
expect(search.url).to eq "http://example.com"
|
13
|
+
end
|
14
|
+
|
15
|
+
it "assigns params" do
|
16
|
+
expect(search.params).to be_a Hash
|
17
|
+
expect(search.params).to be_empty
|
18
|
+
end
|
19
|
+
|
20
|
+
it "assigns page" do
|
21
|
+
expect(search.page).to eq 1
|
22
|
+
end
|
23
|
+
|
24
|
+
it "assigns total results count" do
|
25
|
+
expect(search.total_results).to eq 0
|
26
|
+
end
|
27
|
+
|
28
|
+
it "assigns total pages count" do
|
29
|
+
expect(search.total_pages).to eq 0
|
30
|
+
end
|
31
|
+
|
32
|
+
it "assigns results collection" do
|
33
|
+
expect(search.results).to eq []
|
34
|
+
end
|
35
|
+
end
|
36
|
+
|
37
|
+
describe "for results page" do
|
38
|
+
let(:page) { fixture("page_with_results.html") }
|
39
|
+
|
40
|
+
before do
|
41
|
+
Faraday.stub_chain(:get, :body) { page }
|
42
|
+
end
|
43
|
+
|
44
|
+
it "assigns total results count" do
|
45
|
+
expect(search.total_results).to eq 33515
|
46
|
+
end
|
47
|
+
|
48
|
+
it "assigns total pages count" do
|
49
|
+
expect(search.total_pages).to eq 1118
|
50
|
+
end
|
51
|
+
|
52
|
+
it "assigns current page" do
|
53
|
+
expect(search.page).to eq 1
|
54
|
+
end
|
55
|
+
|
56
|
+
it "assigns results" do
|
57
|
+
expect(search.results).to be_an Array
|
58
|
+
expect(search.results.size).to eq 30
|
59
|
+
end
|
60
|
+
end
|
61
|
+
|
62
|
+
describe "for no results" do
|
63
|
+
let(:page) { fixture("no_results.html") }
|
64
|
+
|
65
|
+
before do
|
66
|
+
Faraday.stub_chain(:get, :body) { page }
|
67
|
+
end
|
68
|
+
|
69
|
+
it "assigns total results count" do
|
70
|
+
expect(search.total_results).to eq 0
|
71
|
+
end
|
72
|
+
|
73
|
+
it "assigns total pages count" do
|
74
|
+
expect(search.total_pages).to eq 0
|
75
|
+
end
|
76
|
+
|
77
|
+
it "assigns results" do
|
78
|
+
expect(search.results).to eq []
|
79
|
+
end
|
80
|
+
end
|
81
|
+
end
|
@@ -0,0 +1,22 @@
|
|
1
|
+
require "spec_helper"
|
2
|
+
|
3
|
+
describe Reckless do
|
4
|
+
it { should respond_to :search }
|
5
|
+
it { should respond_to :recent_arrivals }
|
6
|
+
|
7
|
+
before do
|
8
|
+
Faraday.stub_chain(:get, :body) { "" }
|
9
|
+
end
|
10
|
+
|
11
|
+
describe ".search" do
|
12
|
+
it "returns a search result" do
|
13
|
+
expect(described_class.search).to be_a Reckless::Search
|
14
|
+
end
|
15
|
+
end
|
16
|
+
|
17
|
+
describe ".recent_arrivals" do
|
18
|
+
it "returns a search result" do
|
19
|
+
expect(described_class.recent_arrivals).to be_a Reckless::Search
|
20
|
+
end
|
21
|
+
end
|
22
|
+
end
|
data/spec/spec_helper.rb
ADDED
@@ -0,0 +1,15 @@
|
|
1
|
+
$:.unshift File.expand_path("../..", __FILE__)
|
2
|
+
|
3
|
+
require "simplecov"
|
4
|
+
SimpleCov.start
|
5
|
+
|
6
|
+
require "reckless"
|
7
|
+
|
8
|
+
def fixture_path(filename=nil)
|
9
|
+
path = File.expand_path("../fixtures", __FILE__)
|
10
|
+
filename.nil? ? path : File.join(path, filename)
|
11
|
+
end
|
12
|
+
|
13
|
+
def fixture(file)
|
14
|
+
File.read(File.join(fixture_path, file))
|
15
|
+
end
|
metadata
ADDED
@@ -0,0 +1,163 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: reckless
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
version: 0.1.0
|
5
|
+
platform: ruby
|
6
|
+
authors:
|
7
|
+
- Dan Sosedoff
|
8
|
+
autorequire:
|
9
|
+
bindir: bin
|
10
|
+
cert_chain: []
|
11
|
+
date: 2014-01-28 00:00:00.000000000 Z
|
12
|
+
dependencies:
|
13
|
+
- !ruby/object:Gem::Dependency
|
14
|
+
name: json
|
15
|
+
requirement: !ruby/object:Gem::Requirement
|
16
|
+
requirements:
|
17
|
+
- - ~>
|
18
|
+
- !ruby/object:Gem::Version
|
19
|
+
version: '1.8'
|
20
|
+
type: :runtime
|
21
|
+
prerelease: false
|
22
|
+
version_requirements: !ruby/object:Gem::Requirement
|
23
|
+
requirements:
|
24
|
+
- - ~>
|
25
|
+
- !ruby/object:Gem::Version
|
26
|
+
version: '1.8'
|
27
|
+
- !ruby/object:Gem::Dependency
|
28
|
+
name: faraday
|
29
|
+
requirement: !ruby/object:Gem::Requirement
|
30
|
+
requirements:
|
31
|
+
- - ~>
|
32
|
+
- !ruby/object:Gem::Version
|
33
|
+
version: '0.7'
|
34
|
+
type: :runtime
|
35
|
+
prerelease: false
|
36
|
+
version_requirements: !ruby/object:Gem::Requirement
|
37
|
+
requirements:
|
38
|
+
- - ~>
|
39
|
+
- !ruby/object:Gem::Version
|
40
|
+
version: '0.7'
|
41
|
+
- !ruby/object:Gem::Dependency
|
42
|
+
name: nokogiri
|
43
|
+
requirement: !ruby/object:Gem::Requirement
|
44
|
+
requirements:
|
45
|
+
- - ~>
|
46
|
+
- !ruby/object:Gem::Version
|
47
|
+
version: '1.5'
|
48
|
+
type: :runtime
|
49
|
+
prerelease: false
|
50
|
+
version_requirements: !ruby/object:Gem::Requirement
|
51
|
+
requirements:
|
52
|
+
- - ~>
|
53
|
+
- !ruby/object:Gem::Version
|
54
|
+
version: '1.5'
|
55
|
+
- !ruby/object:Gem::Dependency
|
56
|
+
name: rake
|
57
|
+
requirement: !ruby/object:Gem::Requirement
|
58
|
+
requirements:
|
59
|
+
- - '>='
|
60
|
+
- !ruby/object:Gem::Version
|
61
|
+
version: '0'
|
62
|
+
type: :development
|
63
|
+
prerelease: false
|
64
|
+
version_requirements: !ruby/object:Gem::Requirement
|
65
|
+
requirements:
|
66
|
+
- - '>='
|
67
|
+
- !ruby/object:Gem::Version
|
68
|
+
version: '0'
|
69
|
+
- !ruby/object:Gem::Dependency
|
70
|
+
name: rspec
|
71
|
+
requirement: !ruby/object:Gem::Requirement
|
72
|
+
requirements:
|
73
|
+
- - ~>
|
74
|
+
- !ruby/object:Gem::Version
|
75
|
+
version: '2.13'
|
76
|
+
type: :development
|
77
|
+
prerelease: false
|
78
|
+
version_requirements: !ruby/object:Gem::Requirement
|
79
|
+
requirements:
|
80
|
+
- - ~>
|
81
|
+
- !ruby/object:Gem::Version
|
82
|
+
version: '2.13'
|
83
|
+
- !ruby/object:Gem::Dependency
|
84
|
+
name: simplecov
|
85
|
+
requirement: !ruby/object:Gem::Requirement
|
86
|
+
requirements:
|
87
|
+
- - ~>
|
88
|
+
- !ruby/object:Gem::Version
|
89
|
+
version: '0.7'
|
90
|
+
type: :development
|
91
|
+
prerelease: false
|
92
|
+
version_requirements: !ruby/object:Gem::Requirement
|
93
|
+
requirements:
|
94
|
+
- - ~>
|
95
|
+
- !ruby/object:Gem::Version
|
96
|
+
version: '0.7'
|
97
|
+
description: Client for Reckless.com site
|
98
|
+
email:
|
99
|
+
- dan.sosedoff@gmail.com
|
100
|
+
executables: []
|
101
|
+
extensions: []
|
102
|
+
extra_rdoc_files: []
|
103
|
+
files:
|
104
|
+
- .gitignore
|
105
|
+
- .rspec
|
106
|
+
- Gemfile
|
107
|
+
- Gemfile.lock
|
108
|
+
- LICENSE
|
109
|
+
- README.md
|
110
|
+
- Rakefile
|
111
|
+
- lib/reckless.rb
|
112
|
+
- lib/reckless/client.rb
|
113
|
+
- lib/reckless/normalizer.rb
|
114
|
+
- lib/reckless/results_parser.rb
|
115
|
+
- lib/reckless/search.rb
|
116
|
+
- lib/reckless/version.rb
|
117
|
+
- reckless.gemspec
|
118
|
+
- spec/fixtures/no_results.html
|
119
|
+
- spec/fixtures/page_with_results.html
|
120
|
+
- spec/fixtures/pagination.html
|
121
|
+
- spec/fixtures/recent_arrivals.html
|
122
|
+
- spec/fixtures/single_result.html
|
123
|
+
- spec/reckless/client_spec.rb
|
124
|
+
- spec/reckless/normalizer_spec.rb
|
125
|
+
- spec/reckless/results_parser_spec.rb
|
126
|
+
- spec/reckless/search_spec.rb
|
127
|
+
- spec/reckless_spec.rb
|
128
|
+
- spec/spec_helper.rb
|
129
|
+
homepage: http://github.com/sosedoff/reckless
|
130
|
+
licenses: []
|
131
|
+
metadata: {}
|
132
|
+
post_install_message:
|
133
|
+
rdoc_options: []
|
134
|
+
require_paths:
|
135
|
+
- lib
|
136
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
137
|
+
requirements:
|
138
|
+
- - '>='
|
139
|
+
- !ruby/object:Gem::Version
|
140
|
+
version: '0'
|
141
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
142
|
+
requirements:
|
143
|
+
- - '>='
|
144
|
+
- !ruby/object:Gem::Version
|
145
|
+
version: '0'
|
146
|
+
requirements: []
|
147
|
+
rubyforge_project:
|
148
|
+
rubygems_version: 2.1.11
|
149
|
+
signing_key:
|
150
|
+
specification_version: 4
|
151
|
+
summary: Client for Reckless.com site
|
152
|
+
test_files:
|
153
|
+
- spec/fixtures/no_results.html
|
154
|
+
- spec/fixtures/page_with_results.html
|
155
|
+
- spec/fixtures/pagination.html
|
156
|
+
- spec/fixtures/recent_arrivals.html
|
157
|
+
- spec/fixtures/single_result.html
|
158
|
+
- spec/reckless/client_spec.rb
|
159
|
+
- spec/reckless/normalizer_spec.rb
|
160
|
+
- spec/reckless/results_parser_spec.rb
|
161
|
+
- spec/reckless/search_spec.rb
|
162
|
+
- spec/reckless_spec.rb
|
163
|
+
- spec/spec_helper.rb
|