shopify_api 9.0.2 → 9.0.3
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/CHANGELOG.md +12 -0
- data/README.md +6 -0
- data/lib/shopify_api/resources/discount_code_batch.rb +32 -0
- data/lib/shopify_api/resources/product.rb +21 -0
- data/lib/shopify_api/resources/variant.rb +31 -0
- data/lib/shopify_api/version.rb +1 -1
- data/shopify_api.gemspec +2 -0
- data/test/discount_code_batch_test.rb +40 -0
- data/test/fixtures/discount_code_batch.json +14 -0
- data/test/fixtures/discount_code_batch_discount_codes.json +21 -0
- data/test/product_test.rb +39 -0
- data/test/test_helper.rb +1 -1
- data/test/variant_test.rb +89 -0
- metadata +8 -3
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: a9f98c9f7ec2a7834c9b4f69c4dfa346e23b220173a03690cabc753e9d0b4318
|
4
|
+
data.tar.gz: 5245b531946faf49fc3213e7faadc5b8372ba71ccfa8e26f14d8b2630bff0d36
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: a8b09cb70ebd5ff98dfe08bb4adfb6f25cfa2a2f5023b7e9d703a6e97d33dd6beaac6dfbae29780cf6cab8f9de87718c1e3c5e6cdc8fe2b85b1258a9315c1fa9
|
7
|
+
data.tar.gz: f17ae5b2022d64fe91391dda645e9684b57449dd274f3de0ebbf8c8117072c67d78849646ba914c1432f60b4cfce46ed4b62432e7ecdb00651e1f59210d26c2a
|
data/CHANGELOG.md
CHANGED
@@ -1,3 +1,15 @@
|
|
1
|
+
## Version 9.0.3
|
2
|
+
|
3
|
+
* We now raise a `ShopifyAPI::ValidationException` exception when clients try to use `Product` and `Variant` with deprecated inventory-related fields in API version `2019-10` or later. [#655](https://github.com/shopify/shopify_api/pull/655) Deprecation and migration information can be found in the following documents:
|
4
|
+
* [Product Variant REST API Reference](https://shopify.dev/docs/admin-api/rest/reference/products/product-variant)
|
5
|
+
* [Migrate your app to support multiple locations](https://shopify.dev/tutorials/migrate-your-app-to-support-multiple-locations)
|
6
|
+
* [Manage product inventory with the Admin API](https://shopify.dev/tutorials/manage-product-inventory-with-admin-api)
|
7
|
+
* Added support for the Discount Code API batch endpoints [#701](https://github.com/shopify/shopify_api/pull/701)
|
8
|
+
* [Create](https://shopify.dev/docs/admin-api/rest/reference/discounts/discountcode#batch_create-2020-01)
|
9
|
+
* [Show](https://shopify.dev/docs/admin-api/rest/reference/discounts/discountcode#batch_show-2020-01)
|
10
|
+
* [List](https://shopify.dev/docs/admin-api/rest/reference/discounts/discountcode#batch_discount_codes_index-2020-01)
|
11
|
+
* Fix issue in the README to explicitly say clients need to require the `shopify_api` gem [#700](https://github.com/Shopify/shopify_api/pull/700)
|
12
|
+
|
1
13
|
## Version 9.0.2
|
2
14
|
|
3
15
|
* Added optional flag passed to `initialize_clients` to prevent from raising the `InvalidSchema` exception [#693](https://github.com/Shopify/shopify_api/pull/693)
|
data/README.md
CHANGED
@@ -73,6 +73,12 @@ Or install via [gem](http://rubygems.org/)
|
|
73
73
|
gem install shopify_api
|
74
74
|
```
|
75
75
|
|
76
|
+
Once the gem is installed, it must be added to your project by placing the following line in your app :
|
77
|
+
|
78
|
+
```ruby
|
79
|
+
require 'shopify_api'
|
80
|
+
```
|
81
|
+
|
76
82
|
## Getting Started
|
77
83
|
|
78
84
|
ShopifyAPI sessions need to be configured with a fully authorized URL of a particular store before they can start making API calls. To obtain that URL, you can follow these steps:
|
@@ -0,0 +1,32 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
module ShopifyAPI
|
3
|
+
class DiscountCodeBatch < Base
|
4
|
+
init_prefix :price_rule
|
5
|
+
|
6
|
+
self.collection_name = 'batch'
|
7
|
+
|
8
|
+
def price_rule_id
|
9
|
+
@prefix_options[:price_rule_id]
|
10
|
+
end
|
11
|
+
|
12
|
+
def discount_code_job
|
13
|
+
@discount_codes ||= begin
|
14
|
+
if id
|
15
|
+
path = self.class.api_version.construct_api_path("price_rules/#{price_rule_id}/batch/#{id}/discount_codes.json")
|
16
|
+
discount_codes = ShopifyAPI::DiscountCode.find :all, from: path
|
17
|
+
discount_codes.each do |code|
|
18
|
+
errors = code.attributes['errors']
|
19
|
+
errors.attributes.each do |key, values|
|
20
|
+
values.each { |message| code.errors.add(key, message) }
|
21
|
+
end
|
22
|
+
end
|
23
|
+
discount_codes
|
24
|
+
end
|
25
|
+
end
|
26
|
+
end
|
27
|
+
|
28
|
+
def encode(options = {})
|
29
|
+
send("to_#{self.class.format.extension}", options)
|
30
|
+
end
|
31
|
+
end
|
32
|
+
end
|
@@ -16,6 +16,15 @@ module ShopifyAPI
|
|
16
16
|
end
|
17
17
|
end
|
18
18
|
|
19
|
+
def total_inventory=(new_value)
|
20
|
+
raise_deprecated_inventory_call('total_inventory') unless allow_inventory_params?
|
21
|
+
super
|
22
|
+
end
|
23
|
+
|
24
|
+
def serializable_hash(options = {})
|
25
|
+
allow_inventory_params? ? super(options) : super(options).except('total_inventory')
|
26
|
+
end
|
27
|
+
|
19
28
|
def collections
|
20
29
|
CustomCollection.find(:all, :params => {:product_id => self.id})
|
21
30
|
end
|
@@ -31,5 +40,17 @@ module ShopifyAPI
|
|
31
40
|
def remove_from_collection(collection)
|
32
41
|
collection.remove_product(self)
|
33
42
|
end
|
43
|
+
|
44
|
+
private
|
45
|
+
|
46
|
+
def raise_deprecated_inventory_call(parameter)
|
47
|
+
raise(ShopifyAPI::ValidationException,
|
48
|
+
"'#{parameter}' is deprecated - see https://help.shopify.com/en/api/guides/inventory-migration-guide",
|
49
|
+
)
|
50
|
+
end
|
51
|
+
|
52
|
+
def allow_inventory_params?
|
53
|
+
Base.api_version < ApiVersion.find_version('2019-10')
|
54
|
+
end
|
34
55
|
end
|
35
56
|
end
|
@@ -4,5 +4,36 @@ module ShopifyAPI
|
|
4
4
|
include DisablePrefixCheck
|
5
5
|
|
6
6
|
conditional_prefix :product
|
7
|
+
|
8
|
+
def inventory_quantity_adjustment=(new_value)
|
9
|
+
raise_deprecated_inventory_call('inventory_quantity_adjustment') unless allow_inventory_params?
|
10
|
+
super
|
11
|
+
end
|
12
|
+
|
13
|
+
def inventory_quantity=(new_value)
|
14
|
+
raise_deprecated_inventory_call('inventory_quantity') unless allow_inventory_params?
|
15
|
+
super
|
16
|
+
end
|
17
|
+
|
18
|
+
def old_inventory_quantity=(new_value)
|
19
|
+
raise_deprecated_inventory_call('old_inventory_quantity') unless allow_inventory_params?
|
20
|
+
super
|
21
|
+
end
|
22
|
+
|
23
|
+
def serializable_hash(options = {})
|
24
|
+
allow_inventory_params? ? super(options) : super(options).except('inventory_quantity', 'old_inventory_quantity')
|
25
|
+
end
|
26
|
+
|
27
|
+
private
|
28
|
+
|
29
|
+
def raise_deprecated_inventory_call(parameter)
|
30
|
+
raise(ShopifyAPI::ValidationException,
|
31
|
+
"'#{parameter}' is deprecated - see https://help.shopify.com/en/api/guides/inventory-migration-guide",
|
32
|
+
)
|
33
|
+
end
|
34
|
+
|
35
|
+
def allow_inventory_params?
|
36
|
+
Base.api_version < ApiVersion.find_version('2019-10')
|
37
|
+
end
|
7
38
|
end
|
8
39
|
end
|
data/lib/shopify_api/version.rb
CHANGED
data/shopify_api.gemspec
CHANGED
@@ -0,0 +1,40 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
require 'test_helper'
|
3
|
+
|
4
|
+
class DiscountCodeBatchTest < Test::Unit::TestCase
|
5
|
+
def setup
|
6
|
+
super
|
7
|
+
fake 'price_rules/102586120/batch/989355119', body: load_fixture('discount_code_batch')
|
8
|
+
end
|
9
|
+
|
10
|
+
def test_get_batch
|
11
|
+
batch = ShopifyAPI::DiscountCodeBatch.find 989355119, params: { price_rule_id: 102586120 }
|
12
|
+
|
13
|
+
assert_equal 989355119, batch.id
|
14
|
+
end
|
15
|
+
|
16
|
+
def test_get_batch_discount_codes
|
17
|
+
fake 'price_rules/102586120/batch/989355119/discount_codes',
|
18
|
+
method: :get,
|
19
|
+
status: 200,
|
20
|
+
body: load_fixture('discount_code_batch_discount_codes')
|
21
|
+
|
22
|
+
batch = ShopifyAPI::DiscountCodeBatch.find 989355119, params: { price_rule_id: 102586120 }
|
23
|
+
discount_code_job = batch.discount_code_job
|
24
|
+
|
25
|
+
assert_equal 3, discount_code_job.count
|
26
|
+
assert discount_code_job[2].errors.present?
|
27
|
+
end
|
28
|
+
|
29
|
+
def test_create_batch
|
30
|
+
fake 'price_rules/102586120/batch', method: :post, status: 201, body: load_fixture('discount_code_batch')
|
31
|
+
batch = ShopifyAPI::DiscountCodeBatch.new
|
32
|
+
batch.prefix_options[:price_rule_id] = 102586120
|
33
|
+
discount_codes = [{ "code": "SUMMER1" }, { "code": "SUMMER2" }, { "code": "SUMMER3" }]
|
34
|
+
batch.discount_codes = discount_codes
|
35
|
+
batch.save
|
36
|
+
|
37
|
+
expected_body = { discount_codes: discount_codes }.to_json
|
38
|
+
assert_equal expected_body, WebMock.last_request.body
|
39
|
+
end
|
40
|
+
end
|
@@ -0,0 +1,14 @@
|
|
1
|
+
{
|
2
|
+
"discount_code_creation": {
|
3
|
+
"id": 989355119,
|
4
|
+
"price_rule_id": 102586120,
|
5
|
+
"started_at": null,
|
6
|
+
"completed_at": null,
|
7
|
+
"created_at": "2018-07-05T13:04:29-04:00",
|
8
|
+
"updated_at": "2018-07-05T13:04:29-04:00",
|
9
|
+
"status": "queued",
|
10
|
+
"codes_count": 3,
|
11
|
+
"imported_count": 0,
|
12
|
+
"failed_count": 0
|
13
|
+
}
|
14
|
+
}
|
@@ -0,0 +1,21 @@
|
|
1
|
+
{
|
2
|
+
"discount_codes": [
|
3
|
+
{
|
4
|
+
"id": null,
|
5
|
+
"code": "SUMMER1",
|
6
|
+
"errors": {}
|
7
|
+
},
|
8
|
+
{
|
9
|
+
"id": null,
|
10
|
+
"code": "SUMMER2",
|
11
|
+
"errors": {}
|
12
|
+
},
|
13
|
+
{
|
14
|
+
"id": null,
|
15
|
+
"code": "SUMMER2",
|
16
|
+
"errors": {
|
17
|
+
"code": ["must be unique"]
|
18
|
+
}
|
19
|
+
}
|
20
|
+
]
|
21
|
+
}
|
data/test/product_test.rb
CHANGED
@@ -57,4 +57,43 @@ class ProductTest < Test::Unit::TestCase
|
|
57
57
|
|
58
58
|
assert_equal('100.00 - 199.00', @product.price_range)
|
59
59
|
end
|
60
|
+
|
61
|
+
def test_deprecated_variant_inventory_fields_are_included_in_2019_07
|
62
|
+
ShopifyAPI::Base.api_version = '2019-07'
|
63
|
+
variant = @product.variants.first
|
64
|
+
assert variant.as_json.include?('inventory_quantity')
|
65
|
+
end
|
66
|
+
|
67
|
+
def test_deprecated_variant_inventory_fields_are_removed_in_2020_01
|
68
|
+
ShopifyAPI::Base.api_version = '2020-01'
|
69
|
+
variant = @product.variants.first
|
70
|
+
refute variant.as_json.include?('inventory_quantity')
|
71
|
+
end
|
72
|
+
|
73
|
+
def test_deprecated_inventory_fields_are_removed_in_2020_01
|
74
|
+
ShopifyAPI::Base.api_version = '2020-01'
|
75
|
+
refute @product.as_json.include?('total_inventory')
|
76
|
+
end
|
77
|
+
|
78
|
+
def test_setting_product_total_inventory_passes_in_api_before_2019_10
|
79
|
+
ShopifyAPI::Base.api_version = '2019-07'
|
80
|
+
fake("products/632910392", {:body => load_fixture('product')})
|
81
|
+
@product.total_inventory = 8
|
82
|
+
end
|
83
|
+
|
84
|
+
def test_setting_product_total_inventory_fails_in_2019_10_api
|
85
|
+
ShopifyAPI::Base.api_version = '2019-10'
|
86
|
+
fake("products/632910392", {:body => load_fixture('product')})
|
87
|
+
assert_raises(ShopifyAPI::ValidationException) do
|
88
|
+
@product.total_inventory = 8
|
89
|
+
end
|
90
|
+
end
|
91
|
+
|
92
|
+
def test_setting_product_total_inventory_fails_in_the_unstable_api
|
93
|
+
ShopifyAPI::Base.api_version = :unstable
|
94
|
+
fake("products/632910392", {:body => load_fixture('product')})
|
95
|
+
assert_raises(ShopifyAPI::ValidationException) do
|
96
|
+
@product.total_inventory = 8
|
97
|
+
end
|
98
|
+
end
|
60
99
|
end
|
data/test/test_helper.rb
CHANGED
@@ -96,7 +96,7 @@ module Test
|
|
96
96
|
body = options.has_key?(:body) ? options.delete(:body) : load_fixture(endpoint)
|
97
97
|
format = options.delete(:format) || :json
|
98
98
|
method = options.delete(:method) || :get
|
99
|
-
api_version = options.delete(:api_version) || ShopifyAPI::
|
99
|
+
api_version = options.delete(:api_version) || ShopifyAPI::Base.api_version
|
100
100
|
extension = ".#{options.delete(:extension)||'json'}" unless options[:extension]==false
|
101
101
|
status = options.delete(:status) || 200
|
102
102
|
url = if options.has_key?(:url)
|
data/test/variant_test.rb
CHANGED
@@ -43,4 +43,93 @@ class VariantTest < Test::Unit::TestCase
|
|
43
43
|
v = ShopifyAPI::Variant.find(808950810, :params => {:product_id => 632910392})
|
44
44
|
assert v.destroy
|
45
45
|
end
|
46
|
+
|
47
|
+
def test_deprecated_inventory_fields_are_included_in_2019_07
|
48
|
+
ShopifyAPI::Base.api_version = '2019-07'
|
49
|
+
fake "products/632910392/variants/808950810", :method => :get, :body => load_fixture('variant')
|
50
|
+
variant = ShopifyAPI::Variant.find(808950810, :params => {:product_id => 632910392})
|
51
|
+
assert variant.as_json.include?('inventory_quantity')
|
52
|
+
end
|
53
|
+
|
54
|
+
def test_deprecated_inventory_fields_are_removed_in_2020_01
|
55
|
+
ShopifyAPI::Base.api_version = '2020-01'
|
56
|
+
fake "products/632910392/variants/808950810", :method => :get, :body => load_fixture('variant')
|
57
|
+
variant = ShopifyAPI::Variant.find(808950810, :params => {:product_id => 632910392})
|
58
|
+
refute variant.as_json.include?('inventory_quantity')
|
59
|
+
end
|
60
|
+
|
61
|
+
def test_setting_variant_inventory_quantity_adjustment_passes_in_api_before_2019_10
|
62
|
+
ShopifyAPI::Base.api_version = '2019-07'
|
63
|
+
fake "products/632910392/variants/808950810", :method => :get, :body => load_fixture('variant')
|
64
|
+
variant = ShopifyAPI::Variant.find(808950810, :params => {:product_id => 632910392})
|
65
|
+
variant.inventory_quantity_adjustment = 8
|
66
|
+
end
|
67
|
+
|
68
|
+
def test_setting_variant_inventory_quantity_adjustment_fails_in_2019_10_api
|
69
|
+
ShopifyAPI::Base.api_version = '2019-10'
|
70
|
+
fake "products/632910392/variants/808950810", :method => :get, :body => load_fixture('variant')
|
71
|
+
variant = ShopifyAPI::Variant.find(808950810, :params => {:product_id => 632910392})
|
72
|
+
assert_raises(ShopifyAPI::ValidationException) do
|
73
|
+
variant.inventory_quantity_adjustment = 8
|
74
|
+
end
|
75
|
+
end
|
76
|
+
|
77
|
+
def test_setting_variant_inventory_quantity_adjustment_fails_in_the_unstable_api
|
78
|
+
ShopifyAPI::Base.api_version = :unstable
|
79
|
+
fake "products/632910392/variants/808950810", :method => :get, :body => load_fixture('variant')
|
80
|
+
variant = ShopifyAPI::Variant.find(808950810, :params => {:product_id => 632910392})
|
81
|
+
assert_raises(ShopifyAPI::ValidationException) do
|
82
|
+
variant.inventory_quantity_adjustment = 8
|
83
|
+
end
|
84
|
+
end
|
85
|
+
|
86
|
+
def test_setting_variant_inventory_quantity_passes_in_api_before_2019_10
|
87
|
+
ShopifyAPI::Base.api_version = '2019-07'
|
88
|
+
fake "products/632910392/variants/808950810", :method => :get, :body => load_fixture('variant')
|
89
|
+
variant = ShopifyAPI::Variant.find(808950810, :params => {:product_id => 632910392})
|
90
|
+
variant.inventory_quantity = 8
|
91
|
+
end
|
92
|
+
|
93
|
+
def test_setting_variant_inventory_quantity_fails_in_2019_10_api
|
94
|
+
ShopifyAPI::Base.api_version = '2019-10'
|
95
|
+
fake "products/632910392/variants/808950810", :method => :get, :body => load_fixture('variant')
|
96
|
+
variant = ShopifyAPI::Variant.find(808950810, :params => {:product_id => 632910392})
|
97
|
+
assert_raises(ShopifyAPI::ValidationException) do
|
98
|
+
variant.inventory_quantity = 8
|
99
|
+
end
|
100
|
+
end
|
101
|
+
|
102
|
+
def test_setting_variant_inventory_quantity_fails_in_the_unstable_api
|
103
|
+
ShopifyAPI::Base.api_version = :unstable
|
104
|
+
fake "products/632910392/variants/808950810", :method => :get, :body => load_fixture('variant')
|
105
|
+
variant = ShopifyAPI::Variant.find(808950810, :params => {:product_id => 632910392})
|
106
|
+
assert_raises(ShopifyAPI::ValidationException) do
|
107
|
+
variant.inventory_quantity = 8
|
108
|
+
end
|
109
|
+
end
|
110
|
+
|
111
|
+
def test_setting_variant_old_inventory_quantity_passes_in_api_before_2019_10
|
112
|
+
ShopifyAPI::Base.api_version = '2019-07'
|
113
|
+
fake "products/632910392/variants/808950810", :method => :get, :body => load_fixture('variant')
|
114
|
+
variant = ShopifyAPI::Variant.find(808950810, :params => {:product_id => 632910392})
|
115
|
+
variant.old_inventory_quantity = 8
|
116
|
+
end
|
117
|
+
|
118
|
+
def test_setting_variant_old_inventory_quantity_fails_in_2019_10_api
|
119
|
+
ShopifyAPI::Base.api_version = '2019-10'
|
120
|
+
fake "products/632910392/variants/808950810", :method => :get, :body => load_fixture('variant')
|
121
|
+
variant = ShopifyAPI::Variant.find(808950810, :params => {:product_id => 632910392})
|
122
|
+
assert_raises(ShopifyAPI::ValidationException) do
|
123
|
+
variant.old_inventory_quantity = 8
|
124
|
+
end
|
125
|
+
end
|
126
|
+
|
127
|
+
def test_setting_variant_old_inventory_quantity_fails_in_the_unstable_api
|
128
|
+
ShopifyAPI::Base.api_version = :unstable
|
129
|
+
fake "products/632910392/variants/808950810", :method => :get, :body => load_fixture('variant')
|
130
|
+
variant = ShopifyAPI::Variant.find(808950810, :params => {:product_id => 632910392})
|
131
|
+
assert_raises(ShopifyAPI::ValidationException) do
|
132
|
+
variant.old_inventory_quantity = 8
|
133
|
+
end
|
134
|
+
end
|
46
135
|
end
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: shopify_api
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 9.0.
|
4
|
+
version: 9.0.3
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Shopify
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2020-03-
|
11
|
+
date: 2020-03-20 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: activeresource
|
@@ -255,6 +255,7 @@ files:
|
|
255
255
|
- lib/shopify_api/resources/customer_invite.rb
|
256
256
|
- lib/shopify_api/resources/customer_saved_search.rb
|
257
257
|
- lib/shopify_api/resources/discount_code.rb
|
258
|
+
- lib/shopify_api/resources/discount_code_batch.rb
|
258
259
|
- lib/shopify_api/resources/draft_order.rb
|
259
260
|
- lib/shopify_api/resources/draft_order_invoice.rb
|
260
261
|
- lib/shopify_api/resources/event.rb
|
@@ -343,6 +344,7 @@ files:
|
|
343
344
|
- test/customer_saved_search_test.rb
|
344
345
|
- test/customer_test.rb
|
345
346
|
- test/detailed_log_subscriber_test.rb
|
347
|
+
- test/discount_code_batch_test.rb
|
346
348
|
- test/discount_code_test.rb
|
347
349
|
- test/draft_order_test.rb
|
348
350
|
- test/fixtures/abandoned_checkout.json
|
@@ -385,6 +387,8 @@ files:
|
|
385
387
|
- test/fixtures/customers_account_activation_url.json
|
386
388
|
- test/fixtures/customers_search.json
|
387
389
|
- test/fixtures/discount_code.json
|
390
|
+
- test/fixtures/discount_code_batch.json
|
391
|
+
- test/fixtures/discount_code_batch_discount_codes.json
|
388
392
|
- test/fixtures/discount_codes.json
|
389
393
|
- test/fixtures/draft_order.json
|
390
394
|
- test/fixtures/draft_order_completed.json
|
@@ -515,7 +519,8 @@ files:
|
|
515
519
|
homepage: http://www.shopify.com/partners/apps
|
516
520
|
licenses:
|
517
521
|
- MIT
|
518
|
-
metadata:
|
522
|
+
metadata:
|
523
|
+
allowed_push_host: https://rubygems.org
|
519
524
|
post_install_message:
|
520
525
|
rdoc_options:
|
521
526
|
- "--charset=UTF-8"
|