walmart_open 0.1.1 → 0.1.2

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: fa379e22ca9addd3faf813eca698a9e7b006be7b
4
- data.tar.gz: c525ed648bede3c023d7c871a6e734b9d0aee614
3
+ metadata.gz: 99ef0d1a053ce3fcd3bf4a46e79ef360cb169e57
4
+ data.tar.gz: 5d238dcb8bec67b17d36a0dc0a7640e5d57c3c59
5
5
  SHA512:
6
- metadata.gz: 80eacafcf598a84235fae992fc7ad253e98f88c286145d417f8845cd0e86e49bb20eae76b3da20c4fac5546fbdce982f3397585c27670e48ed5bb23408065614
7
- data.tar.gz: 1cdda5817fdd35b0101be616f4136dfe7c57d170b226d48894ab99cbb11a9ce5e0a58d2ee2290f3c4d479c4c7691a6252546e8c50772a8ba505576584568bb4c
6
+ metadata.gz: ac2ae75e1a8c323b597bd878f7740d45f854d5a5bdc443db31afe1de6bad592af19f5bb814b1024d96b6dd7a4624e361c8a828bfad73ad2fc609243280c93018
7
+ data.tar.gz: 3f657ba97af0af99d15d3447b56d378a62ae5b30efc47e445bd9ed8b28a4d4d414caa8fe6ef0025044ff1203d656d1171e21bb0a5351f66ab6c718c264500e62
@@ -2,6 +2,7 @@ require "walmart_open/config"
2
2
  require "walmart_open/connection_manager"
3
3
  require "walmart_open/requests/search"
4
4
  require "walmart_open/requests/lookup"
5
+ require "walmart_open/requests/upc_lookup"
5
6
  require "walmart_open/requests/taxonomy"
6
7
  require "walmart_open/requests/feed"
7
8
 
@@ -25,6 +26,10 @@ module WalmartOpen
25
26
  connection.request(Requests::Lookup.new(item_id, params))
26
27
  end
27
28
 
29
+ def upc_lookup(upc, params = {})
30
+ connection.request(Requests::UpcLookup.new(upc, params))
31
+ end
32
+
28
33
  def taxonomy
29
34
  connection.request(Requests::Taxonomy.new)
30
35
  end
@@ -6,6 +6,7 @@ module WalmartOpen
6
6
  :product_domain,
7
7
  :product_version,
8
8
  :product_api_key,
9
+ :linkshare_publisher_id,
9
10
  :product_calls_per_second
10
11
 
11
12
  def initialize(options = {})
@@ -0,0 +1,62 @@
1
+ require "builder"
2
+
3
+ module WalmartOpen
4
+ class OrderXMLBuilder
5
+ attr_reader :order
6
+
7
+ def initialize(order)
8
+ @order = order
9
+ end
10
+
11
+ def build
12
+ xml = Builder::XmlMarkup.new
13
+ xml.instruct!(:xml, version: "1.0", encoding: "UTF-8")
14
+ xml.order do |xml|
15
+ payment(xml)
16
+ shipping_address(xml)
17
+ xml.partnerOrderId(order.partner_order_id)
18
+ xml.partnerOrderTime(order.partner_order_time.strftime( "%H:%M:%S"))
19
+
20
+ xml.items do |xml|
21
+ order.items.each do |order_item|
22
+ item(xml, order_item)
23
+ end
24
+ end
25
+
26
+ xml.target!
27
+ end
28
+
29
+ end
30
+
31
+ private
32
+
33
+ def shipping_address(xml)
34
+ xml.shippingAddress do |xml|
35
+ xml.firstName(order.shipping_address.first_name)
36
+ xml.lastName(order.shipping_address.last_name) if order.shipping_address.last_name
37
+ xml.street1(order.shipping_address.street1)
38
+ xml.street2(order.shipping_address.street2) if order.shipping_address.street2
39
+ xml.city(order.shipping_address.city)
40
+ xml.state(order.shipping_address.state)
41
+ xml.zip(order.shipping_address.zipcode)
42
+ xml.country(order.shipping_address.country)
43
+ xml.phone(order.shipping_address.phone)
44
+ end
45
+ end
46
+
47
+ def payment(xml)
48
+ xml.payment do |xml|
49
+ xml.billingRecordId(order.billing_record_id)
50
+ end
51
+ end
52
+
53
+ def item(xml, order_item)
54
+ xml.item do |xml|
55
+ xml.itemId(order_item.item_id)
56
+ xml.quantity(order_item.quantity)
57
+ xml.itemPrice(order_item.item_price) if order_item.item_price
58
+ xml.shippingPrice(order_item.shipping_price) if order_item.shipping_price
59
+ end
60
+ end
61
+ end
62
+ end
@@ -28,10 +28,18 @@ module WalmartOpen
28
28
  end
