shopify_api 9.2.0 → 9.3.0

Sign up to get free protection for your applications and to get access to all the features.
Files changed (190) hide show
  1. checksums.yaml +4 -4
  2. data/.github/ISSUE_TEMPLATE.md +36 -0
  3. data/.github/workflows/build.yml +41 -0
  4. data/.gitignore +0 -1
  5. data/.rubocop.yml +23 -3
  6. data/.rubocop_todo.yml +75 -0
  7. data/CHANGELOG.md +15 -0
  8. data/Gemfile +1 -0
  9. data/Gemfile.lock +151 -0
  10. data/Gemfile_ar51 +1 -1
  11. data/README.md +40 -30
  12. data/RELEASING +10 -6
  13. data/Rakefile +10 -6
  14. data/docs/graphql.md +1 -1
  15. data/docs/index.md +1 -1
  16. data/lib/active_resource/connection_ext.rb +1 -0
  17. data/lib/active_resource/detailed_log_subscriber.rb +6 -7
  18. data/lib/active_resource/json_errors.rb +8 -2
  19. data/lib/shopify_api.rb +8 -1
  20. data/lib/shopify_api/api_access.rb +57 -0
  21. data/lib/shopify_api/api_version.rb +6 -5
  22. data/lib/shopify_api/connection.rb +1 -0
  23. data/lib/shopify_api/countable.rb +3 -2
  24. data/lib/shopify_api/disable_prefix_check.rb +2 -2
  25. data/lib/shopify_api/events.rb +2 -1
  26. data/lib/shopify_api/graphql.rb +8 -6
  27. data/lib/shopify_api/limits.rb +3 -2
  28. data/lib/shopify_api/message_enricher.rb +11 -9
  29. data/lib/shopify_api/meta.rb +0 -1
  30. data/lib/shopify_api/metafields.rb +5 -4
  31. data/lib/shopify_api/pagination_link_headers.rb +4 -3
  32. data/lib/shopify_api/resources.rb +1 -0
  33. data/lib/shopify_api/resources/access_scope.rb +1 -1
  34. data/lib/shopify_api/resources/access_token.rb +1 -0
  35. data/lib/shopify_api/resources/address.rb +1 -0
  36. data/lib/shopify_api/resources/announcement.rb +2 -1
  37. data/lib/shopify_api/resources/application_charge.rb +1 -0
  38. data/lib/shopify_api/resources/application_credit.rb +1 -0
  39. data/lib/shopify_api/resources/article.rb +3 -2
  40. data/lib/shopify_api/resources/asset.rb +6 -5
  41. data/lib/shopify_api/resources/assigned_fulfillment_order.rb +1 -1
  42. data/lib/shopify_api/resources/base.rb +11 -6
  43. data/lib/shopify_api/resources/billing_address.rb +1 -0
  44. data/lib/shopify_api/resources/blog.rb +2 -1
  45. data/lib/shopify_api/resources/carrier_service.rb +1 -0
  46. data/lib/shopify_api/resources/cart.rb +2 -1
  47. data/lib/shopify_api/resources/collect.rb +1 -0
  48. data/lib/shopify_api/resources/collection_listing.rb +1 -0
  49. data/lib/shopify_api/resources/comment.rb +20 -5
  50. data/lib/shopify_api/resources/country.rb +1 -0
  51. data/lib/shopify_api/resources/custom_collection.rb +4 -3
  52. data/lib/shopify_api/resources/customer.rb +2 -1
  53. data/lib/shopify_api/resources/customer_group.rb +1 -0
  54. data/lib/shopify_api/resources/customer_invite.rb +1 -0
  55. data/lib/shopify_api/resources/customer_saved_search.rb +2 -1
  56. data/lib/shopify_api/resources/discount_code.rb +1 -0
  57. data/lib/shopify_api/resources/discount_code_batch.rb +4 -2
  58. data/lib/shopify_api/resources/draft_order.rb +1 -0
  59. data/lib/shopify_api/resources/draft_order_invoice.rb +1 -0
  60. data/lib/shopify_api/resources/event.rb +1 -0
  61. data/lib/shopify_api/resources/fulfillment.rb +12 -3
  62. data/lib/shopify_api/resources/fulfillment_event.rb +1 -0
  63. data/lib/shopify_api/resources/fulfillment_order.rb +30 -16
  64. data/lib/shopify_api/resources/fulfillment_order_locations_for_move.rb +1 -0
  65. data/lib/shopify_api/resources/fulfillment_request.rb +1 -0
  66. data/lib/shopify_api/resources/fulfillment_service.rb +1 -0
  67. data/lib/shopify_api/resources/fulfillment_v2.rb +3 -2
  68. data/lib/shopify_api/resources/gift_card.rb +1 -0
  69. data/lib/shopify_api/resources/image.rb +2 -1
  70. data/lib/shopify_api/resources/inventory_level.rb +2 -3
  71. data/lib/shopify_api/resources/line_item.rb +4 -3
  72. data/lib/shopify_api/resources/location.rb +1 -1
  73. data/lib/shopify_api/resources/marketing_event.rb +1 -0
  74. data/lib/shopify_api/resources/metafield.rb +1 -0
  75. data/lib/shopify_api/resources/note_attribute.rb +1 -0
  76. data/lib/shopify_api/resources/option.rb +1 -0
  77. data/lib/shopify_api/resources/order.rb +2 -1
  78. data/lib/shopify_api/resources/order_risk.rb +1 -0
  79. data/lib/shopify_api/resources/page.rb +1 -0
  80. data/lib/shopify_api/resources/payment_details.rb +1 -0
  81. data/lib/shopify_api/resources/policy.rb +1 -0
  82. data/lib/shopify_api/resources/price_rule.rb +1 -1
  83. data/lib/shopify_api/resources/product.rb +14 -11
  84. data/lib/shopify_api/resources/product_listing.rb +1 -0
  85. data/lib/shopify_api/resources/province.rb +1 -0
  86. data/lib/shopify_api/resources/receipt.rb +1 -0
  87. data/lib/shopify_api/resources/recurring_application_charge.rb +4 -1
  88. data/lib/shopify_api/resources/redirect.rb +1 -0
  89. data/lib/shopify_api/resources/refund.rb +2 -1
  90. data/lib/shopify_api/resources/report.rb +1 -0
  91. data/lib/shopify_api/resources/resource_feedback.rb +1 -1
  92. data/lib/shopify_api/resources/rule.rb +1 -0
  93. data/lib/shopify_api/resources/script_tag.rb +1 -0
  94. data/lib/shopify_api/resources/shipping_address.rb +1 -0
  95. data/lib/shopify_api/resources/shipping_line.rb +1 -0
  96. data/lib/shopify_api/resources/shipping_zone.rb +1 -0
  97. data/lib/shopify_api/resources/shop.rb +2 -1
  98. data/lib/shopify_api/resources/smart_collection.rb +2 -2
  99. data/lib/shopify_api/resources/storefront_access_token.rb +1 -0
  100. data/lib/shopify_api/resources/tax_line.rb +1 -0
  101. data/lib/shopify_api/resources/tax_service.rb +1 -0
  102. data/lib/shopify_api/resources/theme.rb +1 -0
  103. data/lib/shopify_api/resources/transaction.rb +1 -0
  104. data/lib/shopify_api/resources/usage_charge.rb +1 -0
  105. data/lib/shopify_api/resources/user.rb +1 -0
  106. data/lib/shopify_api/resources/variant.rb +16 -18
  107. data/lib/shopify_api/resources/webhook.rb +1 -0
  108. data/lib/shopify_api/session.rb +20 -12
  109. data/lib/shopify_api/version.rb +2 -1
  110. data/lib/verify_docs.rb +1 -0
  111. data/service.yml +1 -1
  112. data/shopify_api.gemspec +10 -4
  113. data/test/access_token_test.rb +6 -5
  114. data/test/active_resource/json_errors_test.rb +6 -6
  115. data/test/api_access_test.rb +153 -0
  116. data/test/api_version_test.rb +3 -3
  117. data/test/application_charge_test.rb +30 -27
  118. data/test/application_credit_test.rb +10 -9
  119. data/test/article_test.rb +34 -35
  120. data/test/asset_test.rb +14 -6
  121. data/test/assigned_fulfillment_order_test.rb +5 -4
  122. data/test/base_test.rb +55 -56
  123. data/test/blog_test.rb +4 -3
  124. data/test/carrier_service_test.rb +7 -6
  125. data/test/cart_test.rb +2 -1
  126. data/test/collect_test.rb +4 -3
  127. data/test/collection_listing_test.rb +21 -16
  128. data/test/collection_publication_test.rb +8 -8
  129. data/test/collection_test.rb +20 -19
  130. data/test/countable_test.rb +3 -2
  131. data/test/currency_test.rb +5 -5
  132. data/test/custom_collection_test.rb +4 -3
  133. data/test/customer_saved_search_test.rb +18 -8
  134. data/test/customer_test.rb +22 -14
  135. data/test/detailed_log_subscriber_test.rb +15 -11
  136. data/test/discount_code_batch_test.rb +11 -10
  137. data/test/discount_code_test.rb +21 -15
  138. data/test/draft_order_test.rb +68 -52
  139. data/test/fixtures/assigned_fulfillment_orders.json +2 -0
  140. data/test/fixtures/fulfillment_order.json +1 -0
  141. data/test/fixtures/fulfillment_orders.json +2 -0
  142. data/test/fulfillment_event_test.rb +31 -26
  143. data/test/fulfillment_order_test.rb +215 -147
  144. data/test/fulfillment_order_test_helper.rb +1 -0
  145. data/test/fulfillment_request_test.rb +10 -8
  146. data/test/fulfillment_service_test.rb +13 -12
  147. data/test/fulfillment_test.rb +81 -66
  148. data/test/fulfillment_v2_test.rb +16 -12
  149. data/test/gift_card_test.rb +6 -4
  150. data/test/graphql_test.rb +27 -27
  151. data/test/image_test.rb +19 -17
  152. data/test/inventory_level_test.rb +24 -15
  153. data/test/lib/webmock_extensions/last_request.rb +1 -1
  154. data/test/limits_test.rb +2 -1
  155. data/test/location_test.rb +2 -1
  156. data/test/marketing_event_test.rb +20 -20
  157. data/test/message_enricher_test.rb +6 -6
  158. data/test/meta_test.rb +7 -9
  159. data/test/metafield_test.rb +30 -20
  160. data/test/order_risk_test.rb +17 -16
  161. data/test/order_test.rb +43 -28
  162. data/test/pagination_test.rb +89 -56
  163. data/test/policy_test.rb +6 -5
  164. data/test/price_rule_test.rb +20 -15
  165. data/test/product_listing_test.rb +20 -20
  166. data/test/product_publication_test.rb +8 -8
  167. data/test/product_test.rb +44 -32
  168. data/test/publication_test.rb +3 -3
  169. data/test/recurring_application_charge_test.rb +104 -42
  170. data/test/redirect_test.rb +4 -3
  171. data/test/refund_test.rb +22 -17
  172. data/test/report_test.rb +12 -10
  173. data/test/resource_feedback_test.rb +14 -13
  174. data/test/script_tag_test.rb +10 -9
  175. data/test/session_test.rb +74 -46
  176. data/test/shipping_zone_test.rb +4 -3
  177. data/test/shop_test.rb +47 -33
  178. data/test/smart_collection_test.rb +5 -4
  179. data/test/storefront_access_token_test.rb +13 -15
  180. data/test/tax_service_test.rb +7 -4
  181. data/test/tender_transaction_test.rb +3 -3
  182. data/test/test_helper.rb +13 -11
  183. data/test/transaction_test.rb +4 -3
  184. data/test/usage_charge_test.rb +12 -8
  185. data/test/user_test.rb +4 -3
  186. data/test/variant_test.rb +23 -54
  187. data/test/webhook_test.rb +10 -7
  188. metadata +14 -9
  189. data/.rubocop-https---shopify-github-io-ruby-style-guide-rubocop-yml +0 -1027
  190. data/.travis.yml +0 -28
