shopify_api 7.0.2 → 7.1.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/.rubocop-https---shopify-github-io-ruby-style-guide-rubocop-yml +1027 -0
- data/CHANGELOG.md +7 -0
- data/README.md +30 -0
- data/Rakefile +1 -1
- data/lib/shopify_api.rb +2 -1
- data/lib/shopify_api/api_version.rb +17 -0
- data/lib/shopify_api/defined_versions.rb +1 -0
- data/lib/shopify_api/paginated_collection.rb +57 -0
- data/lib/shopify_api/pagination_link_headers.rb +33 -0
- data/lib/shopify_api/resources.rb +2 -1
- data/lib/shopify_api/resources/array_base.rb +13 -0
- data/lib/shopify_api/resources/base.rb +24 -21
- data/lib/shopify_api/resources/collect.rb +1 -0
- data/lib/shopify_api/resources/collection_listing.rb +10 -1
- data/lib/shopify_api/resources/customer_saved_search.rb +2 -0
- data/lib/shopify_api/resources/event.rb +1 -0
- data/lib/shopify_api/resources/metafield.rb +1 -0
- data/lib/shopify_api/resources/product.rb +2 -0
- data/lib/shopify_api/resources/product_listing.rb +8 -1
- data/lib/shopify_api/version.rb +1 -1
- data/shopify_api.gemspec +1 -1
- data/test/api_version_test.rb +14 -0
- data/test/base_test.rb +12 -6
- data/test/blog_test.rb +1 -1
- data/test/collection_listing_test.rb +38 -0
- data/test/collection_publication_test.rb +1 -1
- data/test/customer_test.rb +2 -2
- data/test/discount_code_test.rb +2 -2
- data/test/draft_order_test.rb +4 -4
- data/test/fixtures/collection_listing_product_ids2.json +1 -0
- data/test/fixtures/product_listing_product_ids.json +1 -1
- data/test/fixtures/product_listing_product_ids2.json +1 -0
- data/test/lib/webmock_extensions/last_request.rb +16 -0
- data/test/metafield_test.rb +1 -1
- data/test/pagination_test.rb +229 -0
- data/test/price_rule_test.rb +1 -1
- data/test/product_listing_test.rb +59 -2
- data/test/product_publication_test.rb +1 -1
- data/test/product_test.rb +1 -1
- data/test/recurring_application_charge_test.rb +3 -4
- data/test/shop_test.rb +1 -1
- data/test/tax_service_test.rb +2 -1
- data/test/test_helper.rb +83 -83
- metadata +12 -5
data/test/product_test.rb
CHANGED
@@ -12,7 +12,7 @@ class ProductTest < Test::Unit::TestCase
|
|
12
12
|
fake "products/632910392/metafields", :method => :post, :status => 201, :body => load_fixture('metafield')
|
13
13
|
|
14
14
|
field = @product.add_metafield(ShopifyAPI::Metafield.new(:namespace => "contact", :key => "email", :value => "123@example.com", :value_type => "string"))
|
15
|
-
assert_equal ActiveSupport::JSON.decode('{"metafield":{"namespace":"contact","key":"email","value":"123@example.com","value_type":"string"}}'), ActiveSupport::JSON.decode(
|
15
|
+
assert_equal ActiveSupport::JSON.decode('{"metafield":{"namespace":"contact","key":"email","value":"123@example.com","value_type":"string"}}'), ActiveSupport::JSON.decode(WebMock.last_request.body)
|
16
16
|
assert !field.new_record?
|
17
17
|
assert_equal "contact", field.namespace
|
18
18
|
assert_equal "email", field.key
|
@@ -129,15 +129,14 @@ class RecurringApplicationChargeTest < Test::Unit::TestCase
|
|
129
129
|
fake "recurring_application_charges", body: {recurring_application_charges: []}.to_json
|
130
130
|
|
131
131
|
assert_equal 0, ShopifyAPI::RecurringApplicationCharge.all.count
|
132
|
-
|
132
|
+
assert_nil ShopifyAPI::RecurringApplicationCharge.current
|
133
133
|
assert_equal [], ShopifyAPI::RecurringApplicationCharge.pending
|
134
134
|
end
|
135
135
|
|
136
136
|
def test_recurring_application_charge_not_found_error
|
137
137
|
fake "recurring_application_charges", body: '{"errors":"Not Found"}', status: 404
|
138
|
-
|
139
|
-
|
140
|
-
assert_equal(nil, ShopifyAPI::RecurringApplicationCharge.current)
|
138
|
+
assert_nil ShopifyAPI::RecurringApplicationCharge.all
|
139
|
+
assert_nil ShopifyAPI::RecurringApplicationCharge.current
|
141
140
|
assert_equal([], ShopifyAPI::RecurringApplicationCharge.pending)
|
142
141
|
end
|
143
142
|
end
|
data/test/shop_test.rb
CHANGED
@@ -50,7 +50,7 @@ class ShopTest < Test::Unit::TestCase
|
|
50
50
|
fake "metafields", :method => :post, :status => 201, :body =>load_fixture('metafield')
|
51
51
|
|
52
52
|
field = @shop.add_metafield(ShopifyAPI::Metafield.new(:namespace => "contact", :key => "email", :value => "123@example.com", :value_type => "string"))
|
53
|
-
assert_equal ActiveSupport::JSON.decode('{"metafield":{"namespace":"contact","key":"email","value":"123@example.com","value_type":"string"}}'), ActiveSupport::JSON.decode(
|
53
|
+
assert_equal ActiveSupport::JSON.decode('{"metafield":{"namespace":"contact","key":"email","value":"123@example.com","value_type":"string"}}'), ActiveSupport::JSON.decode(WebMock.last_request.body)
|
54
54
|
assert !field.new_record?
|
55
55
|
assert_equal "contact", field.namespace
|
56
56
|
assert_equal "email", field.key
|
data/test/tax_service_test.rb
CHANGED
@@ -3,6 +3,7 @@ class TaxServiceTest < Test::Unit::TestCase
|
|
3
3
|
test "tax service creation" do
|
4
4
|
fake "tax_services", :method => :post, :status => 202, :body => load_fixture('tax_service')
|
5
5
|
tax_service = ShopifyAPI::TaxService.create(:name => "My Tax Service", :url => "https://mytaxservice.com")
|
6
|
-
assert_equal '{"tax_service":{"name":"My Tax Service","url":"https://mytaxservice.com"}}',
|
6
|
+
assert_equal '{"tax_service":{"name":"My Tax Service","url":"https://mytaxservice.com"}}', WebMock.last_request.body
|
7
|
+
|
7
8
|
end
|
8
9
|
end
|
data/test/test_helper.rb
CHANGED
@@ -1,6 +1,7 @@
|
|
1
1
|
require 'rubygems'
|
2
2
|
require 'minitest/autorun'
|
3
|
-
require '
|
3
|
+
require 'webmock/minitest'
|
4
|
+
require_relative 'lib/webmock_extensions/last_request'
|
4
5
|
require 'mocha/setup'
|
5
6
|
require 'pry'
|
6
7
|
|
@@ -8,107 +9,106 @@ $LOAD_PATH.unshift(File.dirname(__FILE__))
|
|
8
9
|
$LOAD_PATH.unshift(File.join(File.dirname(__FILE__), '..', 'lib'))
|
9
10
|
require 'shopify_api'
|
10
11
|
|
11
|
-
|
12
|
+
WebMock.disable_net_connect!
|
12
13
|
|
13
14
|
# setup ShopifyAPI with fake api_key and secret
|
14
15
|
module Test
|
15
16
|
module Unit
|
16
|
-
|
17
|
-
|
18
|
-
|
19
|
-
|
20
|
-
def self.test(string, &block)
|
21
|
-
define_method("test_#{string}", &block)
|
22
|
-
end
|
23
|
-
|
24
|
-
def self.should(string, &block)
|
25
|
-
self.test("should_#{string}", &block)
|
26
|
-
end
|
27
|
-
|
28
|
-
def self.context(string)
|
29
|
-
yield
|
30
|
-
end
|
17
|
+
class TestCase < Minitest::Test
|
18
|
+
def self.test(string, &block)
|
19
|
+
define_method("test_#{string}", &block)
|
20
|
+
end
|
31
21
|
|
32
|
-
|
33
|
-
|
34
|
-
ShopifyAPI.constants.each do |const|
|
35
|
-
begin
|
36
|
-
const = mod.const_get(const)
|
37
|
-
const.format = :json if const.respond_to?(:format=)
|
38
|
-
rescue NameError
|
22
|
+
def self.should(string, &block)
|
23
|
+
self.test("should_#{string}", &block)
|
39
24
|
end
|
40
|
-
end
|
41
25
|
|
42
|
-
|
26
|
+
def self.context(string)
|
27
|
+
yield
|
28
|
+
end
|
43
29
|
|
44
|
-
|
45
|
-
|
46
|
-
|
47
|
-
|
48
|
-
|
49
|
-
|
30
|
+
def setup
|
31
|
+
ActiveResource::Base.format = :json
|
32
|
+
ShopifyAPI.constants.each do |const|
|
33
|
+
begin
|
34
|
+
const = mod.const_get(const)
|
35
|
+
const.format = :json if const.respond_to?(:format=)
|
36
|
+
rescue NameError
|
37
|
+
end
|
38
|
+
end
|
39
|
+
|
40
|
+
ShopifyAPI::ApiVersion.define_version(ShopifyAPI::ApiVersion::Release.new('2019-01'))
|
41
|
+
|
42
|
+
ShopifyAPI::Base.clear_session
|
43
|
+
session = ShopifyAPI::Session.new(
|
44
|
+
domain: "https://this-is-my-test-shop.myshopify.com",
|
45
|
+
token: "token_test_helper",
|
46
|
+
api_version: '2019-01',
|
47
|
+
)
|
48
|
+
|
49
|
+
ShopifyAPI::Base.activate_session(session)
|
50
|
+
end
|
50
51
|
|
51
|
-
|
52
|
-
|
52
|
+
def teardown
|
53
|
+
ShopifyAPI::Base.clear_session
|
54
|
+
ShopifyAPI::Base.site = nil
|
55
|
+
ShopifyAPI::Base.password = nil
|
56
|
+
ShopifyAPI::Base.user = nil
|
53
57
|
|
54
|
-
|
55
|
-
|
58
|
+
ShopifyAPI::ApiVersion.clear_defined_versions
|
59
|
+
ShopifyAPI::ApiVersion.define_known_versions
|
60
|
+
end
|
56
61
|
|
57
|
-
|
58
|
-
|
59
|
-
|
60
|
-
|
62
|
+
# Custom Assertions
|
63
|
+
def assert_not(expression)
|
64
|
+
refute expression, "Expected <#{expression}> to be false!"
|
65
|
+
end
|
61
66
|
|
62
|
-
|
63
|
-
|
64
|
-
|
67
|
+
def assert_nothing_raised
|
68
|
+
yield
|
69
|
+
end
|
65
70
|
|
66
|
-
|
67
|
-
|
68
|
-
|
69
|
-
end
|
71
|
+
def assert_not_includes(array, value)
|
72
|
+
refute array.include?(value)
|
73
|
+
end
|
70
74
|
|
71
|
-
|
72
|
-
|
73
|
-
|
75
|
+
def assert_includes(array, value)
|
76
|
+
assert array.include?(value)
|
77
|
+
end
|
74
78
|
|
75
|
-
|
76
|
-
|
77
|
-
|
79
|
+
def load_fixture(name, format=:json)
|
80
|
+
File.read(File.dirname(__FILE__) + "/fixtures/#{name}.#{format}")
|
81
|
+
end
|
78
82
|
|
79
|
-
|
80
|
-
|
81
|
-
|
83
|
+
def assert_request_body(expected)
|
84
|
+
assert_equal expected, WebMock.last_request.body
|
85
|
+
end
|
82
86
|
|
83
|
-
|
84
|
-
|
85
|
-
|
87
|
+
def fake(endpoint, options={})
|
88
|
+
body = options.has_key?(:body) ? options.delete(:body) : load_fixture(endpoint)
|
89
|
+
format = options.delete(:format) || :json
|
90
|
+
method = options.delete(:method) || :get
|
91
|
+
api_version = options.delete(:api_version) || ShopifyAPI::ApiVersion.coerce_to_version('2019-01')
|
92
|
+
extension = ".#{options.delete(:extension)||'json'}" unless options[:extension]==false
|
93
|
+
status = options.delete(:status) || 200
|
94
|
+
url = if options.has_key?(:url)
|
95
|
+
options[:url]
|
96
|
+
else
|
97
|
+
"https://this-is-my-test-shop.myshopify.com#{api_version.construct_api_path("#{endpoint}#{extension}")}"
|
98
|
+
end
|
99
|
+
|
100
|
+
WebMock.stub_request(method, url).to_return(
|
101
|
+
body: body, status: status, headers: { content_type: "text/#{format}", content_length: 1 }.merge(options)
|
102
|
+
)
|
103
|
+
end
|
86
104
|
|
87
|
-
|
88
|
-
|
89
|
-
|
105
|
+
def ar_version_before?(version_string)
|
106
|
+
Gem::Version.new(ActiveResource::VERSION::STRING) < Gem::Version.new(version_string)
|
107
|
+
end
|
90
108
|
|
91
|
-
|
92
|
-
|
93
|
-
|
94
|
-
method = options.delete(:method) || :get
|
95
|
-
api_version = options.delete(:api_version) || ShopifyAPI::ApiVersion.coerce_to_version('2019-01')
|
96
|
-
extension = ".#{options.delete(:extension)||'json'}" unless options[:extension]==false
|
97
|
-
|
98
|
-
url = if options.has_key?(:url)
|
99
|
-
options[:url]
|
100
|
-
else
|
101
|
-
"https://this-is-my-test-shop.myshopify.com#{api_version.construct_api_path("#{endpoint}#{extension}")}"
|
109
|
+
def ar_version_after?(version_string)
|
110
|
+
Gem::Version.new(version_string) < Gem::Version.new(ActiveResource::VERSION::STRING)
|
111
|
+
end
|
102
112
|
end
|
103
|
-
|
104
|
-
FakeWeb.register_uri(method, url, {:body => body, :status => 200, :content_type => "text/#{format}", :content_length => 1}.merge(options))
|
105
|
-
end
|
106
|
-
|
107
|
-
def ar_version_before?(version_string)
|
108
|
-
Gem::Version.new(ActiveResource::VERSION::STRING) < Gem::Version.new(version_string)
|
109
|
-
end
|
110
|
-
|
111
|
-
def ar_version_after?(version_string)
|
112
|
-
Gem::Version.new(version_string) < Gem::Version.new(ActiveResource::VERSION::STRING)
|
113
113
|
end
|
114
114
|
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: 7.0
|
4
|
+
version: 7.1.0
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Shopify
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2019-
|
11
|
+
date: 2019-08-29 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: activeresource
|
@@ -73,7 +73,7 @@ dependencies:
|
|
73
73
|
- !ruby/object:Gem::Version
|
74
74
|
version: 0.9.8
|
75
75
|
- !ruby/object:Gem::Dependency
|
76
|
-
name:
|
76
|
+
name: webmock
|
77
77
|
requirement: !ruby/object:Gem::Requirement
|
78
78
|
requirements:
|
79
79
|
- - ">="
|
@@ -186,6 +186,7 @@ files:
|
|
186
186
|
- ".github/CODEOWNERS"
|
187
187
|
- ".github/probots.yml"
|
188
188
|
- ".gitignore"
|
189
|
+
- ".rubocop-https---shopify-github-io-ruby-style-guide-rubocop-yml"
|
189
190
|
- ".rubocop.yml"
|
190
191
|
- ".travis.yml"
|
191
192
|
- CHANGELOG.md
|
@@ -214,6 +215,8 @@ files:
|
|
214
215
|
- lib/shopify_api/events.rb
|
215
216
|
- lib/shopify_api/limits.rb
|
216
217
|
- lib/shopify_api/metafields.rb
|
218
|
+
- lib/shopify_api/paginated_collection.rb
|
219
|
+
- lib/shopify_api/pagination_link_headers.rb
|
217
220
|
- lib/shopify_api/resources.rb
|
218
221
|
- lib/shopify_api/resources/abandoned_checkout.rb
|
219
222
|
- lib/shopify_api/resources/access_scope.rb
|
@@ -223,6 +226,7 @@ files:
|
|
223
226
|
- lib/shopify_api/resources/api_permission.rb
|
224
227
|
- lib/shopify_api/resources/application_charge.rb
|
225
228
|
- lib/shopify_api/resources/application_credit.rb
|
229
|
+
- lib/shopify_api/resources/array_base.rb
|
226
230
|
- lib/shopify_api/resources/article.rb
|
227
231
|
- lib/shopify_api/resources/asset.rb
|
228
232
|
- lib/shopify_api/resources/base.rb
|
@@ -351,6 +355,7 @@ files:
|
|
351
355
|
- test/fixtures/collect.json
|
352
356
|
- test/fixtures/collection_listing.json
|
353
357
|
- test/fixtures/collection_listing_product_ids.json
|
358
|
+
- test/fixtures/collection_listing_product_ids2.json
|
354
359
|
- test/fixtures/collection_listings.json
|
355
360
|
- test/fixtures/collection_publication.json
|
356
361
|
- test/fixtures/collection_publications.json
|
@@ -401,6 +406,7 @@ files:
|
|
401
406
|
- test/fixtures/product.json
|
402
407
|
- test/fixtures/product_listing.json
|
403
408
|
- test/fixtures/product_listing_product_ids.json
|
409
|
+
- test/fixtures/product_listing_product_ids2.json
|
404
410
|
- test/fixtures/product_listings.json
|
405
411
|
- test/fixtures/product_publication.json
|
406
412
|
- test/fixtures/product_publications.json
|
@@ -440,12 +446,14 @@ files:
|
|
440
446
|
- test/gift_card_test.rb
|
441
447
|
- test/image_test.rb
|
442
448
|
- test/inventory_level_test.rb
|
449
|
+
- test/lib/webmock_extensions/last_request.rb
|
443
450
|
- test/limits_test.rb
|
444
451
|
- test/location_test.rb
|
445
452
|
- test/marketing_event_test.rb
|
446
453
|
- test/metafield_test.rb
|
447
454
|
- test/order_risk_test.rb
|
448
455
|
- test/order_test.rb
|
456
|
+
- test/pagination_test.rb
|
449
457
|
- test/payment_test.rb
|
450
458
|
- test/policy_test.rb
|
451
459
|
- test/price_rule_test.rb
|
@@ -493,8 +501,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
493
501
|
- !ruby/object:Gem::Version
|
494
502
|
version: '0'
|
495
503
|
requirements: []
|
496
|
-
|
497
|
-
rubygems_version: 2.7.6
|
504
|
+
rubygems_version: 3.0.3
|
498
505
|
signing_key:
|
499
506
|
specification_version: 4
|
500
507
|
summary: ShopifyAPI is a lightweight gem for accessing the Shopify admin REST web
|