29
29
 
30
30
  def build_params(client)
31
- {
31
+ base_params = {
32
32
  format: "json",
33
33
  api_key: client.config.product_api_key
34
- }.merge(params || {})
34
+ }
35
+
36
+ # In order to use affiliate URLs from Walmart, it is necessary to provide
37
+ # a publisher ID from LinkShare via the lsPublisherId param.
38
+ if client.config.linkshare_publisher_id
39
+ base_params[:ls_publisher_id] = client.config.linkshare_publisher_id
40
+ end
41
+
42
+ base_params.merge(params || {})
35
43
  end
36
44
 
37
45
  # Walmart API unofficially supports HTTPS so we rather hit that instead of
@@ -0,0 +1,57 @@
1
+ require "walmart_open/commerce_request"
2
+ require "walmart_open/order_xml_builder"
3
+ require "walmart_open/order_results"
4
+ require "walmart_open/errors"
5
+ require "openssl"
6
+ require "base64"
7
+
8
+
9
+ module WalmartOpen
10
+ module Requests
11
+ class ExecuteOrder < CommerceRequest
12
+ attr_accessor :verify_response
13
+
14
+ def initialize(verify_response)
15
+ self.path = "orders/execute"
16
+ @verify_response = verify_response
17
+ end
18
+
19
+ private
20
+
21
+ def parse_response(response)
22
+ if response["verifyResponse"]
23
+ response
24
+ else
25
+ end
26
+ #OrderResults.new(response.parsed_response)
27
+ end
28
+
29
+ def verify_response(response)
30
+ if response.code == 400
31
+ raise WalmartOpen::OrderError, response.parsed_response.inspect
32
+ end
33
+ super
34
+ end
35
+
36
+ def request_options(client)
37
+ signature = client.config.debug ? "FAKE_SIGNATURE" : sign(client.config.private_key, body)
38
+ {
39
+ headers: {
40
+ "Authorization" => client.auth_token.authorization_header,
41
+ "Content-Type" => "text/xml",
42
+ "X-Walmart-Body-Signature" => signature
43
+ },
44
+ body: @verify_response
45
+ }
46
+ end
47
+
48
+ def build_params(client)
49
+ { disablesigv: true } if client.config.debug
50
+ end
51
+
52
+ def sign(key, data)
53
+ Base64.urlsafe_encode64(key.sign(OpenSSL::Digest::SHA256.new, data))
54
+ end
55
+ end
56
+ end
57
+ end
@@ -0,0 +1,13 @@
1
+ require "walmart_open/item"
2
+ require "walmart_open/requests/lookup"
3
+
4
+ module WalmartOpen
5
+ module Requests
6
+ class UpcLookup < Lookup
7
+ def initialize(upc, params)
8
+ self.path = "items"
9
+ self.params = params.merge(upc: upc)
10
+ end
11
+ end
12
+ end
13
+ end
@@ -1,3 +1,3 @@
1
1
  module WalmartOpen
2
- VERSION = "0.1.1"
2
+ VERSION = "0.1.2"
3
3
  end
@@ -0,0 +1,21 @@
1
+ require "pathname"
2
+ require "webmock/rspec"
3
+
4
+ ROOT_PATH = Pathname.new(__FILE__).join("../..").expand_path
5
+ $LOAD_PATH.unshift(ROOT_PATH.join("lib"))
6
+
7
+ # TODO: don't leave this in:
8
+ Webmocok.allow_net_connect!
9
+
10
+ RSpec.configure do |config|
11
+ # Run specs in random order to surface order dependencies. If you find an
12
+ # order dependency and want to debug it, you can fix the order by providing
13
+ # the seed, which is printed after each run.
14
+ # --seed 1234
15
+ config.order = "random"
16
+
17
+ # Disable the should syntax compeletely; we use the expect syntax only.
18
+ config.expect_with :rspec do |c|
19
+ c.syntax = :expect
20
+ end
21
+ end
@@ -3,6 +3,7 @@ require "walmart_open/client"
3
3
  require "walmart_open/config"
4
4
  require "walmart_open/requests/search"
5
5
  require "walmart_open/requests/lookup"
6
+ require "walmart_open/requests/upc_lookup"
6
7
  require "walmart_open/requests/taxonomy"
7
8
  require "walmart_open/requests/feed"
8
9
 
@@ -64,6 +65,25 @@ describe WalmartOpen::Client do
64
65
  end
65
66
  end
66
67
 
68
+ context "#upc_lookup" do
69
+ it "generates a lookup request for a UPC" do
70
+ client = WalmartOpen::Client.new
71
+ params = double
72
+ request = double
73
+ upc = double
74
+
75
+ expect(WalmartOpen::Requests::UpcLookup).to receive(:new) do |upc_arg, params_arg|
76
+ expect(upc_arg).to eq(upc)
77
+ expect(params_arg).to eq(params)
78
+ request
79
+ end
80
+
81
+ expect(client.connection).to receive(:request).with(request)
82
+
83
+ client.upc_lookup(upc, params)
84
+ end
85
+ end
86
+
67
87
  context "#taxonomy" do
68
88
  it "delegates the request and returns the response" do
69
89
  client = WalmartOpen::Client.new
@@ -0,0 +1,250 @@
1
+ require "spec_helper"
2
+ require "walmart_open/client"
3
+ require "walmart_open/config"
4
+ require "walmart_open/requests/search"
5
+ require "walmart_open/order"
6
+ require "walmart_open/errors"
7
+
8
+ describe WalmartOpen::Client do
9
+ context ".new" do
10
+ context "when block is given" do
11
+ it "yields the config" do
12
+ yielded_config = nil
13
+
14
+ client = WalmartOpen::Client.new do |config|
15
+ yielded_config = config
16
+ end
17
+
18
+ expect(yielded_config).to be_kind_of(WalmartOpen::Config)
19
+ expect(yielded_config).to eq(client.config)
20
+ end
21
+ end
22
+
23
+ context "when block is not given" do
24
+ it "does not complain" do
25
+ client = WalmartOpen::Client.new
26
+ end
27
+ end
28
+ end
29
+
30
+ context "#search" do
31
+ it "delegates the request and returns the response" do
32
+ client = WalmartOpen::Client.new
33
+ query = double
34
+ params = double
35
+ request = double
36
+
37
+ expect(WalmartOpen::Requests::Search).to receive(:new) do |query_arg, params_arg|
38
+ expect(query_arg).to eq(query)
39
+ expect(params_arg).to eq(params)
40
+ request
41
+ end
42
+ expect(client.connection).to receive(:request).with(request)
43
+
44
+ client.search(query, params)
45
+ end
46
+ end
47
+
48
+ context "#lookup" do
49
+ it "delegates the request and returns the response" do
50
+ client = WalmartOpen::Client.new
51
+ item_id = double
52
+ params = double
53
+ request = double
54
+
55
+ expect(WalmartOpen::Requests::Lookup).to receive(:new) do |item_id_arg, params_arg|
56
+ expect(item_id_arg).to eq(item_id)
57
+ expect(params_arg).to eq(params)
58
+ request
59
+ end
60
+ expect(client.connection).to receive(:request).with(request)
61
+
62
+ client.lookup(item_id, params)
63
+ end
64
+ end
65
+
66
+ context "#taxonomy" do
67
+ it "delegates the request and returns the response" do
68
+ client = WalmartOpen::Client.new
69
+ request = double
70
+
71
+ expect(WalmartOpen::Requests::Taxonomy).to receive(:new).and_return(request)
72
+ expect(client.connection).to receive(:request).with(request)
73
+
74
+ client.taxonomy
75
+ end
76
+ end
77
+
78
+ context "#order" do
79
+ it "delegates the request and returns the response" do
80
+ client = WalmartOpen::Client.new
81
+ request = double
82
+ order_info = double
83
+
84
+ auth_token = double
85
+
86
+ expect(WalmartOpen::Requests::PlaceOrder).to receive(:new).and_return(request)
87
+ expect(WalmartOpen::Requests::Token).to receive(:new).and_return(auth_token)
88
+ expect(client.connection).to receive(:request).with(auth_token).and_return(auth_token)
89
+ expect(client.connection).to receive(:request).with(request)
90
+
91
+ client.order(order_info)
92
+ end
93
+ end
94
+
95
+ context "actual call test" do
96
+ context "#feed" do
97
+ before do
98
+ @client = WalmartOpen::Client.new do |config|
99
+ ## Product API
100
+ config.product_api_key = "jd72e9a32235765ckrewbpfw"
101
+
102
+ # This value defaults to 5.
103
+ config.product_calls_per_second = 4
104
+ ## Commerce API
105
+ config.commerce_api_key = "8tbvkxd6gu6zjzp6qbyeewb6"
106
+ config.commerce_api_secret = "CttvjYfupZ"
107
+ config.commerce_private_key = File.read("/Users/xlu/xlu_listia/walmart_open/private.key") #xlu comment out for now
108
+
109
+ # This value defaults to 2.
110
+ commerce_calls_per_second = 1
111
+
112
+ # Set this to true for development mode.
113
+ # This mainly applies to the Commerce API; orders will not actually be placed.
114
+ config.debug = false
115
+ end
116
+ end
117
+ it "delegates the request and returns the response" do
118
+ #client = WalmartOpen::Client.new
119
+ items = @client.feed(:bestsellers, "4171")
120
+ debugger
121
+ items = @client.feed(:preorder)
122
+ debugger
123
+ items = @client.feed(:rollback, "4171")
124
+ debugger
125
+ items = @client.feed(:clearance, "4171")
126
+ debugger
127
+ items = @client.feed(:specialbuy, "4171")
128
+ debugger
129
+ x = 1
130
+
131
+ end
132
+ end
133
+
134
+ before do
135
+ @client = WalmartOpen::Client.new do |config|
136
+ ## Product API
137
+ config.product_api_key = "jd72e9a32235765ckrewbpfw"
138
+
139
+ # This value defaults to 5.
140
+ config.product_calls_per_second = 4
141
+ ## Commerce API
142
+ config.commerce_api_key = "8tbvkxd6gu6zjzp6qbyeewb6"
143
+ config.commerce_api_secret = "CttvjYfupZ"
144
+ config.commerce_private_key = File.read("/Users/xlu/xlu_listia/walmart_open/private.key") #xlu comment out for now
145
+
146
+ # This value defaults to 2.
147
+ commerce_calls_per_second = 1
148
+
149
+ # Set this to true for development mode.
150
+ # This mainly applies to the Commerce API; orders will not actually be placed.
151
+ config.debug = false
152
+ end # 10371356 wks, 15076191
153
+ #sres = client.search(10371356);
154
+
155
+ end
156
+
157
+ it "should search by param" do
158
+ debugger
159
+ res = @client.search("ipod")
160
+ debugger
161
+ x = 1
162
+ end
163
+
164
+ it "should make a search for taxonomy" do
165
+
166
+ expect {
167
+ @client.config.product_api_key = nil
168
+
169
+ @client.taxonomy
170
+ }.to raise_error(WalmartOpen::AuthenticationError)
171
+
172
+ #res = @client.taxonomy
173
+ debugger
174
+ res
175
+ end
176
+
177
+ it "should make a search for a product" do
178
+ #item = @client.lookup(10371356)
179
+ expect {
180
+ item = @client.lookup(1)
181
+ }.to raise_error(WalmartOpen::ItemNotFoundError)
182
+ debugger
183
+ =begin
184
+ expect {
185
+
186
+ item = @client.lookup(1)
187
+ }.to raise_error(WalmartOpen::NotFoundError)
188
+
189
+ expect {
190
+ @client.config.product_api_key = nil
191
+
192
+ item = @client.lookup(1)
193
+ }.to raise_error(WalmartOpen::AuthenticationError)
194
+ =end
195
+ x = 1
196
+ end
197
+
198
+ it "makes an order in debug mode" do
199
+ debugger
200
+ =begin
201
+ params = {"billing_record_id"=>1,
202
+ :partner_order_id=>"51",
203
+ :partner_order_time => Time.parse('2013-12-12 12:22:26')}
204
+
205
+ street_params = {"first_name"=>"James",
206
+ :last_name=>"Fong",
207
+ :phone=>"606-478-0850",
208
+ "street1" =>"200 Blossom Lane",
209
+ "city" =>"Mountain View",
210
+ "state"=>"CA",
211
+ "zipcode"=>"94041", :country =>"USA"}
212
+ =end
213
+ params = {:billing_record_id=>1,
214
+ :partner_order_id=>"52",
215
+ "first_name"=>"James",
216
+ "last_name"=>"Fong",
217
+ "street1"=>"200 Blossom Lane",
218
+ "city"=>"Mountain View",
219
+ "state"=>"CA",
220
+ "zipcode"=>"94041",
221
+ "country"=>"USA",
222
+ "phone"=>"347-254-7842"}
223
+
224
+ order = WalmartOpen::Order.new(params)
225
+ debugger
226
+ item = @client.lookup(20925212)
227
+ order.add_item(item)
228
+
229
+ #item2 = @client.lookup(20658394) #order.add_item(20658394, 12.99, 4.97, 1)
230
+ #order.add_item(item2)
231
+ #order.add_item(10371356, 27.94, 0, 1)
232
+ #order.add_item(25174174, 1, 214.99, 0.0)
233
+ debugger
234
+ #order.valid?
235
+ #expect(order).to be_valid
236
+ debugger
237
+ begin
238
+ res = @client.order(order)
239
+ rescue => e
240
+ debugger
241
+ puts "order.valid?=#{order.valid?}, order.errors is: #{e.inspect}"
242
+ # "order.valid?=false, order.errors is: #<WalmartOpen::OrderError: {\"errors\"=>{\"error\"=>{\"code\"=>\"10020\", \"message\"=>\"This order has already been executed\"}}}>"
243
+ end
244
+ debugger
245
+ res
246
+ end
247
+ end
248
+
249
+
250
+ end
@@ -12,16 +12,19 @@ describe WalmartOpen::Config do
12
12
  expect(config.product_domain).to eq("walmartlabs.api.mashery.com")
