skimlinks 1.0.0 → 1.0.1

Sign up to get free protection for your applications and to get access to all the features.
@@ -0,0 +1,87 @@
1
+ require 'spec_helper'
2
+
3
+ describe Skimlinks::Client do
4
+ context 'configuration' do
5
+ describe 'with module configuration' do
6
+ [:module_config, :class_config].each do |config|
7
+ let(config) {
8
+ Hash[
9
+ *Skimlinks.configuration.rules.keys.map { |key| [key, valid_value_for_config(key)] }.flatten
10
+ ]
11
+ }
12
+ end
13
+
14
+ before do
15
+ Skimlinks.configure do |config|
16
+ Skimlinks.configuration.rules.keys.each do |key|
17
+ config.send "#{key}=", module_config[key]
18
+ end
19
+ end
20
+ end
21
+
22
+ after do
23
+ Skimlinks.configuration.reset
24
+ end
25
+
26
+ it 'inherits module configuration' do
27
+ client = Skimlinks::Client.new
28
+
29
+ Skimlinks.configuration.rules.keys.each do |key|
30
+ client.send(key).should eq(module_config[key])
31
+ end
32
+ end
33
+
34
+ describe 'with class configuration' do
35
+ it 'overrides module configuration' do
36
+ client = Skimlinks::Client.new(class_config)
37
+
38
+ Skimlinks.configuration.rules.keys.each do |key|
39
+ client.send(key).should eq(class_config[key])
40
+ end
41
+ end
42
+
43
+ it 'overrides module configuration after' do
44
+ client = Skimlinks::Client.new
45
+
46
+ class_config.each do |key, value|
47
+ client.send "#{key}=", value
48
+ end
49
+
50
+ Skimlinks.configuration.rules.keys.each do |key|
51
+ client.send(key).should eq(class_config[key])
52
+ end
53
+ end
54
+ end
55
+ end
56
+ end
57
+
58
+ context 'actions' do
59
+ before do
60
+ Skimlinks.configuration.api_key = 'foo'
61
+ end
62
+
63
+ describe '#merchant_categories' do
64
+ subject { Skimlinks::Client.new.merchant_categories }
65
+
66
+ it 'returns a non-empty hash' do
67
+ VCR.use_cassette 'Skimlinks_MerchantSearch' do
68
+ subject.should be_an_instance_of(Hash)
69
+ subject.should be_present
70
+ end
71
+ end
72
+ end
73
+
74
+ describe '#merchant_category_ids' do
75
+ subject {
76
+ VCR.use_cassette 'Skimlinks_MerchantSearch' do
77
+ Skimlinks::Client.new.merchant_category_ids
78
+ end
79
+ }
80
+
81
+ it 'returns a non-empty array' do
82
+ subject.should be_an_instance_of(Array)
83
+ subject.should be_present
84
+ end
85
+ end
86
+ end
87
+ end
@@ -0,0 +1,88 @@
1
+ require 'spec_helper'
2
+
3
+ describe Skimlinks::MerchantSearch do
4
+ subject { Skimlinks::MerchantSearch.new }
5
+
6
+ before do
7
+ Skimlinks.configuration.api_key = 'foo'
8
+ end
9
+
10
+ describe '#categories' do
11
+ it 'returns a hash' do
12
+ VCR.use_cassette 'Skimlinks_MerchantSearch' do
13
+ subject.categories.should be_an_instance_of(Hash)
14
+ end
15
+ end
16
+ end
17
+
18
+ describe '#nested_categories' do
19
+ it 'returns a hash' do
20
+ VCR.use_cassette 'Skimlinks_MerchantSearch' do
21
+ subject.nested_categories.should be_an_instance_of(Hash)
22
+ end
23
+ end
24
+ end
25
+
26
+ describe '#merchants' do
27
+ let(:category_id) { 12 }
28
+ let(:query) { 'amazon' }
29
+
30
+ it 'returns an array of Skimlinks::Merchant objects' do
31
+ VCR.use_cassette 'Skimlinks_MerchantSearch' do
32
+ subject.merchants.should be_an_instance_of(Array)
33
+ subject.merchants.should be_present
34
+ subject.merchants.should be_all { |merchant| merchant.is_a?(Skimlinks::Merchant) }
35
+ end
36
+ end
37
+
38
+ context 'when searching by a category ID' do
39
+ let(:merchants) { subject.merchants(category_ids: category_id) }
40
+
41
+ it 'returns merchants from the specified category' do
42
+ VCR.use_cassette 'Skimlinks_MerchantSearch' do
43
+ merchants.should be_an_instance_of(Array)
44
+ merchants.should be_present
45
+ merchants.should be_all { |merchant| merchant.categories.keys.map(&:to_i).include?(category_id) }
46
+ end
47
+ end
48
+ end
49
+
50
+ context 'when searching by a query' do
51
+ let(:merchants) { subject.merchants(query: query) }
52
+
53
+ it 'returns merchants that match the query' do
54
+ VCR.use_cassette 'Skimlinks_MerchantSearch' do
55
+ merchants.should be_all { |merchant| merchant.name =~ /#{Regexp.escape(query)}/i }
56
+ end
57
+ end
58
+
59
+ context 'when the query contains whitespace' do
60
+ let(:query) { 'virgin atlantic' }
61
+
62
+ it 'should not raise an error' do
63
+ VCR.use_cassette 'Skimlinks_MerchantSearch' do
64
+ expect { merchants }.to_not raise_error
65
+ end
66
+ end
67
+ end
68
+ end
69
+
70
+ context 'when searching by a category ID and a query' do
71
+ let(:merchants) { subject.merchants(category_ids: category_id, query: query) }
72
+
73
+ it 'returns merchants that match the query' do
74
+ VCR.use_cassette 'Skimlinks_MerchantSearch' do
75
+ merchants.should be_all { |merchant| merchant.categories.keys.map(&:to_i).include?(category_id) && merchant.name =~ /#{Regexp.escape(query)}/i }
76
+ end
77
+ end
78
+ end
79
+ end
80
+
81
+ describe '#merchant' do
82
+ it 'returns a Skimlinks::Merchant' do
83
+ VCR.use_cassette 'Skimlinks_MerchantSearch' do
84
+ subject.merchant(12678).should be_an_instance_of(Skimlinks::Merchant)
85
+ end
86
+ end
87
+ end
88
+ end
@@ -0,0 +1,4 @@
1
+ require 'spec_helper'
2
+
3
+ describe Skimlinks::Merchant do
4
+ end
@@ -0,0 +1,44 @@
1
+ require 'spec_helper'
2
+
3
+ describe Skimlinks::ProductSearch do
4
+ subject { Skimlinks::ProductSearch.new }
5
+
6
+ before do
7
+ Skimlinks.configuration.api_key = 'foo'
8
+ end
9
+
10
+ describe '#categories' do
11
+ it 'returns a hash' do
12
+ VCR.use_cassette 'Skimlinks_ProductSearch' do
13
+ subject.categories.should be_an_instance_of(Hash)
14
+ end
15
+ end
16
+ end
17
+
18
+ describe '#nested_categories' do
19
+ it 'returns a hash' do
20
+ VCR.use_cassette 'Skimlinks_ProductSearch' do
21
+ subject.nested_categories.should be_an_instance_of(Hash)
22
+ end
23
+ end
24
+ end
25
+
26
+ describe '#products' do
27
+ let(:products) { subject.products(query: 'justin bieber') }
28
+
29
+ it 'returns an array of Skimlinks::Product objects' do
30
+ VCR.use_cassette 'Skimlinks_ProductSearch' do
31
+ products.should be_an_instance_of(Array)
32
+ products.should be_all { |product| product.is_a?(Skimlinks::Product) }
33
+ end
34
+ end
35
+ end
36
+
37
+ describe '#product_count' do
38
+ it 'returns an integer' do
39
+ VCR.use_cassette 'Skimlinks_ProductSearch' do
40
+ subject.product_count(query: 'justin bieber').should be_an_instance_of(Fixnum)
41
+ end
42
+ end
43
+ end
44
+ end
@@ -0,0 +1,4 @@
1
+ require 'spec_helper'
2
+
3
+ describe Skimlinks::Product do
4
+ end
@@ -0,0 +1,7 @@
1
+ require 'spec_helper'
2
+
3
+ describe Skimlinks do
4
+ it 'has a version' do
5
+ Skimlinks::VERSION.should_not be_nil
6
+ end
7
+ end
@@ -0,0 +1,21 @@
1
+ require 'skimlinks'
2
+ require 'webmock/rspec'
3
+ require 'vcr'
4
+ require 'ffaker'
5
+ # require 'gem_config/rspec'
6
+
7
+ VCR.configure do |config|
8
+ config.hook_into :webmock
9
+ config.cassette_library_dir = 'spec/fixtures/vcr_cassettes'
10
+ config.default_cassette_options = {
11
+ allow_playback_repeats: true,
12
+ match_requests_on: [:method, VCR.request_matchers.uri_without_param(:key)]
13
+ }
14
+ end
15
+
16
+ RSpec.configure do |config|
17
+ config.treat_symbols_as_metadata_keys_with_true_values = true
18
+ config.run_all_when_everything_filtered = true
19
+ config.filter_run :focus
20
+ config.order = 'random'
21
+ end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: skimlinks
3
3
  version: !ruby/object:Gem::Version
4
- version: 1.0.0
4
+ version: 1.0.1
5
5
  platform: ruby
6
6
  authors:
7
7
  - Manuel Meurer
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2013-05-18 00:00:00.000000000 Z
11
+ date: 2013-07-01 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: rake
@@ -44,14 +44,14 @@ dependencies:
44
44
  requirements:
45
45
  - - ~>
46
46
  - !ruby/object:Gem::Version
47
- version: 1.11.0
47
+ version: '1.11'
48
48
  type: :development
49
49
  prerelease: false
50
50
  version_requirements: !ruby/object:Gem::Requirement
51
51
  requirements:
52
52
  - - ~>
53
53
  - !ruby/object:Gem::Version
54
- version: 1.11.0
54
+ version: '1.11'
55
55
  - !ruby/object:Gem::Dependency
56
56
  name: vcr
57
57
  requirement: !ruby/object:Gem::Requirement
@@ -122,6 +122,76 @@ dependencies:
122
122
  - - ~>
123
123
  - !ruby/object:Gem::Version
124
124
  version: 2.5.0
125
+ - !ruby/object:Gem::Dependency
126
+ name: gem_config
127
+ requirement: !ruby/object:Gem::Requirement
128
+ requirements:
129
+ - - ~>
130
+ - !ruby/object:Gem::Version
131
+ version: 0.0.2
132
+ type: :runtime
133
+ prerelease: false
134
+ version_requirements: !ruby/object:Gem::Requirement
135
+ requirements:
136
+ - - ~>
137
+ - !ruby/object:Gem::Version
138
+ version: 0.0.2
139
+ - !ruby/object:Gem::Dependency
140
+ name: mechanize
141
+ requirement: !ruby/object:Gem::Requirement
142
+ requirements:
143
+ - - ~>
144
+ - !ruby/object:Gem::Version
145
+ version: '2.5'
146
+ type: :runtime
147
+ prerelease: false
148
+ version_requirements: !ruby/object:Gem::Requirement
149
+ requirements:
150
+ - - ~>
151
+ - !ruby/object:Gem::Version
152
+ version: '2.5'
153
+ - !ruby/object:Gem::Dependency
154
+ name: rest-client
155
+ requirement: !ruby/object:Gem::Requirement
156
+ requirements:
157
+ - - ~>
158
+ - !ruby/object:Gem::Version
159
+ version: 1.6.7
160
+ type: :runtime
161
+ prerelease: false
162
+ version_requirements: !ruby/object:Gem::Requirement
163
+ requirements:
164
+ - - ~>
165
+ - !ruby/object:Gem::Version
166
+ version: 1.6.7
167
+ - !ruby/object:Gem::Dependency
168
+ name: activesupport
169
+ requirement: !ruby/object:Gem::Requirement
170
+ requirements:
171
+ - - ~>
172
+ - !ruby/object:Gem::Version
173
+ version: '3.0'
174
+ type: :runtime
175
+ prerelease: false
176
+ version_requirements: !ruby/object:Gem::Requirement
177
+ requirements:
178
+ - - ~>
179
+ - !ruby/object:Gem::Version
180
+ version: '3.0'
181
+ - !ruby/object:Gem::Dependency
182
+ name: activemodel
183
+ requirement: !ruby/object:Gem::Requirement
184
+ requirements:
185
+ - - ~>
186
+ - !ruby/object:Gem::Version
187
+ version: '3.0'
188
+ type: :runtime
189
+ prerelease: false
190
+ version_requirements: !ruby/object:Gem::Requirement
191
+ requirements:
192
+ - - ~>
193
+ - !ruby/object:Gem::Version
194
+ version: '3.0'
125
195
  description: A simple wrapper around the Skimlinks APIs
126
196
  email: manuel.meurer@gmail.com
127
197
  executables: []
@@ -136,8 +206,23 @@ files:
136
206
  - README.md
137
207
  - Rakefile
138
208
  - lib/skimlinks.rb
209
+ - lib/skimlinks/client.rb
210
+ - lib/skimlinks/merchant.rb
211
+ - lib/skimlinks/merchant_search.rb
212
+ - lib/skimlinks/product.rb
213
+ - lib/skimlinks/product_search.rb
214
+ - lib/skimlinks/search_helpers.rb
139
215
  - lib/skimlinks/version.rb
140
216
  - skimlinks.gemspec
217
+ - spec/fixtures/vcr_cassettes/Skimlinks_MerchantSearch.yml
218
+ - spec/fixtures/vcr_cassettes/Skimlinks_ProductSearch.yml
219
+ - spec/skimlinks/client_spec.rb
220
+ - spec/skimlinks/merchant_search_spec.rb
221
+ - spec/skimlinks/merchant_spec.rb
222
+ - spec/skimlinks/product_search_spec.rb
223
+ - spec/skimlinks/product_spec.rb
224
+ - spec/skimlinks/skimlinks_spec.rb
225
+ - spec/spec_helper.rb
141
226
  homepage: https://github.com/krautcomputing/skimlinks
142
227
  licenses:
143
228
  - MIT
@@ -162,4 +247,14 @@ rubygems_version: 2.0.2
162
247
  signing_key:
163
248
  specification_version: 4
164
249
  summary: A simple wrapper around the Skimlinks APIs
165
- test_files: []
250
+ test_files:
251
+ - spec/fixtures/vcr_cassettes/Skimlinks_MerchantSearch.yml
252
+ - spec/fixtures/vcr_cassettes/Skimlinks_ProductSearch.yml
253
+ - spec/skimlinks/client_spec.rb
254
+ - spec/skimlinks/merchant_search_spec.rb
255
+ - spec/skimlinks/merchant_spec.rb
256
+ - spec/skimlinks/product_search_spec.rb
257
+ - spec/skimlinks/product_spec.rb
258
+ - spec/skimlinks/skimlinks_spec.rb
259
+ - spec/spec_helper.rb
260
+ has_rdoc: