shopify_api 4.9.0 → 5.0.0

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.
Files changed (64) hide show
  1. checksums.yaml +4 -4
  2. data/.rubocop.yml +8 -0
  3. data/.travis.yml +0 -4
  4. data/CHANGELOG +25 -0
  5. data/README.md +36 -14
  6. data/lib/shopify_api/limits.rb +1 -2
  7. data/lib/shopify_api/resources/abandoned_checkout.rb +7 -0
  8. data/lib/shopify_api/resources/access_scope.rb +5 -0
  9. data/lib/shopify_api/resources/api_permission.rb +9 -0
  10. data/lib/shopify_api/resources/asset.rb +8 -8
  11. data/lib/shopify_api/resources/billing_address.rb +1 -1
  12. data/lib/shopify_api/resources/checkout.rb +24 -1
  13. data/lib/shopify_api/resources/custom_collection.rb +3 -3
  14. data/lib/shopify_api/resources/{customer_invite_message.rb → customer_invite.rb} +0 -0
  15. data/lib/shopify_api/resources/graphql.rb +22 -0
  16. data/lib/shopify_api/resources/image.rb +2 -2
  17. data/lib/shopify_api/resources/inventory_item.rb +6 -0
  18. data/lib/shopify_api/resources/inventory_level.rb +55 -0
  19. data/lib/shopify_api/resources/line_item.rb +9 -1
  20. data/lib/shopify_api/resources/location.rb +4 -0
  21. data/lib/shopify_api/resources/o_auth.rb +8 -0
  22. data/lib/shopify_api/resources/order.rb +7 -2
  23. data/lib/shopify_api/resources/payment.rb +7 -0
  24. data/lib/shopify_api/resources/ping.rb +3 -0
  25. data/lib/shopify_api/resources/ping/conversation.rb +18 -0
  26. data/lib/shopify_api/resources/ping/message.rb +9 -0
  27. data/lib/shopify_api/resources/product.rb +4 -4
  28. data/lib/shopify_api/resources/shipping_line.rb +1 -1
  29. data/lib/shopify_api/resources/shipping_rate.rb +7 -0
  30. data/lib/shopify_api/resources/shop.rb +4 -4
  31. data/lib/shopify_api/session.rb +1 -1
  32. data/lib/shopify_api/version.rb +1 -1
  33. data/shopify_api.gemspec +2 -1
  34. data/test/abandoned_checkouts_test.rb +29 -0
  35. data/test/api_permission_test.rb +9 -0
  36. data/test/checkouts_test.rb +67 -4
  37. data/test/detailed_log_subscriber_test.rb +3 -2
  38. data/test/fixtures/abandoned_checkout.json +184 -0
  39. data/test/fixtures/abandoned_checkouts.json +186 -0
  40. data/test/fixtures/checkout.json +160 -0
  41. data/test/fixtures/checkouts.json +25 -49
  42. data/test/fixtures/inventory_level.json +7 -0
  43. data/test/fixtures/inventory_levels.json +24 -0
  44. data/test/fixtures/order_with_properties.json +373 -0
  45. data/test/fixtures/payment.json +7 -0
  46. data/test/fixtures/payments.json +9 -0
  47. data/test/fixtures/ping/conversation.json +1 -0
  48. data/test/fixtures/ping/message.json +1 -0
  49. data/test/fixtures/shipping_rates.json +12 -0
  50. data/test/inventory_level_test.rb +59 -0
  51. data/test/location_test.rb +14 -0
  52. data/test/order_test.rb +13 -1
  53. data/test/payment_test.rb +19 -0
  54. data/test/ping/conversation_test.rb +39 -0
  55. data/test/session_test.rb +11 -11
  56. data/test/shipping_rate_test.rb +17 -0
  57. data/test/test_helper.rb +7 -5
  58. data/test/variant_test.rb +4 -1
  59. metadata +49 -10
  60. data/lib/shopify_api/resources/discount.rb +0 -11
  61. data/test/discount_test.rb +0 -52
  62. data/test/fixtures/discount.json +0 -17
  63. data/test/fixtures/discount_disabled.json +0 -17
  64. data/test/fixtures/discounts.json +0 -34
@@ -0,0 +1,7 @@
1
+ {
2
+ "inventory_level" : {
3
+ "inventory_item_id": 808950810,
4
+ "location_id": 905684977,
5
+ "available": 1
6
+ }
7
+ }
@@ -0,0 +1,24 @@
1
+ {
2
+ "inventory_levels": [
3
+ {
4
+ "inventory_item_id": 39072856,
5
+ "location_id": 487838322,
6
+ "available": 27
7
+ },
8
+ {
9
+ "inventory_item_id": 808950810,
10
+ "location_id": 905684977,
11
+ "available": 1
12
+ },
13
+ {
14
+ "inventory_item_id": 808950810,
15
+ "location_id": 487838322,
16
+ "available": 9
17
+ },
18
+ {
19
+ "inventory_item_id": 39072856,
20
+ "location_id": 905684977,
21
+ "available": 3
22
+ }
23
+ ]
24
+ }
@@ -0,0 +1,373 @@
1
+ {
2
+ "order": {
3
+ "buyer_accepts_marketing": false,
4
+ "cancel_reason": null,
5
+ "cancelled_at": null,
6
+ "cart_token": "68778783ad298f1c80c3bafcddeea02f",
7
+ "checkout_token": null,
8
+ "closed_at": null,
9
+ "confirmed": false,
10
+ "created_at": "2008-01-10T11:00:00-05:00",
11
+ "currency": "USD",
12
+ "email": "bob.norman@hostmail.com",
13
+ "financial_status": "authorized",
14
+ "fulfillment_status": null,
15
+ "gateway": "authorize_net",
16
+ "id": 450789469,
17
+ "landing_site": "http://www.example.com?source=abc",
18
+ "location_id": null,
19
+ "name": "#1001",
20
+ "note": "Test note",
21
+ "number": 1,
22
+ "reference": "fhwdgads",
23
+ "referring_site": "http://www.otherexample.com",
24
+ "source": null,
25
+ "source_identifier": "fhwdgads",
26
+ "source_name": "web",
27
+ "source_url": null,
28
+ "subtotal_price": "398.00",
29
+ "taxes_included": false,
30
+ "test": false,
31
+ "token": "b1946ac92492d2347c6235b4d2611184",
32
+ "total_discounts": "0.00",
33
+ "total_line_items_price": "398.00",
34
+ "total_price": "409.94",
35
+ "total_price_usd": "409.94",
36
+ "total_tax": "11.94",
37
+ "total_weight": 0,
38
+ "updated_at": "2008-01-10T11:00:00-05:00",
39
+ "user_id": null,
40
+ "browser_ip": null,
41
+ "landing_site_ref": "abc",
42
+ "order_number": 1001,
43
+ "discount_codes": [],
44
+ "note_attributes": [],
45
+ "processing_method": "direct",
46
+ "checkout_id": 450789469,
47
+ "tax_lines": [
48
+ {
49
+ "price": "11.94",
50
+ "rate": 0.06,
51
+ "title": "State Tax"
52
+ }
53
+ ],
54
+ "tags": "",
55
+ "line_items": [
56
+ {
57
+ "fulfillment_service": "manual",
58
+ "fulfillment_status": null,
59
+ "grams": 1361,
60
+ "id": 466157049,
61
+ "price": "45.00",
62
+ "product_id": 632910392,
63
+ "quantity": 1,
64
+ "requires_shipping": true,
65
+ "sku": "",
66
+ "taxable": true,
67
+ "title": "Create Your Own Coffee 3 Pack",
68
+ "variant_id": 39072856,
69
+ "variant_title": "",
70
+ "vendor": "VCR",
71
+ "name": "Create Your Own Coffee 3 Pack",
72
+ "variant_inventory_management": null,
73
+ "properties": [
74
+ {
75
+ "name": "1st Coffee",
76
+ "value": "Coffee1"
77
+ },
78
+ {
79
+ "name": "2nd Coffee",
80
+ "value": "Coffee2"
81
+ },
82
+ {
83
+ "name": "3rd Coffee",
84
+ "value": "Coffee3"
85
+ },
86
+ {
87
+ "name": "Select Your Grind",
88
+ "value": "Ground"
89
+ }
90
+ ],
91
+ "product_exists": true,
92
+ "tax_lines": [
93
+
94
+ ]
95
+ },
96
+ {
97
+ "fulfillment_service": "manual",
98
+ "fulfillment_status": null,
99
+ "grams": 680,
100
+ "id": 641254555689,
101
+ "price": "24.00",
102
+ "product_id": 288331137065,
103
+ "quantity": 1,
104
+ "requires_shipping": true,
105
+ "sku": "",
106
+ "taxable": true,
107
+ "title": "Create Your Own Coffee 3 Pack (8oz bags)",
108
+ "variant_id": 4107806867497,
109
+ "variant_title": "",
110
+ "vendor": "OMC",
111
+ "name": "Create Your Own Coffee 3 Pack (8oz bags)",
112
+ "variant_inventory_management": null,
113
+ "properties": [
114
+ {
115
+ "name": "By default may label with \"Roasted for ",
116
+ "value": {
117
+ "Your First Name": {
118
+ "\". If you want something specific on the label, enter it here:": ""
119
+ }
120
+ }
121
+ },
122
+ {
123
+ "name": "Select Your Grind",
124
+ "value": "Ground"
125
+ },
126
+ {
127
+ "name": "Coffees",
128
+ "value": "Coffee blend 1"
129
+ },
130
+ {
131
+ "name": "Coffees",
132
+ "value": "Coffee blend 2"
133
+ },
134
+ {
135
+ "name": "Coffees",
136
+ "value": "Coffee blend 3"
137
+ }
138
+ ],
139
+ "product_exists": true,
140
+ "tax_lines": [
141
+
142
+ ]
143
+ }
144
+ ],
145
+ "shipping_lines": [
146
+ {
147
+ "code": "Free Shipping",
148
+ "price": "0.00",
149
+ "source": "shopify",
150
+ "title": "Free Shipping",
151
+ "tax_lines": [
152
+
153
+ ]
154
+ }
155
+ ],
156
+ "payment_details": {
157
+ "avs_result_code": null,
158
+ "credit_card_bin": null,
159
+ "cvv_result_code": null,
160
+ "credit_card_number": "XXXX-XXXX-XXXX-4242",
161
+ "credit_card_company": "Visa"
162
+ },
163
+ "billing_address": {
164
+ "address1": "Chestnut Street 92",
165
+ "address2": "",
166
+ "city": "Louisville",
167
+ "company": null,
168
+ "country": "United States",
169
+ "first_name": "Bob",
170
+ "last_name": "Norman",
171
+ "latitude": "45.41634",
172
+ "longitude": "-75.6868",
173
+ "phone": "555-625-1199",
174
+ "province": "Kentucky",
175
+ "zip": "40202",
176
+ "name": "Bob Norman",
177
+ "country_code": "US",
178
+ "province_code": "KY"
179
+ },
180
+ "shipping_address": {
181
+ "address1": "Chestnut Street 92",
182
+ "address2": "",
183
+ "city": "Louisville",
184
+ "company": null,
185
+ "country": "United States",
186
+ "first_name": "Bob",
187
+ "last_name": "Norman",
188
+ "latitude": "45.41634",
189
+ "longitude": "-75.6868",
190
+ "phone": "555-625-1199",
191
+ "province": "Kentucky",
192
+ "zip": "40202",
193
+ "name": "Bob Norman",
194
+ "country_code": "US",
195
+ "province_code": "KY"
196
+ },
197
+ "fulfillments": [
198
+ {
199
+ "created_at": "2014-03-07T16:14:08-05:00",
200
+ "id": 255858046,
201
+ "order_id": 450789469,
202
+ "service": "manual",
203
+ "status": "failure",
204
+ "tracking_company": null,
205
+ "updated_at": "2014-03-07T16:14:08-05:00",
206
+ "tracking_number": "1Z2345",
207
+ "tracking_numbers": [
208
+ "1Z2345"
209
+ ],
210
+ "tracking_url": "http://wwwapps.ups.com/etracking/tracking.cgi?InquiryNumber1=1Z2345&TypeOfInquiryNumber=T&AcceptUPSLicenseAgreement=yes&submit=Track",
211
+ "tracking_urls": [
212
+ "http://wwwapps.ups.com/etracking/tracking.cgi?InquiryNumber1=1Z2345&TypeOfInquiryNumber=T&AcceptUPSLicenseAgreement=yes&submit=Track"
213
+ ],
214
+ "receipt": {
215
+ "testcase": true,
216
+ "authorization": "123456"
217
+ },
218
+ "line_items": [
219
+ {
220
+ "fulfillment_service": "manual",
221
+ "fulfillment_status": null,
222
+ "grams": 680,
223
+ "id": 641254555689,
224
+ "price": "24.00",
225
+ "product_id": 288331137065,
226
+ "quantity": 1,
227
+ "requires_shipping": true,
228
+ "sku": "",
229
+ "taxable": true,
230
+ "title": "Create Your Own Coffee 3 Pack (8oz bags)",
231
+ "variant_id": 4107806867497,
232
+ "variant_title": "",
233
+ "vendor": "OMC",
234
+ "name": "Create Your Own Coffee 3 Pack (8oz bags)",
235
+ "variant_inventory_management": null,
236
+ "properties": [
237
+ {
238
+ "name": "By default may label with \"Roasted for ",
239
+ "value": {
240
+ "Your First Name": {
241
+ "\". If you want something specific on the label, enter it here:": ""
242
+ }
243
+ }
244
+ },
245
+ {
246
+ "name": "Select Your Grind",
247
+ "value": "Ground"
248
+ },
249
+ {
250
+ "name": "Coffees",
251
+ "value": "Coffee blend 1"
252
+ },
253
+ {
254
+ "name": "Coffees",
255
+ "value": "Coffee blend 2"
256
+ },
257
+ {
258
+ "name": "Coffees",
259
+ "value": "Coffee blend 3"
260
+ }
261
+ ],
262
+ "product_exists": true,
263
+ "tax_lines": [
264
+
265
+ ]
266
+ }
267
+ ]
268
+ },
269
+ {
270
+ "created_at": "2014-03-07T16:14:08-05:00",
271
+ "id": 255858046,
272
+ "order_id": 450789469,
273
+ "service": "manual",
274
+ "status": "failure",
275
+ "tracking_company": null,
276
+ "updated_at": "2014-03-07T16:14:08-05:00",
277
+ "tracking_number": "1Z2345",
278
+ "tracking_numbers": [
279
+ "1Z2345"
280
+ ],
281
+ "tracking_url": "http://wwwapps.ups.com/etracking/tracking.cgi?InquiryNumber1=1Z2345&TypeOfInquiryNumber=T&AcceptUPSLicenseAgreement=yes&submit=Track",
282
+ "tracking_urls": [
283
+ "http://wwwapps.ups.com/etracking/tracking.cgi?InquiryNumber1=1Z2345&TypeOfInquiryNumber=T&AcceptUPSLicenseAgreement=yes&submit=Track"
284
+ ],
285
+ "receipt": {},
286
+ "line_items": [
287
+ {
288
+ "fulfillment_service": "manual",
289
+ "fulfillment_status": null,
290
+ "grams": 1361,
291
+ "id": 466157049,
292
+ "price": "45.00",
293
+ "product_id": 632910392,
294
+ "quantity": 1,
295
+ "requires_shipping": true,
296
+ "sku": "",
297
+ "taxable": true,
298
+ "title": "Create Your Own Coffee 3 Pack",
299
+ "variant_id": 39072856,
300
+ "variant_title": "",
301
+ "vendor": "VCR",
302
+ "name": "Create Your Own Coffee 3 Pack",
303
+ "variant_inventory_management": null,
304
+ "properties": [
305
+ {
306
+ "name": "1st Coffee",
307
+ "value": "Coffee1"
308
+ },
309
+ {
310
+ "name": "2nd Coffee",
311
+ "value": "Coffee2"
312
+ },
313
+ {
314
+ "name": "3rd Coffee",
315
+ "value": "Coffee3"
316
+ },
317
+ {
318
+ "name": "Select Your Grind",
319
+ "value": "Ground"
320
+ }
321
+ ],
322
+ "product_exists": true,
323
+ "tax_lines": [
324
+
325
+ ]
326
+ }
327
+ ]
328
+ }
329
+ ],
330
+ "client_details": {
331
+ "accept_language": null,
332
+ "browser_ip": "0.0.0.0",
333
+ "session_hash": null,
334
+ "user_agent": null
335
+ },
336
+ "customer": {
337
+ "accepts_marketing": false,
338
+ "created_at": "2014-03-07T16:14:08-05:00",
339
+ "email": "bob.norman@hostmail.com",
340
+ "first_name": "Bob",
341
+ "id": 207119551,
342
+ "last_name": "Norman",
343
+ "last_order_id": null,
344
+ "multipass_identifier": null,
345
+ "note": null,
346
+ "orders_count": 0,
347
+ "state": "disabled",
348
+ "total_spent": "0.00",
349
+ "updated_at": "2014-03-07T16:14:08-05:00",
350
+ "verified_email": true,
351
+ "tags": "",
352
+ "last_order_name": null,
353
+ "default_address": {
354
+ "address1": "Chestnut Street 92",
355
+ "address2": "",
356
+ "city": "Louisville",
357
+ "company": null,
358
+ "country": "United States",
359
+ "first_name": null,
360
+ "id": 207119551,
361
+ "last_name": null,
362
+ "phone": "555-625-1199",
363
+ "province": "Kentucky",
364
+ "zip": "40202",
365
+ "name": null,
366
+ "province_code": "KY",
367
+ "country_code": "US",
368
+ "country_name": "United States",
369
+ "default": true
370
+ }
371
+ }
372
+ }
373
+ }
@@ -0,0 +1,7 @@
1
+ {
2
+ "payment" : {
3
+ "amount": 10.00,
4
+ "session_id": "east-44a400ef20b36e38f10b882cb7260796",
5
+ "unique_token": "my-client-generated-idempotency-token"
6
+ }
7
+ }
@@ -0,0 +1,9 @@
1
+ {
2
+ "payments" : [
3
+ {
4
+ "amount": 10.00,
5
+ "session_id": "east-44a400ef20b36e38f10b882cb7260796",
6
+ "unique_token": "my-client-generated-idempotency-token"
7
+ }
8
+ ]
9
+ }
@@ -0,0 +1 @@
1
+ {"conversation":{"id":"d315d4f7-53bd-49ec-8808-23f6db3c641a","name":"my topic","participants":{"counts":{"total":1},"data":[{"id":"test","name":"foo","avatar":null,"group":"customer"}]},"shopify_account":{"domain":"backpackinghacks.myshopify.com"}}}
@@ -0,0 +1 @@
1
+ {"message":{"id":"d0c7a2e6-8084-4e79-8483-e4a1352b81f7","sender_id":"test","sender":{"id":"test","name":"foo","avatar":null,"group":"customer"},"content":{"text":"Hello from shopify_api"},"sent_at":"2018-08-29T22:16:05.589479Z"}}
@@ -0,0 +1,12 @@
1
+ [
2
+ {
3
+ "id": "canada_post-INT.TP.BOGUS-4.00",
4
+ "price": "4.00",
5
+ "title": "Small Packet International Air Bogus"
6
+ },
7
+ {
8
+ "id": "canada_post-INT.TP.BOGUS-8.00",
9
+ "price": "8.00",
10
+ "title": "Medium Packet International Air Bogus"
11
+ }
12
+ ]
@@ -0,0 +1,59 @@
1
+ require 'test_helper'
2
+
3
+ class InventoryLevelTest < Test::Unit::TestCase
4
+ def setup
5
+ super
6
+ @inventory_level_response = ActiveSupport::JSON.decode load_fixture('inventory_level')
7
+ @inventory_level = ShopifyAPI::InventoryLevel.new(@inventory_level_response['inventory_level'])
8
+ end
9
+
10
+ test ".find with inventory_item_ids and location_ids returns expected inventory levels" do
11
+ params = { inventory_item_ids: [808950810, 39072856], location_ids: [905684977, 487838322] }
12
+ fake "inventory_levels.json?#{params.to_param}", extension: false, method: :get,
13
+ status: 200, body: load_fixture('inventory_levels')
14
+ inventory_levels = ShopifyAPI::InventoryLevel.find(:all, params: params)
15
+
16
+ assert inventory_levels.all? { |item|
17
+ params[:location_ids].include?(item.location_id) &&
18
+ params[:inventory_item_ids].include?(item.inventory_item_id)
19
+ }, message: 'Response contained inventory_items or locations not requested.'
20
+ end
21
+
22
+ test '#adjust with adjustment value returns inventory_level with available increased by adjustment value' do
23
+ adjustment = 5
24
+ updated_available = @inventory_level.available + adjustment
25
+ @inventory_level_response[:available] = updated_available
26
+
27
+ fake 'inventory_levels/adjust', method: :post, body: ActiveSupport::JSON.encode(@inventory_level_response)
28
+ @inventory_level.adjust(adjustment)
29
+ assert_equal updated_available, @inventory_level.available
30
+ end
31
+
32
+ test '#connect saves an inventory_level associated with inventory_item and location_id' do
33
+ params = { inventory_item_id: 808950810, location_id: 99999999 }
34
+ response = params.clone
35
+ response[:available] = 0
36
+
37
+ fake 'inventory_levels/connect', method: :post, body: ActiveSupport::JSON.encode(response)
38
+ inventory_level = ShopifyAPI::InventoryLevel.new(params)
39
+ inventory_level.connect
40
+ assert_equal 0, inventory_level.available, message: 'expected newly connected location to have 0 inventory'
41
+ end
42
+
43
+ test '#destroy removes inventory_level and returns nil' do
44
+ params = { inventory_item_id: @inventory_level.inventory_item_id, location_id: @inventory_level.location_id }
45
+ fake "inventory_levels.json?#{params.to_param}", extension: false, method: :delete, status: 204, body: nil
46
+ assert_nil @inventory_level.destroy
47
+ end
48
+
49
+ test '#set with available value returns inventory_level with available as the available value' do
50
+ available = 13
51
+ response = @inventory_level_response.clone
52
+ response['inventory_level']['available'] = available
53
+
54
+ fake 'inventory_levels/set', method: :post, body: ActiveSupport::JSON.encode(response)
55
+ @inventory_level.set(available)
56
+
57
+ assert_equal available, @inventory_level.available
58
+ end
59
+ end