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,155 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: remixr
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.1.0
5
+ platform: ruby
6
+ authors:
7
+ - Wynn Netherland
8
+ - Jim Mulholland
9
+ autorequire:
10
+ bindir: bin
11
+ cert_chain: []
12
+
13
+ date: 2009-08-04 00:00:00 -05:00
14
+ default_executable:
15
+ dependencies:
16
+ - !ruby/object:Gem::Dependency
17
+ name: mash
18
+ type: :runtime
19
+ version_requirement:
20
+ version_requirements: !ruby/object:Gem::Requirement
21
+ requirements:
22
+ - - "="
23
+ - !ruby/object:Gem::Version
24
+ version: 0.0.3
25
+ version:
26
+ - !ruby/object:Gem::Dependency
27
+ name: httparty
28
+ type: :runtime
29
+ version_requirement:
30
+ version_requirements: !ruby/object:Gem::Requirement
31
+ requirements:
32
+ - - "="
33
+ - !ruby/object:Gem::Version
34
+ version: 0.4.3
35
+ version:
36
+ - !ruby/object:Gem::Dependency
37
+ name: thoughtbot-shoulda
38
+ type: :development
39
+ version_requirement:
40
+ version_requirements: !ruby/object:Gem::Requirement
41
+ requirements:
42
+ - - ">="
43
+ - !ruby/object:Gem::Version
44
+ version: "0"
45
+ version:
46
+ - !ruby/object:Gem::Dependency
47
+ name: jeremymcanally-matchy
48
+ type: :development
49
+ version_requirement:
50
+ version_requirements: !ruby/object:Gem::Requirement
51
+ requirements:
52
+ - - ">="
53
+ - !ruby/object:Gem::Version
54
+ version: "0"
55
+ version:
56
+ - !ruby/object:Gem::Dependency
57
+ name: mocha
58
+ type: :development
59
+ version_requirement:
60
+ version_requirements: !ruby/object:Gem::Requirement
61
+ requirements:
62
+ - - ">="
63
+ - !ruby/object:Gem::Version
64
+ version: "0"
65
+ version:
66
+ - !ruby/object:Gem::Dependency
67
+ name: fakeweb
68
+ type: :development
69
+ version_requirement:
70
+ version_requirements: !ruby/object:Gem::Requirement
71
+ requirements:
72
+ - - ">="
73
+ - !ruby/object:Gem::Version
74
+ version: "0"
75
+ version:
76
+ - !ruby/object:Gem::Dependency
77
+ name: mash
78
+ type: :development
79
+ version_requirement:
80
+ version_requirements: !ruby/object:Gem::Requirement
81
+ requirements:
82
+ - - ">="
83
+ - !ruby/object:Gem::Version
84
+ version: "0"
85
+ version:
86
+ description: wrapper for the BestBuy Remix api
87
+ email: wynn@squeejee.com
88
+ executables: []
89
+
90
+ extensions: []
91
+
92
+ extra_rdoc_files:
93
+ - README.markdown
94
+ files:
95
+ - History
96
+ - License
97
+ - Notes
98
+ - README.markdown
99
+ - Rakefile
100
+ - VERSION.yml
101
+ - examples/chaining.rb
102
+ - examples/find_products.rb
103
+ - examples/find_stores.rb
104
+ - lib/remixr.rb
105
+ - lib/remixr/client.rb
106
+ - test/fixtures/product_search_digital_photo_printer.json
107
+ - test/fixtures/products.json
108
+ - test/fixtures/products_over_20_bucks.json
109
+ - test/fixtures/products_over_3k_within_50_miles.json
110
+ - test/fixtures/products_skus_only.json
111
+ - test/fixtures/stores.json
112
+ - test/fixtures/stores_by_zip_02184.json
113
+ - test/fixtures/stores_in_list.json
114
+ - test/fixtures/stores_in_texas.json
115
+ - test/fixtures/stores_page_20.json
116
+ - test/fixtures/stores_page_20_sort_by_store_id_desc.json
117
+ - test/fixtures/stores_starting_with_zip_021.json
118
+ - test/fixtures/stores_within_50_miles_products_over_3k.json
119
+ - test/fixtures/stores_within_50_of_76227.json
120
+ - test/remixr/client_test.rb
121
+ - test/test_helper.rb
122
+ has_rdoc: true
123
+ homepage: http://github.com/squeejee/remixr
124
+ licenses: []
125
+
126
+ post_install_message:
127
+ rdoc_options:
128
+ - --charset=UTF-8
129
+ require_paths:
130
+ - lib
131
+ required_ruby_version: !ruby/object:Gem::Requirement
132
+ requirements:
133
+ - - ">="
134
+ - !ruby/object:Gem::Version
135
+ version: "0"
136
+ version:
137
+ required_rubygems_version: !ruby/object:Gem::Requirement
138
+ requirements:
139
+ - - ">="
140
+ - !ruby/object:Gem::Version
141
+ version: "0"
142
+ version:
143
+ requirements: []
144
+
145
+ rubyforge_project: remixr
146
+ rubygems_version: 1.3.3
147
+ signing_key:
148
+ specification_version: 3
149
+ summary: wrapper for the BestBuy Remix api
150
+ test_files:
151
+ - test/remixr/client_test.rb
152
+ - test/test_helper.rb
153
+ - examples/chaining.rb
154
+ - examples/find_products.rb
155
+ - examples/find_stores.rb