13
13
  expect(config.product_version).to eq("v1")
14
14
  expect(config.product_calls_per_second).to be(5)
15
+ expect(config.linkshare_publisher_id).to eq(nil)
15
16
  end
16
17
 
17
18
  it "allows setting configs" do
18
19
  config = WalmartOpen::Config.new({debug: true, product_domain: "test",
19
- product_version: "test", product_calls_per_second: 1,
20
+ product_version: "test", linkshare_publisher_id: "test",
21
+ product_calls_per_second: 1,
20
22
  })
21
23
 
22
24
  expect(config.debug).to be(true)
23
25
  expect(config.product_domain).to eq("test")
24
26
  expect(config.product_version).to eq("test")
27
+ expect(config.linkshare_publisher_id).to eq("test")
25
28
  expect(config.product_calls_per_second).to be(1)
26
29
  end
27
30
  end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: walmart_open
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.1.1
4
+ version: 0.1.2
5
5
  platform: ruby
6
6
  authors:
7
7
  - Ngan Pham
@@ -9,7 +9,7 @@ authors:
9
9
  autorequire:
10
10
  bindir: bin
11
11
  cert_chain: []
12
- date: 2015-05-06 00:00:00.000000000 Z
12
+ date: 2016-03-28 00:00:00.000000000 Z
13
13
  dependencies:
