reenhanced-remixr 0.1.0

Sign up to get free protection for your applications and to get access to all the features.
@@ -0,0 +1,172 @@
1
+ {
2
+ "totalPages": 4,
3
+ "currentPage": 1,
4
+ "queryTime": "0.008",
5
+ "from": 1,
6
+ "total": 31,
7
+ "to": 10,
8
+ "stores": [
9
+ {
10
+ "fullPostalCode": "76205",
11
+ "city": "Denton",
12
+ "longName": "Best Buy - Denton",
13
+ "name": "Denton",
14
+ "region": "TX",
15
+ "country": "US",
16
+ "lng": -97.10067,
17
+ "postalCode": "76205",
18
+ "phone": "940-384-9581",
19
+ "hours": "Mon: 10-9; Tue: 10-9; Wed: 10-9; Thurs: 10-9; Fri: 10-10; Sat: 10-10; Sun: 11-8",
20
+ "lat": 33.192524,
21
+ "address": "1800 S Loop 288, Ste 102 Bldg 1 ",
22
+ "distance": 9.79,
23
+ "storeId": 827
24
+ },
25
+ {
26
+ "fullPostalCode": "75034",
27
+ "city": "Frisco",
28
+ "longName": "Best Buy - Frisco",
29
+ "name": "Frisco",
30
+ "region": "TX",
31
+ "country": "US",
32
+ "lng": -96.83974,
33
+ "postalCode": "75034",
34
+ "phone": "214-872-2079",
35
+ "hours": "Mon: 10-9; Tue: 10-9; Wed: 10-9; Thurs: 10-9; Fri: 10-10; Sat: 10-10; Sun: 10-8",
36
+ "lat": 33.17477,
37
+ "address": "5299 Eldorado Pkwy",
38
+ "distance": 10.79,
39
+ "storeId": 1773
40
+ },
41
+ {
42
+ "fullPostalCode": "75034",
43
+ "city": "Frisco",
44
+ "longName": "Best Buy - Frisco",
45
+ "name": "Frisco",
46
+ "region": "TX",
47
+ "country": "US",
48
+ "lng": -96.807182,
49
+ "postalCode": "75034",
50
+ "phone": "972-712-3939",
51
+ "hours": "Mon: 10-9; Tue: 10-9; Wed: 10-9; Thurs: 10-9; Fri: 10-10; Sat: 10-10; Sun: 11-8",
52
+ "lat": 33.108253,
53
+ "address": "3333 Preston Rd #200",
54
+ "distance": 15.49,
55
+ "storeId": 180
56
+ },
57
+ {
58
+ "fullPostalCode": "75056",
59
+ "city": "Lewisville",
60
+ "longName": "Best Buy - The Colony",
61
+ "name": "The Colony",
62
+ "region": "TX",
63
+ "country": "US",
64
+ "lng": -96.88915,
65
+ "postalCode": "75056",
66
+ "phone": "214-469-2979",
67
+ "hours": "Mon: 10-9; Tue: 10-9; Wed: 10-9; Thurs: 10-9; Fri: 10-10; Sat: 10-10; Sun: 11-8",
68
+ "lat": 33.06501,
69
+ "address": "4800 State Hwy 121 ",
70
+ "distance": 15.93,
71
+ "storeId": 1796
72
+ },
73
+ {
74
+ "fullPostalCode": "75022",
75
+ "city": "Flower Mound",
76
+ "longName": "Best Buy - Flower Mound",
77
+ "name": "Flower Mound",
78
+ "region": "TX",
79
+ "country": "US",
80
+ "lng": -97.080109,
81
+ "postalCode": "75022",
82
+ "phone": "972-874-0965",
83
+ "hours": "Mon: 10-9; Tue: 10-9; Wed: 10-9; Thurs: 10-9; Fri: 10-9; Sat: 9-9; Sun: 10-8",
84
+ "lat": 33.06926,
85
+ "address": "6060 Long Prairie Rd",
86
+ "distance": 16.15,
87
+ "storeId": 1038
88
+ },
89
+ {
90
+ "fullPostalCode": "75070",
91
+ "city": "Mckinney",
92
+ "longName": "Best Buy - SW Mckinney",
93
+ "name": "SW Mckinney",
94
+ "region": "TX",
95
+ "country": "US",
96
+ "lng": -96.72936,
97
+ "postalCode": "75070",
98
+ "phone": "214-250-5939",
99
+ "hours": "Mon: 10-9; Tue: 10-9; Wed: 10-9; Thurs: 10-9; Fri: 10-9; Sat: 10-9; Sun: 10-7",
100
+ "lat": 33.13148,
101
+ "address": "8720 State Hwy 121 Ste 112",
102
+ "distance": 17.59,
103
+ "storeId": 1775
104
+ },
105
+ {
106
+ "fullPostalCode": "75067",
107
+ "city": "Lewisville",
108
+ "longName": "Best Buy - Lewisville",
109
+ "name": "Lewisville",
110
+ "region": "TX",
111
+ "country": "US",
112
+ "lng": -96.963219,
113
+ "postalCode": "75067",
114
+ "phone": "214-488-8624",
115
+ "hours": "Mon: 10-9; Tue: 10-9; Wed: 10-9; Thurs: 10-9; Fri: 10-10; Sat: 10-10; Sun: 10-8",
116
+ "lat": 32.999397,
117
+ "address": "2601 S Stemmons Fwy",
118
+ "distance": 19.73,
119
+ "storeId": 258
120
+ },
121
+ {
122
+ "fullPostalCode": "75070",
123
+ "city": "Mckinney",
124
+ "longName": "Best Buy - Mckinney",
125
+ "name": "Mckinney",
126
+ "region": "TX",
127
+ "country": "US",
128
+ "lng": -96.639603,
129
+ "postalCode": "75070",
130
+ "phone": "972-542-8305",
131
+ "hours": "Mon: 10-9; Tue: 10-9; Wed: 10-9; Thurs: 10-9; Fri: 10-10; Sat: 10-10; Sun: 10-7",
132
+ "lat": 33.213333,
133
+ "address": "1751 N Central Expy Ste C",
134
+ "distance": 19.86,
135
+ "storeId": 196
136
+ },
137
+ {
138
+ "fullPostalCode": "75002",
139
+ "city": "Allen",
140
+ "longName": "Best Buy - Allen",
141
+ "name": "Allen",
142
+ "region": "TX",
143
+ "country": "US",
144
+ "lng": -96.65549,
145
+ "postalCode": "75002",
146
+ "phone": "469-675-8924",
147
+ "hours": "Mon: 10-9; Tue: 10-9; Wed: 10-9; Thurs: 10-9; Fri: 10-10; Sat: 10-10; Sun: 10-8",
148
+ "lat": 33.1267,
149
+ "address": "190 E Stacy Rd Bldg 3000",
150
+ "distance": 21.33,
151
+ "storeId": 1780
152
+ },
153
+ {
154
+ "fullPostalCode": "75074",
155
+ "city": "Plano",
156
+ "longName": "Best Buy - Plano ",
157
+ "name": "Plano ",
158
+ "region": "TX",
159
+ "country": "US",
160
+ "lng": -96.702805,
161
+ "postalCode": "75074",
162
+ "phone": "972-578-8000",
163
+ "hours": "Mon: 10-9:00; Tue: 10-9:00; Wed: 10-9:00; Thurs: 10-9:00; Fri: 10-10; Sat: 10-10; Sun: 10-8",
164
+ "lat": 33.035957,
165
+ "address": "2800 N Central Expy",
166
+ "distance": 23.21,
167
+ "storeId": 202
168
+ }
169
+ ],
170
+ "canonicalUrl": "\/v1\/stores(area(\"76227\",50))?format=json&apiKey=OU812",
171
+ "totalTime": "0.023"
172
+ }
@@ -0,0 +1,143 @@
1
+ require File.dirname(__FILE__) + '/../test_helper'
2
+
3
+ class ClientTest < Test::Unit::TestCase
4
+ include Remixr
5
+
6
+ context "Searching for stores" do
7
+ setup { @client = Remixr::Client.new('OU812') }
8
+
9
+ should "find all stores" do
10
+ stub_get '/stores?apiKey=OU812&format=json', 'stores.json'
11
+ stores = @client.stores.fetch.stores
12
+ stores.size.should == 10
13
+ stores.first.name.should == 'Caguas'
14
+ end
15
+
16
+ should "find stores by postal code as option" do
17
+ stub_get '/stores(postalCode=02184)?apiKey=OU812&format=json', 'stores_by_zip_02184.json'
18
+
19
+ stores = @client.stores({'postalCode' => '02184'}).fetch.stores
20
+ stores.size.should == 1
21
+ stores.first.name.should == 'Braintree'
22
+ end
23
+
24
+ should "find stores in zip" do
25
+ stub_get '/stores(postalCode=02184)?apiKey=OU812&format=json', 'stores_by_zip_02184.json'
26
+
27
+ stores = @client.stores.in_zip('02184').fetch.stores
28
+ stores.size.should == 1
29
+ stores.first.name.should == 'Braintree'
30
+ end
31
+
32
+ should "find stores starting with zip" do
33
+ stub_get '/stores(postalCode=021*)?apiKey=OU812&format=json', 'stores_starting_with_zip_021.json'
34
+
35
+ stores = @client.stores.in_zip('021*').fetch.stores
36
+ stores.size.should == 5
37
+ stores.first.name.should == 'Back Bay'
38
+ end
39
+
40
+ should "find stores in a region" do
41
+ stub_get '/stores(region=TX)?apiKey=OU812&format=json', 'stores_in_texas.json'
42
+
43
+ stores = @client.stores.in_region('TX').fetch.stores
44
+ stores.size.should == 10
45
+ stores.first.name.should == 'Lake Charles'
46
+ end
47
+
48
+ should "find stores within a radius of a postal code" do
49
+ stub_get '/stores(area(76227,50))?apiKey=OU812&format=json', 'stores_within_50_of_76227.json'
50
+
51
+ stores = @client.stores({'area' => [76227,50]}).fetch.stores
52
+ stores.size.should == 10
53
+ stores.first.name.should == 'Denton'
54
+ end
55
+
56
+ should "find stores matching a given list of store IDs" do
57
+ stub_get '/stores(storeId%20in(307,281,612))?apiKey=OU812&format=json', 'stores_in_list.json'
58
+
59
+ stores = @client.stores({'storeId' => {'$in' => [307,281,612]}}).fetch.stores
60
+ stores.size.should == 3
61
+ stores.first.name.should == 'Richfield'
62
+ end
63
+
64
+ end
65
+
66
+ context "Searching for products" do
67
+ setup { @client = Remixr::Client.new('OU812') }
68
+
69
+ should "find all products" do
70
+ stub_get '/products?apiKey=OU812&format=json', 'products.json'
71
+ products = @client.products.fetch.products
72
+ products.size.should == 10
73
+ products.first.sku.should == 7000032
74
+ end
75
+
76
+
77
+ should "find all products with sale price greater than twenty dollars" do
78
+ stub_get '/products(salePrice%3E20)?apiKey=OU812&format=json', 'products_over_20_bucks.json'
79
+ products = @client.products({'salePrice' => {'$gt' => 20}}).fetch.products
80
+ products.size.should == 10
81
+ products.first.sku.should == 16306454
82
+ end
83
+
84
+ should "find all products with based on search string" do
85
+ stub_get '/products(search=digital%20photo%20printer)?apiKey=OU812&format=json', 'product_search_digital_photo_printer.json'
86
+ products = @client.products({'search' => "digital photo printer"}).fetch.products
87
+ products.size.should == 2
88
+ products.first.sku.should == 4660432
89
+ end
90
+
91
+ end
92
+
93
+ context "When chaining product and store searches" do
94
+ setup { @client = Remixr::Client.new('OU812') }
95
+
96
+ should "return a products with nested stores" do
97
+ stub_get '/products(salePrice%3E3000)+stores(area(76227,50))?apiKey=OU812&format=json', 'products_over_3k_within_50_miles.json'
98
+ results = @client.products({'salePrice' => {'$gt' => 3000}}).stores({'area' => ['76227', 50]}).fetch
99
+ results.should_respond_to(:products)
100
+ results.should_not_respond_to(:stores)
101
+ results.products.first.sku.should == 9234198
102
+ end
103
+ end
104
+
105
+ context "When chaining store and product searches" do
106
+ setup { @client = Remixr::Client.new('OU812') }
107
+
108
+ should "return a products with nested stores" do
109
+ stub_get '/stores(area(76227,50))+products(salePrice%3E3000)?apiKey=OU812&format=json', 'stores_within_50_miles_products_over_3k.json'
110
+ results = @client.stores({'area' => ['76227', 50]}).products({'salePrice' => {'$gt' => 3000}}).fetch
111
+ results.stores.first.name.should == 'Denton'
112
+ results.stores.first.products.first.sku.should == 9234198
113
+ end
114
+ end
115
+
116
+ context "When using the API" do
117
+
118
+ setup { @client = Remixr::Client.new('OU812') }
119
+
120
+ should "support paging" do
121
+ stub_get '/stores?apiKey=OU812&format=json&page=20', 'stores_page_20.json'
122
+ stores = @client.stores.fetch({:page => 20}).stores
123
+ stores.size.should == 10
124
+ stores.first.storeId.should == 282
125
+ end
126
+
127
+ should "support sorting" do
128
+ stub_get '/stores?apiKey=OU812&format=json&page=20&sort=storeId.desc', 'stores_page_20_sort_by_store_id_desc.json'
129
+ stores = @client.stores.fetch({:page => 20, :sort => {'storeId' => 'desc'}}).stores
130
+ stores.size.should == 10
131
+ stores.first.storeId.should == 1159
132
+ end
133
+
134
+ should "support limiting return fields" do
135
+ stub_get '/products?apiKey=OU812&format=json&show=sku', 'products_skus_only.json'
136
+ products = @client.products.fetch({:show => 'sku'}).products
137
+ products.size.should == 10
138
+ products.first.sku.should == 7000032
139
+ products.first.format.should == nil
140
+ end
141
+
142
+ end
143
+ end
@@ -0,0 +1,36 @@
1
+ require 'rubygems'
2
+ require 'test/unit'
3
+ require 'shoulda'
4
+ require 'matchy'
5
+ require 'mocha'
6
+ require 'fakeweb'
7
+
8
+ FakeWeb.allow_net_connect = false
9
+
10
+ $LOAD_PATH.unshift(File.join(File.dirname(__FILE__), '..', 'lib'))
11
+ $LOAD_PATH.unshift(File.dirname(__FILE__))
12
+ require 'remixr'
13
+
14
+ class Test::Unit::TestCase
15
+ end
16
+
17
+ def fixture_file(filename)
18
+ return '' if filename == ''
19
+ file_path = File.expand_path(File.dirname(__FILE__) + '/fixtures/' + filename)
20
+ File.read(file_path)
21
+ end
22
+
23
+ def remix_url(url)
24
+ url =~ /^http/ ? url : "http://api.remix.bestbuy.com:80/v1#{url}"
25
+ end
26
+
27
+ def stub_get(url, filename, status=nil)
28
+ options = {:body => fixture_file(filename)}
29
+ options.merge!({:status => status}) unless status.nil?
30
+
31
+ FakeWeb.register_uri(:get, remix_url(url), options)
32
+ end
33
+
34
+ def stub_post(url, filename)
35
+ FakeWeb.register_uri(:post, remix_url(url), :body => fixture_file(filename))
36
+ end
metadata ADDED
@@ -0,0 +1,195 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: reenhanced-remixr
3
+ version: !ruby/object:Gem::Version
4
+ hash: 27
5
+ prerelease:
6
+ segments:
7
+ - 0
8
+ - 1
9
+ - 0
10
+ version: 0.1.0
11
+ platform: ruby
12
+ authors:
13
+ - Wynn Netherland
14
+ - Jim Mulholland
15
+ autorequire:
16
+ bindir: bin
17
+ cert_chain: []
18
+
19
+ date: 2009-08-04 00:00:00 -04:00
20
+ default_executable:
21
+ dependencies:
22
+ - !ruby/object:Gem::Dependency
23
+ name: mash
24
+ prerelease: false
25
+ requirement: &id001 !ruby/object:Gem::Requirement
26
+ none: false
27
+ requirements:
28
+ - - ">="
29
+ - !ruby/object:Gem::Version
30
+ hash: 3
31
+ segments:
32
+ - 0
33
+ version: "0"
34
+ type: :runtime
35
+ version_requirements: *id001
36
+ - !ruby/object:Gem::Dependency
37
+ name: httparty
38
+ prerelease: false
39
+ requirement: &id002 !ruby/object:Gem::Requirement
40
+ none: false
41
+ requirements:
42
+ - - ">="
43
+ - !ruby/object:Gem::Version
44
+ hash: 3
45
+ segments:
46
+ - 0
47
+ version: "0"
48
+ type: :runtime
49
+ version_requirements: *id002
50
+ - !ruby/object:Gem::Dependency
51
+ name: thoughtbot-shoulda
52
+ prerelease: false
53
+ requirement: &id003 !ruby/object:Gem::Requirement
54
+ none: false
55
+ requirements:
56
+ - - ">="
57
+ - !ruby/object:Gem::Version
58
+ hash: 3
59
+ segments:
60
+ - 0
61
+ version: "0"
62
+ type: :development
63
+ version_requirements: *id003
64
+ - !ruby/object:Gem::Dependency
65
+ name: jeremymcanally-matchy
66
+ prerelease: false
67
+ requirement: &id004 !ruby/object:Gem::Requirement
68
+ none: false
69
+ requirements:
70
+ - - ">="
71
+ - !ruby/object:Gem::Version
72
+ hash: 3
73
+ segments:
74
+ - 0
75
+ version: "0"
76
+ type: :development
77
+ version_requirements: *id004
78
+ - !ruby/object:Gem::Dependency
79
+ name: mocha
80
+ prerelease: false
81
+ requirement: &id005 !ruby/object:Gem::Requirement
82
+ none: false
83
+ requirements:
84
+ - - ">="
85
+ - !ruby/object:Gem::Version
86
+ hash: 3
87
+ segments:
88
+ - 0
89
+ version: "0"
90
+ type: :development
91
+ version_requirements: *id005
92
+ - !ruby/object:Gem::Dependency
93
+ name: fakeweb
94
+ prerelease: false
95
+ requirement: &id006 !ruby/object:Gem::Requirement
96
+ none: false
97
+ requirements:
98
+ - - ">="
99
+ - !ruby/object:Gem::Version
100
+ hash: 3
101
+ segments:
102
+ - 0
103
+ version: "0"
104
+ type: :development
105
+ version_requirements: *id006
106
+ - !ruby/object:Gem::Dependency
107
+ name: mash
108
+ prerelease: false
109
+ requirement: &id007 !ruby/object:Gem::Requirement
110
+ none: false
111
+ requirements:
112
+ - - ">="
113
+ - !ruby/object:Gem::Version
114
+ hash: 3
115
+ segments:
116
+ - 0
117
+ version: "0"
118
+ type: :development
119
+ version_requirements: *id007
120
+ description: wrapper for the BestBuy Remix api
121
+ email: wynn@squeejee.com
122
+ executables: []
123
+
124
+ extensions: []
125
+
126
+ extra_rdoc_files:
127
+ - README.markdown
128
+ files:
129
+ - History
130
+ - License
131
+ - Notes
132
+ - README.markdown
133
+ - Rakefile
134
+ - VERSION.yml
135
+ - examples/chaining.rb
136
+ - examples/find_products.rb
137
+ - examples/find_stores.rb
138
+ - lib/remixr.rb
139
+ - lib/remixr/client.rb
140
+ - test/fixtures/product_search_digital_photo_printer.json
141
+ - test/fixtures/products.json
142
+ - test/fixtures/products_over_20_bucks.json
143
+ - test/fixtures/products_over_3k_within_50_miles.json
144
+ - test/fixtures/products_skus_only.json
145
+ - test/fixtures/stores.json
146
+ - test/fixtures/stores_by_zip_02184.json
147
+ - test/fixtures/stores_in_list.json
148
+ - test/fixtures/stores_in_texas.json
149
+ - test/fixtures/stores_page_20.json
150
+ - test/fixtures/stores_page_20_sort_by_store_id_desc.json
151
+ - test/fixtures/stores_starting_with_zip_021.json
152
+ - test/fixtures/stores_within_50_miles_products_over_3k.json
153
+ - test/fixtures/stores_within_50_of_76227.json
154
+ - test/remixr/client_test.rb
155
+ - test/test_helper.rb
156
+ has_rdoc: true
157
+ homepage: http://github.com/squeejee/remixr
158
+ licenses: []
159
+
160
+ post_install_message:
161
+ rdoc_options:
162
+ - --charset=UTF-8
163
+ require_paths:
164
+ - lib
165
+ required_ruby_version: !ruby/object:Gem::Requirement
166
+ none: false
167
+ requirements:
168
+ - - ">="
169
+ - !ruby/object:Gem::Version
170
+ hash: 3
171
+ segments:
172
+ - 0
173
+ version: "0"
174
+ required_rubygems_version: !ruby/object:Gem::Requirement
175
+ none: false
176
+ requirements:
177
+ - - ">="
178
+ - !ruby/object:Gem::Version
179
+ hash: 3
180
+ segments:
181
+ - 0
182
+ version: "0"
183
+ requirements: []
184
+
185
+ rubyforge_project: remixr
186
+ rubygems_version: 1.4.1
187
+ signing_key:
188
+ specification_version: 3
189
+ summary: wrapper for the BestBuy Remix api
190
+ test_files:
191
+ - test/remixr/client_test.rb
192
+ - test/test_helper.rb
193
+ - examples/chaining.rb
194
+ - examples/find_products.rb
195
+ - examples/find_stores.rb