data/RELEASING CHANGED
@@ -2,12 +2,16 @@ Releasing ShopifyAPI
2
2
 
3
3
  1. Check the Semantic Versioning page for info on how to version the new release: http://semver.org
4
4
  2. Update the version of ShopifyAPI in lib/shopify_api/version.rb
5
- 3. Add a CHANGELOG entry for the new release
6
- 4. Commit the changes with a commit message like "Packaging for release X.Y.Z"
7
- 5. Tag the release with the version (Leave REV blank for HEAD or provide a SHA)
5
+ 3. Run `bundle`
6
+ 4. Add a CHANGELOG entry for the new release
7
+ 5. Commit the changes with a commit message like "Packaging for release X.Y.Z"
8
+ 6. Tag the release with the version (Leave REV blank for HEAD or provide a SHA)
8
9
  $ git tag vX.Y.Z REV
9
- 6. Push out the changes
10
+ 7. Push out the changes
10
11
  $ git push
11
- 7. Push out the tags
12
+ 8. Push out the tags
12
13
  $ git push --tags
13
- 8. Publish the gem using Shipit
14
+ 9. Publish the gem using Shipit
15
+ 10. Consider if the dependency in Shopify/shopify needs updated. It's used only by the tests so is a low risk change.
16
+ Also consider Shopify/shopify_app whose gemspec depends on this.
17
+ We don't need to do this for every release, but we should try to keep them relatively up to date.
data/Rakefile CHANGED
@@ -1,13 +1,17 @@
1
+ # frozen_string_literal: true
1
2
  require 'rake'