14
14
  - !ruby/object:Gem::Dependency
15
15
  name: httparty
@@ -140,16 +140,21 @@ files:
140
140
  - lib/walmart_open/connection_manager.rb
141
141
  - lib/walmart_open/errors.rb
142
142
  - lib/walmart_open/item.rb
143
+ - lib/walmart_open/order_verify_xml_builder.rb
143
144
  - lib/walmart_open/request.rb
145
+ - lib/walmart_open/requests/execute_order.rb
144
146
  - lib/walmart_open/requests/feed.rb
145
147
  - lib/walmart_open/requests/lookup.rb
146
148
  - lib/walmart_open/requests/search.rb
147
149
  - lib/walmart_open/requests/taxonomy.rb
150
+ - lib/walmart_open/requests/upc_lookup.rb
148
151
  - lib/walmart_open/search_results.rb
149
152
  - lib/walmart_open/stock_string.rb
150
153
  - lib/walmart_open/version.rb
151
154
  - spec/spec_helper.rb
155
+ - spec/spec_helper.rb.xlukeep
152
156
  - spec/walmart_open/client_spec.rb
157
+ - spec/walmart_open/client_spec.rb.xlun2
153
158
  - spec/walmart_open/config_spec.rb
154
159
  - spec/walmart_open/connection_manager_spec.rb
155
160
  - spec/walmart_open/item_spec.rb
@@ -186,7 +191,9 @@ specification_version: 4
186
191
  summary: Ruby implementation for Walmart Open API
187
192
  test_files:
188
193
  - spec/spec_helper.rb
194
+ - spec/spec_helper.rb.xlukeep
189
195
  - spec/walmart_open/client_spec.rb
196
+ - spec/walmart_open/client_spec.rb.xlun2
190
197
  - spec/walmart_open/config_spec.rb
191
198
  - spec/walmart_open/connection_manager_spec.rb
192
199
  - spec/walmart_open/item_spec.rb