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.
Files changed (45) hide show
  1. checksums.yaml +4 -4
  2. data/.rubocop-https---shopify-github-io-ruby-style-guide-rubocop-yml +1027 -0
  3. data/CHANGELOG.md +7 -0
  4. data/README.md +30 -0
  5. data/Rakefile +1 -1
  6. data/lib/shopify_api.rb +2 -1
  7. data/lib/shopify_api/api_version.rb +17 -0
  8. data/lib/shopify_api/defined_versions.rb +1 -0
  9. data/lib/shopify_api/paginated_collection.rb +57 -0
  10. data/lib/shopify_api/pagination_link_headers.rb +33 -0
  11. data/lib/shopify_api/resources.rb +2 -1
  12. data/lib/shopify_api/resources/array_base.rb +13 -0
  13. data/lib/shopify_api/resources/base.rb +24 -21
  14. data/lib/shopify_api/resources/collect.rb +1 -0
  15. data/lib/shopify_api/resources/collection_listing.rb +10 -1
  16. data/lib/shopify_api/resources/customer_saved_search.rb +2 -0
  17. data/lib/shopify_api/resources/event.rb +1 -0
  18. data/lib/shopify_api/resources/metafield.rb +1 -0
  19. data/lib/shopify_api/resources/product.rb +2 -0
  20. data/lib/shopify_api/resources/product_listing.rb +8 -1
  21. data/lib/shopify_api/version.rb +1 -1
  22. data/shopify_api.gemspec +1 -1
  23. data/test/api_version_test.rb +14 -0
  24. data/test/base_test.rb +12 -6
  25. data/test/blog_test.rb +1 -1
  26. data/test/collection_listing_test.rb +38 -0
  27. data/test/collection_publication_test.rb +1 -1
  28. data/test/customer_test.rb +2 -2
  29. data/test/discount_code_test.rb +2 -2
  30. data/test/draft_order_test.rb +4 -4
  31. data/test/fixtures/collection_listing_product_ids2.json +1 -0
  32. data/test/fixtures/product_listing_product_ids.json +1 -1
  33. data/test/fixtures/product_listing_product_ids2.json +1 -0
  34. data/test/lib/webmock_extensions/last_request.rb +16 -0
  35. data/test/metafield_test.rb +1 -1
  36. data/test/pagination_test.rb +229 -0
  37. data/test/price_rule_test.rb +1 -1
  38. data/test/product_listing_test.rb +59 -2
  39. data/test/product_publication_test.rb +1 -1
  40. data/test/product_test.rb +1 -1
  41. data/test/recurring_application_charge_test.rb +3 -4
  42. data/test/shop_test.rb +1 -1
  43. data/test/tax_service_test.rb +2 -1
  44. data/test/test_helper.rb +83 -83
  45. metadata +12 -5
@@ -35,6 +35,6 @@ class ProductPublicationTest < Test::Unit::TestCase
35
35
  },
36
36
  }.to_json
37
37
 
38
- assert_equal expected_body, FakeWeb.last_request.body
38
+ assert_equal expected_body, WebMock.last_request.body
39
39
  end
40
40
  end
@@ -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(FakeWeb.last_request.body)
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
- assert_equal nil, ShopifyAPI::RecurringApplicationCharge.current
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
- assert_equal(nil, ShopifyAPI::RecurringApplicationCharge.all)
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
@@ -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(FakeWeb.last_request.body)
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
@@ -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"}}', FakeWeb.last_request.body
6
+ assert_equal '{"tax_service":{"name":"My Tax Service","url":"https://mytaxservice.com"}}', WebMock.last_request.body
7
+
7
8
  end
8
9
  end
@@ -1,6 +1,7 @@
1
1
  require 'rubygems'
2
2
  require 'minitest/autorun'
3
- require 'fakeweb'
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
- FakeWeb.allow_net_connect = false
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
- end
17
- end
18
-
19
- class Test::Unit::TestCase < Minitest::Unit::TestCase
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
- def setup
33
- ActiveResource::Base.format = :json
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
- ShopifyAPI::ApiVersion.define_version(ShopifyAPI::ApiVersion::Release.new('2019-01'))
26
+ def self.context(string)
27
+ yield
28
+ end
43
29
 
44
- ShopifyAPI::Base.clear_session
45
- session = ShopifyAPI::Session.new(
46
- domain: "https://this-is-my-test-shop.myshopify.com",
47
- token: "token_test_helper",
48
- api_version: '2019-01',
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
- ShopifyAPI::Base.activate_session(session)
52
- end
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
- def teardown
55
- FakeWeb.clean_registry
58
+ ShopifyAPI::ApiVersion.clear_defined_versions
59
+ ShopifyAPI::ApiVersion.define_known_versions
60
+ end
56
61
 
57
- ShopifyAPI::Base.clear_session
58
- ShopifyAPI::Base.site = nil
59
- ShopifyAPI::Base.password = nil
60
- ShopifyAPI::Base.user = nil
62
+ # Custom Assertions
63
+ def assert_not(expression)
64
+ refute expression, "Expected <#{expression}> to be false!"
65
+ end
61
66
 
62
- ShopifyAPI::ApiVersion.clear_defined_versions
63
- ShopifyAPI::ApiVersion.define_known_versions
64
- end
67
+ def assert_nothing_raised
68
+ yield
69
+ end
65
70
 
66
- # Custom Assertions
67
- def assert_not(expression)
68
- refute expression, "Expected <#{expression}> to be false!"
69
- end
71
+ def assert_not_includes(array, value)
72
+ refute array.include?(value)
73
+ end
70
74
 
71
- def assert_nothing_raised
72
- yield
73
- end
75
+ def assert_includes(array, value)
76
+ assert array.include?(value)
77
+ end
74
78
 
75
- def assert_not_includes(array, value)
76
- refute array.include?(value)
77
- end
79
+ def load_fixture(name, format=:json)
80
+ File.read(File.dirname(__FILE__) + "/fixtures/#{name}.#{format}")
81
+ end
78
82
 
79
- def assert_includes(array, value)
80
- assert array.include?(value)
81
- end
83
+ def assert_request_body(expected)
84
+ assert_equal expected, WebMock.last_request.body
85
+ end
82
86
 
83
- def load_fixture(name, format=:json)
84
- File.read(File.dirname(__FILE__) + "/fixtures/#{name}.#{format}")
85
- end
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
- def assert_request_body(expected)
88
- assert_equal expected, FakeWeb.last_request.body
89
- end
105
+ def ar_version_before?(version_string)
106
+ Gem::Version.new(ActiveResource::VERSION::STRING) < Gem::Version.new(version_string)
107
+ end
90
108
 
91
- def fake(endpoint, options={})
92
- body = options.has_key?(:body) ? options.delete(:body) : load_fixture(endpoint)
93
- format = options.delete(:format) || :json
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.2
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-07-02 00:00:00.000000000 Z
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: fakeweb
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
- rubyforge_project:
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