2
3
  require "bundler/gem_tasks"
3
-
4
4
  require 'rake/testtask'
5
+ require 'rubocop/rake_task'
6
+
5
7
  Rake::TestTask.new(:test) do |test|
6
8
  test.libs << 'lib' << 'test'
7
9
  test.pattern = 'test/**/*_test.rb'
8
10
  test.warning = false
9
11
  end
10
12
 
13
+ RuboCop::RakeTask.new
14
+
11
15
  begin
12
16
  require 'rcov/rcovtask'
13
17
  Rcov::RcovTask.new do |test|
@@ -16,15 +20,15 @@ begin
16
20
  test.verbose = true
17
21
  end
18
22
  rescue LoadError
19
- task :rcov do
20
- abort "RCov is not available. In order to run rcov, you must: sudo gem install spicycode-rcov"
23
+ task(:rcov) do
24
+ abort("RCov is not available. In order to run rcov, you must: sudo gem install spicycode-rcov")
21
25
  end
22
26
  end
23
27
 
24
- task :default => [:test, :verify_docs]
28
+ task(default: [:test, :rubocop, :verify_docs])
25
29
 
26
30
  require 'verify_docs'
27
- task :verify_docs do
31
+ task(:verify_docs) do
28
32
  unless VerifyDocs.call
29
33
  abort("\nWARNING: docs/index.md and README.md no longer have identical content. Please correct this.")
30
34
  end
@@ -45,7 +49,7 @@ Rake::RDocTask.new do |rdoc|
45
49
  rdoc.rdoc_files.include('lib/**/*.rb')
46
50
  end
47
51
 
48
- task :docker do
52
+ task(:docker) do
49
53
  cmd = "docker-compose up -d && docker exec -i -t shopify_api bash"
50
54
  exec(cmd, err: File::NULL)
51
55
  end
@@ -32,7 +32,7 @@ result.data.shop.name
32
32
  ## Getting started
33
33
 
34
34
  1. [Dump the schema](#dump-the-schema)
35
- 2. [Configure session/authencation](#sessions-and-authentication)
35
+ 2. [Configure session/authentication](#sessions-and-authentication)
36
36
  3. [Make queries](#make-queries)
37
37
 
38
38
  ### Dump the schema
@@ -2,7 +2,7 @@
2
2
  layout: index
3
3
  ---
4
4
 
5
- [![Version][gem]][gem_url] [![Build Status](https://travis-ci.org/Shopify/shopify_api.svg?branch=master)](https://travis-ci.org/Shopify/shopify_api)
5
+ [![Version][gem]][gem_url] [![Build Status](https://github.com/Shopify/shopify_api/workflows/CI/badge.svg?branch=master)](https://github.com/Shopify/shopify_api/actions)
6
6
 
7
7
  [gem]: https://img.shields.io/gem/v/shopify_api.svg
8
8
  [gem_url]: https://rubygems.org/gems/shopify_api
@@ -1,3 +1,4 @@
1
+ # frozen_string_literal: true
1
2
  require 'shopify_api/connection'
2
3
 
3
4
  module ActiveResource
@@ -1,3 +1,4 @@
1
+ # frozen_string_literal: true
1
2
  module ActiveResource
2
3
  class DetailedLogSubscriber < ActiveSupport::LogSubscriber
3
4
  VERSION_EOL_WARNING_HEADER = 'x-shopify-api-version-warning'
@@ -18,9 +19,9 @@ module ActiveResource
18
19
  headers = data.extract_options!
19
20
  request_body = data.first
20
21
 
21
- info "Request:\n#{request_body}" if request_body
22
- info "Headers: #{headers.inspect}"
23
- info "Response:\n#{event.payload[:response].body}"
22
+ info("Request:\n#{request_body}") if request_body
23
+ info("Headers: #{headers.inspect}")
24
+ info("Response:\n#{event.payload[:response].body}")
24
25
  end
25
26
 
26
27
  def warn_on_deprecated_header_or_version_eol_header(event)
@@ -34,7 +35,7 @@ module ActiveResource
34
35
  use of a deprecated endpoint, behaviour, or parameter. See #{header_value} for more details.
35
36
  MSG
36
37
 
37
- warn warning_message
38
+ warn(warning_message)
38
39
 
39
40
  when VERSION_EOL_WARNING_HEADER
40
41
  warning_message = <<-MSG
@@ -42,11 +43,9 @@ module ActiveResource
42
43
  an API version that is unsupported or will become unsupported within 30 days. See #{header_value} for more details.
43
44
  MSG
44
45
 
45
- warn warning_message
46
+ warn(warning_message)
46
47
  end
47
48
  end
48
49
  end
49
50
  end
50
51
  end
51
-
52
- ActiveResource::DetailedLogSubscriber.attach_to :active_resource_detailed
@@ -1,9 +1,15 @@
1
+ # frozen_string_literal: true
1
2
  require 'active_resource/base'
2
3
 
3
4
  module ActiveResource
4
5
  class Errors < ActiveModel::Errors
5
6
  def from_json(json, save_cache = false)
6
- data = ActiveSupport::JSON.decode(json)['errors'] || {} rescue {}
7
+ data =
8
+ begin
9
+ ActiveSupport::JSON.decode(json)['errors'] || {}
10
+ rescue
11
+ {}
12
+ end
7
13
  case data
8
14
  when String
9
15
  from_string(data, save_cache)
@@ -15,7 +21,7 @@ module ActiveResource
15
21
  def from_hash(messages, save_cache = false)
16
22
  clear unless save_cache
17
23
 
18
- messages.each do |key,errors|
24
+ messages.each do |key, errors|
19
25
  errors.each do |error|
20
26
  add(key, error)
21
27
  end
@@ -1,4 +1,5 @@
1
- $:.unshift File.dirname(__FILE__)
1
+ # frozen_string_literal: true
2
+ $:.unshift(File.dirname(__FILE__))
2
3
  require 'active_resource'
3
4
  require 'active_support/core_ext/class/attribute_accessors'
4
5
  require 'digest/md5'
@@ -20,6 +21,7 @@ require 'shopify_api/metafields'
20
21
  require 'shopify_api/countable'
21
22
  require 'shopify_api/resources'
22
23
  require 'shopify_api/session'
24
+ require 'shopify_api/api_access'
23
25
  require 'shopify_api/message_enricher'
24
26
  require 'shopify_api/connection'
25
27
  require 'shopify_api/pagination_link_headers'
@@ -31,3 +33,8 @@ if ShopifyAPI::Base.respond_to?(:connection_class)
31
33
  else
32
34
  require 'active_resource/connection_ext'
33
35
  end
36
+
37
+ if ENV["SHOPIFY_LOG_PATH"]
38
+ ActiveResource::Base.logger = Logger.new(ENV["SHOPIFY_LOG_PATH"])
39
+ ActiveResource::DetailedLogSubscriber.attach_to(:active_resource_detailed)
40
+ end
@@ -0,0 +1,57 @@
1
+ # frozen_string_literal: true
2
+
3
+ module ShopifyAPI
4
+ class ApiAccess
5
+ SCOPE_DELIMITER = ','
6
+
7
+ def initialize(scope_names)
8
+ if scope_names.is_a?(String)
9
+ scope_names = scope_names.to_s.split(SCOPE_DELIMITER)
10
+ end
11
+
12
+ store_scopes(scope_names)
13
+ end
14
+
15
+ def covers?(scopes)
16
+ scopes.compressed_scopes <= expanded_scopes
17
+ end
18
+
19
+ def to_s
20
+ to_a.join(SCOPE_DELIMITER)
21
+ end
22
+
23
+ def to_a
24
+ compressed_scopes.to_a
25
+ end
26
+
27
+ def ==(other)
28
+ other.class == self.class &&
29
+ compressed_scopes == other.compressed_scopes
30
+ end
31
+
32
+ alias :eql? :==
33
+
34
+ def hash
35
+ compressed_scopes.hash
36
+ end
37
+
38
+ protected
39
+
40
+ attr_reader :compressed_scopes, :expanded_scopes
41
+
42
+ private
43
+
44
+ def store_scopes(scope_names)
45
+ scopes = scope_names.map(&:strip).reject(&:empty?).to_set
46
+ implied_scopes = scopes.map { |scope| implied_scope(scope) }.compact
47
+
48
+ @compressed_scopes = scopes - implied_scopes
49
+ @expanded_scopes = scopes + implied_scopes
50
+ end
51
+
52
+ def implied_scope(scope)
53
+ is_write_scope = scope =~ /\A(unauthenticated_)?write_(.*)\z/
54
+ "#{$1}read_#{$2}" if is_write_scope
55
+ end
56
+ end
57
+ end
@@ -54,8 +54,8 @@ module ShopifyAPI
54
54
 
55
55
  def define_known_versions
56
56
  warn(
57
- '[DEPRECATED] ShopifyAPI::ApiVersion.define_known_versions is deprecated and will be removed in a future version. ' \
58
- 'Use `fetch_known_versions` instead.'
57
+ '[DEPRECATED] ShopifyAPI::ApiVersion.define_known_versions is deprecated and will be ' \
58
+ 'removed in a future version. Use `fetch_known_versions` instead.'
59
59
  )
60
60
  fetch_known_versions
61
61
  end
@@ -70,15 +70,16 @@ module ShopifyAPI
70
70
 
71
71
  def clear_defined_versions
72
72
  warn(
73
- '[DEPRECATED] ShopifyAPI::ApiVersion.clear_defined_versions is deprecated and will be removed in a future version. ' \
74
- 'Use `clear_known_versions` instead.'
73
+ '[DEPRECATED] ShopifyAPI::ApiVersion.clear_defined_versions is deprecated and will be ' \
74
+ 'removed in a future version. Use `clear_known_versions` instead.'
75
75
  )
76
76
  clear_known_versions
77
77
  end
78
78
 
79
79
  def latest_stable_version
80
80
  warn(
81
- '[DEPRECATED] ShopifyAPI::ApiVersion.latest_stable_version is deprecated and will be removed in a future version.'
81
+ '[DEPRECATED] ShopifyAPI::ApiVersion.latest_stable_version is deprecated and will be ' \
82
+ 'removed in a future version.'
82
83
  )
83
84
  versions.values.find(&:latest_supported?)
84
85
  end
@@ -1,3 +1,4 @@
1
+ # frozen_string_literal: true
1
2
  module ShopifyAPI
2
3
  class Connection < ActiveResource::Connection
3
4
  attr_reader :response
@@ -1,11 +1,12 @@
1
+ # frozen_string_literal: true
1
2
  module ShopifyAPI
2
3
  module Countable
3
4
  def count(options = {})
4
5
  data = get(:count, options)
5
6
 
6
7
  count = case data
7
- when Hash then data["count"]
8
- else data
8
+ when Hash then data["count"]
9
+ else data
9
10
  end
10
11
 
11
12
  Integer(count)
@@ -14,13 +14,13 @@ module ShopifyAPI
14
14
 
15
15
  init_prefix_explicit(resource_type, resource_id)
16
16
 
17
- define_singleton_method :resource_prefix do |options = {}|
17
+ define_singleton_method(:resource_prefix) do |options = {}|
18
18
  resource_type = options[resource] if flexible
19
19
 
20
20
  options[resource_id].nil? ? '' : "#{resource_type}/#{options[resource_id]}/"
21
21
  end
22
22
 
23
- define_singleton_method :instantiate_record do |record, prefix_options = {}|
23
+ define_singleton_method(:instantiate_record) do |record, prefix_options = {}|
24
24
  new(record, true).tap do |resource_instance|
25
25
  resource_instance.prefix_options = prefix_options unless prefix_options.blank?
26
26
  end
@@ -1,7 +1,8 @@
1
+ # frozen_string_literal: true
1
2
  module ShopifyAPI
2
3
  module Events
3
4
  def events
4
- Event.find(:all, :params => {:resource => self.class.collection_name, :resource_id => id})
5
+ Event.find(:all, params: { resource: self.class.collection_name, resource_id: id })
5
6
  end
6
7
  end
7
8
  end
@@ -30,7 +30,10 @@ module ShopifyAPI
30
30
  To dump the schema file, use the `rake shopify_api:graphql:dump` task.
31
31
  MSG
32
32
  else
33
- puts '[WARNING] Client was not pre-initialized. Ensure `ShopifyAPI::GraphQL.initialize_clients` is called during app initialization.'
33
+ puts(
34
+ '[WARNING] Client was not pre-initialized. Ensure `ShopifyAPI::GraphQL.initialize_clients` ' \
35
+ 'is called during app initialization.'
36
+ )
34
37
  initialize_clients
35
38
  @_client_cache[api_version]
36
39
  end
@@ -50,12 +53,11 @@ module ShopifyAPI
50
53
 
51
54
  if matches
52
55
  api_version = ShopifyAPI::ApiVersion.new(handle: matches[1])
56
+ elsif raise_on_invalid_schema
57
+ raise InvalidSchema,
58
+ "Invalid schema file name `#{schema_file}`. Does not match format of: `<version>.json`."
53
59
  else
54
- if raise_on_invalid_schema
55
- raise InvalidSchema, "Invalid schema file name `#{schema_file}`. Does not match format of: `<version>.json`."
56
- else
57
- next
58
- end
60
+ next
59
61
  end
60
62
 
61
63
  schema = graphql_client.load_schema(schema_file.to_s)
@@ -1,3 +1,4 @@
1
+ # frozen_string_literal: true
1
2
  module ShopifyAPI
2
3
  module Limits
3
4
  class LimitUnavailable < StandardError; end
@@ -38,7 +39,7 @@ module ShopifyAPI
38
39
  # @param {Symbol} scope [:shop]
39
40
  # @return {Integer}
40
41
  #
41
- def credit_limit(scope=:shop)
42
+ def credit_limit(scope = :shop)
42
43
  api_credit_limit_param(scope).pop.to_i - 1
43
44
  end
44
45
  alias_method :call_limit, :credit_limit
@@ -48,7 +49,7 @@ module ShopifyAPI
48
49
  # @param {Symbol} scope [:shop]
49
50
  # @return {Integer}
50
51
  #
51
- def credit_used(scope=:shop)
52
+ def credit_used(scope = :shop)
52
53
  api_credit_limit_param(scope).shift.to_i
53
54
  end
54
55
  alias_method :call_count, :credit_used
@@ -1,20 +1,22 @@
1
+ # frozen_string_literal: true
1
2
  module ShopifyAPI
2
3
  class MessageEnricher < SimpleDelegator
3
4
  def message
4
5
  return super unless (400...500).include?(code.to_i)
5
6
 
6
7
  @_cached_message ||= begin
7
- detailed_error = begin
8
- parsed_body = JSON.parse(body)
8
+ detailed_error =
9
+ begin
10
+ parsed_body = JSON.parse(body)
9
11
 
10
- if parsed_body['error']
11
- parsed_body['error'].to_s
12
- elsif parsed_body['errors']
13
- Array(parsed_body['errors']).join('; ')
12
+ if parsed_body['error']
13
+ parsed_body['error'].to_s
14
+ elsif parsed_body['errors']
15
+ Array(parsed_body['errors']).join('; ')
16
+ end
17
+ rescue JSON::ParserError
18
+ nil
14
19
  end
15
- rescue JSON::ParserError
16
- nil
17
- end
18
20
 
19
21
  detailed_error.present? ? "#{super} (#{detailed_error})" : super
20
22
  end
@@ -12,4 +12,3 @@ module ShopifyAPI
12
12
  end
13
13
  end
14
14
  end
15
-
@@ -1,17 +1,18 @@
1
+ # frozen_string_literal: true
1
2
  module ShopifyAPI
2
3
  module Metafields
3
4
  def metafields(**options)
4
- options.merge! resource: self.class.collection_name, resource_id: id
5
+ options.merge!(resource: self.class.collection_name, resource_id: id)
5
6
 
6
- Metafield.find :all, params: options
7
+ Metafield.find(:all, params: options)
7
8
  end
8
9
 
9
10
  def add_metafield(metafield)
10
11
  raise ArgumentError, "You can only add metafields to resource that has been saved" if new?
11
12
 
12
13
  metafield.prefix_options = {
13
- :resource => self.class.collection_name,
14
- :resource_id => id
14
+ resource: self.class.collection_name,
15
+ resource_id: id,
15
16
  }
16
17
  metafield.save
17
18
  metafield
@@ -1,3 +1,4 @@
1
+ # frozen_string_literal: true
1
2
  module ShopifyAPI
2
3
  class InvalidPaginationLinksError < StandardError; end
3
4
 
@@ -9,8 +10,6 @@ module ShopifyAPI
9
10
  links = parse_link_header(link_header)
10
11
  @previous_link = links.find { |link| link.rel == :previous }
11
12
  @next_link = links.find { |link| link.rel == :next }
12
-
13
- self
14
13
  end
15
14
 
16
15
  private
@@ -20,7 +19,9 @@ module ShopifyAPI
20
19
  links = link_header.split(',')
21
20
  links.map do |link|
22
21
  parts = link.split('; ')
23
- raise ShopifyAPI::InvalidPaginationLinksError.new("Invalid link header: url and rel expected") unless parts.length == 2
22
+ unless parts.length == 2
23
+ raise ShopifyAPI::InvalidPaginationLinksError, "Invalid link header: url and rel expected"
24
+ end
24
25
 
25
26
  url = parts[0][/<(.*)>/, 1]
26
27
  rel = parts[1][/rel="(.*)"/, 1]&.to_sym