shopify_api 7.1.0 → 8.0.0

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: eabb483e194b801a4280e35ef231090afdb16c4e048b1d04750244981596294d
4
- data.tar.gz: caa55aa7f65d51fbb1d7d8fccfcc4ba1ee72331d9709d03c06e1a9e58d27f668
3
+ metadata.gz: 971668a584dc96aa673c1648c5c8da796e64adfd63a30515da9376b460efbd2a
4
+ data.tar.gz: d161f78b00baaf4def4c4effc51a802143b483af08281afc043b93e0e8eba940
5
5
  SHA512:
6
- metadata.gz: 34a727aa05565a3e2098be2d26b6f00472c7c1afb1a3b2cc6a93667309d55881b22aca4d48d7ac3e84a1d313ed614ca1d8303c0e4c5bb9d1cd932b3beba5444f
7
- data.tar.gz: c92774a6599fdfb32b11489239519d28d6ab9ba53cb6e4eb41bafa39b9d8fec50e6e3c7254dd73b472ead02b6b6fc4c93ace53233550e2e66c4ead041a04aea5
6
+ metadata.gz: ca615cd5b6ea53fccc3cd75a0ff4f994ceb6c086034232f36c64a1e2d11abe948faa12cf4b63603e2d9d98f2714038199950b2baa0561dde343b042f551b49e0
7
+ data.tar.gz: 9043ff8baf6e9f22f536c0ca68d85ba96d542648aea47da73a35909c86949036be7b310de82fa266a689786af7b9ca15c975677f048b70e64fb1399197161b80
@@ -1,3 +1,13 @@
1
+ == Version 8.0.0
2
+
3
+ * Api Version changes [#600](https://github.com/Shopify/shopify_api/pull/600)
4
+ * Remove static Api Version definitions.
5
+ * Introduces Api Version lookup modes: `:define_on_unknown` and `:raise_on_unknown`
6
+ * See [migration notes](README.md#-breaking-change-notice-for-version-800-)
7
+ * `Session.valid?` checks that api_version `is_a?(ApiVersion)` instead of `present?`
8
+ * `ApiVersion::NullVersion` cannot be instantiated and now has a `match?` method [#615](https://github.com/Shopify/shopify_api/pull/615/files)
9
+ * Introduces new Collection endpoint for looking up products without knowing collection type. Only available if ApiVersion is `:unstable` [#609](https://github.com/Shopify/shopify_api/pull/609)
10
+
1
11
  == Version 7.1.0
2
12
 
3
13
  * Add 2019-10 to known API versions
data/README.md CHANGED
@@ -10,6 +10,33 @@ The Shopify API gem allows Ruby developers to programmatically access the admin
10
10
 
11
11
  The API is implemented as JSON over HTTP using all four verbs (GET/POST/PUT/DELETE). Each resource, like Order, Product, or Collection, has its own URL and is manipulated in isolation. In other words, we’ve tried to make the API follow the REST principles as much as possible.
12
12
 
13
+ ### !! Breaking change notice for version 8.0.0 !!
14
+
15
+ ApiVersion was introduced in Version 7.0.0 and known versions were hard coded into the gem. Manually defining api versions is no longer required for versions not listed in the gem. Version 8.0.0 removes the following:
16
+ * `ShopifyAPI::ApiVersion::Unstable`
17
+ * `ShopifyAPI::ApiVersion::Release`
18
+ * `ShopifyAPI::ApiVersion.define_version`
19
+
20
+ The following methods on `ApiVersion` have been deprecated:
21
+ - `.coerce_to_version` deprecated. use `.find_version`
22
+ - `.define_known_versions` deprecated. Use `.fetch_known_versions`
23
+ - `.clear_defined_versions` deprecated. Use. `.clear_known_versions`
24
+ - `.latest_stable_version` deprecated. Use `ShopifyAPI::Meta.admin_versions.find(&:latest_supported)` (this fetches info from Shopify servers. No authentication required.)
25
+ - `#name` deprecated. Use `#handle`
26
+ - `#stable?` deprecated. Use `#supported?`
27
+
28
+ Version 8.0.0 introduces a _version lookup mode_. By default, `ShopifyAPI::ApiVersion.version_lookup_mode` is `:define_on_unknown`. When setting the api_version on `Session` or `Base`, the `api_version` attribute takes a version handle (ie `'2019-07'` or `:unstable`) and sets an instance of `ShopifyAPI::ApiVersion` matching the handle. When the version_lookup_mode is set to `:define_on_unknown`, any handle will naïvely create a new `ApiVersion` if the version is not in the known versions returned by `ShopifyAPI::ApiVersion.versions`.
29
+
30
+ To ensure only known and active versions can be set, call
31
+
32
+ ```ruby
33
+ ShopifyAPI::ApiVersion.version_lookup_mode = :raise_on_unknown
34
+ ShopifyAPI::ApiVersion.fetch_known_versions
35
+ ```
36
+
37
+ Known and active versions are fetched from https://app.shopify.com/services/apis.json and cached. Trying to use a version outside this cached set will raise an error. To switch back to naïve lookup and create a version if its not found, call `ShopifyAPI::ApiVersion.version_lookup_mode = :define_on_unknown`.
38
+
39
+
13
40
  ## !! Breaking change notice for version 7.0.0 !!
14
41
 
15
42
  ### Changes to ShopifyAPI::Session
@@ -38,8 +65,6 @@ ShopifyAPI::Session.temp(domain: domain, token: token, api_version: api_version)
38
65
  end
39
66
  ```
40
67
 
41
- The `api_version` attribute can take the string or symbol name of any known version and correctly coerce it to a `ShopifyAPI::ApiVersion`. You can find the currently defined versions [here](https://github.com/Shopify/shopify_api/blob/master/lib/shopify_api/defined_versions.rb), follow these [instructions](#adding-additional-api-versions) to add additional version definitions if needed.
42
-
43
68
  For example if you want to use the `2019-04` version you would create a session like this:
44
69
  ```ruby
45
70
  session = ShopifyAPI::Session.new(domain: domain, token: token, api_version: '2019-04')
@@ -344,21 +369,6 @@ result = client.query(SHOP_NAME_QUERY)
344
369
  result.data.shop.name
345
370
  ```
346
371
 
347
- ## Adding additional API versions
348
- We will release a gem update every time we release a new version of the API. Most of the time upgrading the gem will be all you need to do.
349
-
350
- If you want access to a newer version without upgrading you can define an api version.
351
- For example if you wanted to add an `ApiVersion` '2022-03', you would add the following to the initialization of your application:
352
- ```ruby
353
- ShopifyAPI::ApiVersion.define_version(ShopifyAPI::ApiVersion::Release.new('2022-03'))
354
- ```
355
- Once you have done that you can now set this version in a Sesssion like this:
356
-
357
- ```ruby
358
- ShopifyAPI::Session.new(domain: domain, token: token, api_version: '2022-03')
359
- ```
360
-
361
-
362
372
  ## Threadsafety
363
373
 
364
374
  ActiveResource is threadsafe as of version 4.1 (which works with Rails 4.x and above).
@@ -5,8 +5,8 @@ require 'digest/md5'
5
5
  require 'base64'
6
6
  require 'active_resource/detailed_log_subscriber'
7
7
  require 'shopify_api/limits'
8
- require 'shopify_api/defined_versions'
9
8
  require 'shopify_api/api_version'
9
+ require 'shopify_api/meta'
10
10
  require 'active_resource/json_errors'
11
11
  require 'shopify_api/paginated_collection'
12
12
  require 'shopify_api/disable_prefix_check'
@@ -28,5 +28,3 @@ if ShopifyAPI::Base.respond_to?(:connection_class)
28
28
  else
29
29
  require 'active_resource/connection_ext'
30
30
  end
31
-
32
- ShopifyAPI::ApiVersion.define_known_versions
@@ -1,129 +1,204 @@
1
1
  # frozen_string_literal: true
2
2
  module ShopifyAPI
3
3
  class ApiVersion
4
- class ApiVersionNotSetError < StandardError; end
5
4
  class UnknownVersion < StandardError; end
6
- class InvalidVersion < StandardError; end
5
+ class ApiVersionNotSetError < StandardError; end
6
+ include Comparable
7
7
 
8
- extend DefinedVersions
8
+ HANDLE_FORMAT = /^\d{4}-\d{2}$/.freeze
9
+ UNSTABLE_HANDLE = 'unstable'
10
+ UNSTABLE_AS_DATE = Time.utc(3000, 1, 1)
11
+ API_PREFIX = '/admin/api/'
12
+ LOOKUP_MODES = [:raise_on_unknown, :define_on_unknown].freeze
9
13
 
10
- include Comparable
14
+ class << self
15
+ attr_reader :versions
11
16
 
12
- def self.coerce_to_version(version_or_name)
13
- return version_or_name if version_or_name.is_a?(ApiVersion)
17
+ def version_lookup_mode
18
+ @version_lookup_mode ||= :define_on_unknown
19
+ end
14
20
 
15
- @versions ||= {}
16
- @versions.fetch(version_or_name.to_s) do
17
- raise UnknownVersion, "#{version_or_name} is not in the defined version set: #{@versions.keys.join(', ')}"
21
+ def version_lookup_mode=(mode)
22
+ raise ArgumentError, "Mode must be one of #{LOOKUP_MODES}" unless LOOKUP_MODES.include?(mode)
23
+ sanitize_known_versions if mode == :raise_on_unknown
24
+ @version_lookup_mode = mode
25
+ end
26
+
27
+ def find_version(version_or_handle)
28
+ raise ArgumentError, "NullVersion is not a valid version or version handle." if version_or_handle == NullVersion
29
+ return version_or_handle if version_or_handle.is_a?(ApiVersion)
30
+ handle = version_or_handle.to_s
31
+ @versions ||= {}
32
+ @versions.fetch(handle) do
33
+ if @version_lookup_mode == :raise_on_unknown
34
+ raise UnknownVersion, unknown_version_error_message(handle)
35
+ else
36
+ add_to_known_versions(ApiVersion.new(handle: handle))
37
+ end
38
+ end
18
39
  end
19
- end
20
40
 
21
- def self.define_version(version)
22
- @versions ||= {}
41
+ def coerce_to_version(version_or_handle)
42
+ warn(
43
+ '[DEPRECATED] ShopifyAPI::ApiVersion.coerce_to_version be removed in a future version. ' \
44
+ 'Use `find_version` instead.'
45
+ )
46
+ find_version(version_or_handle)
47
+ end
23
48
 
24
- @versions[version.name] = version
25
- end
49
+ def fetch_known_versions
50
+ @versions = Meta.admin_versions.map do |version|
51
+ [version.handle, ApiVersion.new(version.attributes.merge(verified: version.persisted?))]
52
+ end.to_h
53
+ end
54
+
55
+ def define_known_versions
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.'
59
+ )
60
+ fetch_known_versions
61
+ end
26
62
 
27
- def self.clear_defined_versions
28
- @versions = {}
63
+ def add_to_known_versions(version)
64
+ @versions[version.handle] = version
65
+ end
66
+
67
+ def clear_known_versions
68
+ @versions = {}
69
+ end
70
+
71
+ def clear_defined_versions
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.'
75
+ )
76
+ clear_known_versions
77
+ end
78
+
79
+ def latest_stable_version
80
+ warn(
81
+ '[DEPRECATED] ShopifyAPI::ApiVersion.latest_stable_version is deprecated and will be removed in a future version.'
82
+ )
83
+ versions.values.find(&:latest_supported?)
84
+ end
85
+
86
+ private
87
+
88
+ def sanitize_known_versions
89
+ return if @versions.nil?
90
+ @versions = @versions.keys.map do |handle|
91
+ next unless @versions[handle].verified?
92
+ [handle, @versions[handle]]
93
+ end.compact.to_h
94
+ end
95
+
96
+ def unknown_version_error_message(handle)
97
+ msg = "ApiVersion.version_lookup_mode is set to `:raise_on_unknown`. \n"
98
+ return msg + "No versions defined. You must call `ApiVersion.fetch_known_versions` first." if @versions.empty?
99
+ msg + "`#{handle}` is not in the defined version set. Available versions: #{@versions.keys}"
100
+ end
29
101
  end
30
102
 
31
- def self.latest_stable_version
32
- @versions.values.select(&:stable?).sort.last
103
+ attr_reader :handle, :display_name, :supported, :latest_supported, :verified
104
+
105
+ def initialize(attributes)
106
+ attributes = ActiveSupport::HashWithIndifferentAccess.new(attributes)
107
+ @handle = attributes[:handle].to_s
108
+ @display_name = attributes.fetch(:display_name, attributes[:handle].to_s)
109
+ @supported = attributes.fetch(:supported, false)
110
+ @latest_supported = attributes.fetch(:latest_supported, false)
111
+ @verified = attributes.fetch(:verified, false)
33
112
  end
34
113
 
35
114
  def to_s
36
- @version_name
115
+ handle
37
116
  end
38
- alias_method :name, :to_s
39
117
 
40
- def inspect
41
- @version_name
118
+ def latest_supported?
119
+ latest_supported
42
120
  end
43
121
 
44
- def ==(other)
45
- other.class == self.class && to_s == other.to_s
122
+ def supported?
123
+ supported
46
124
  end
47
125
 
48
- def hash
49
- @version_name.hash
126
+ def verified?
127
+ verified
50
128
  end
51
129
 
52
130
  def <=>(other)
53
- numeric_version <=> other.numeric_version
131
+ handle_as_date <=> other.handle_as_date
54
132
  end
55
133
 
56
- def stable?
57
- false
134
+ def ==(other)
135
+ other.class == self.class && handle == other.handle
58
136
  end
59
137
 
60
- def construct_api_path(_path)
61
- raise NotImplementedError
138
+ def hash
139
+ handle.hash
62
140
  end
63
141
 
64
- def construct_graphql_path
65
- raise NotImplementedError
142
+ def construct_api_path(path)
143
+ "#{API_PREFIX}#{handle}/#{path}"
66
144
  end
67
145
 
68
- protected
69
-
70
- attr_reader :numeric_version
71
-
72
- class Unstable < ApiVersion
73
- API_PREFIX = '/admin/api/unstable/'
74
-
75
- def initialize
76
- @version_name = "unstable"
77
- @url = API_PREFIX
78
- @numeric_version = 9_000_00
79
- end
80
-
81
- def construct_api_path(path)
82
- "#{@url}#{path}"
83
- end
84
-
85
- def construct_graphql_path
86
- construct_api_path("graphql.json")
87
- end
146
+ def construct_graphql_path
147
+ construct_api_path('graphql.json')
88
148
  end
89
149
 
90
- class Release < ApiVersion
91
- FORMAT = /^\d{4}-\d{2}$/.freeze
92
- API_PREFIX = '/admin/api/'
93
-
94
- def initialize(version_number)
95
- raise InvalidVersion, version_number unless version_number.match(FORMAT)
96
- @version_name = version_number
97
- @url = "#{API_PREFIX}#{version_number}/"
98
- @numeric_version = version_number.tr('-', '').to_i
99
- end
150
+ def name
151
+ warn(
152
+ '[DEPRECATED] ShopifyAPI::ApiVersion#name is deprecated and will be removed in a future version. ' \
153
+ 'Use `handle` instead.'
154
+ )
155
+ handle
156
+ end
100
157
 
101
- def stable?
102
- true
103
- end
158
+ def stable?
159
+ warn(
160
+ '[DEPRECATED] ShopifyAPI::ApiVersion#stable? is deprecated and will be removed in a future version. ' \
161
+ 'Use `supported?` instead.'
162
+ )
163
+ supported?
164
+ end
104
165
 
105
- def construct_api_path(path)
106
- "#{@url}#{path}"
107
- end
166
+ def unstable?
167
+ handle == UNSTABLE_HANDLE
168
+ end
108
169
 
109
- def construct_graphql_path
110
- construct_api_path('graphql.json')
111
- end
170
+ def handle_as_date
171
+ return UNSTABLE_AS_DATE if unstable?
172
+ year, month, day = handle.split('-')
173
+ Time.utc(year, month, day)
112
174
  end
113
175
 
114
176
  class NullVersion
115
177
  class << self
116
- def stable?
117
- raise ApiVersionNotSetError, "You must set ShopifyAPI::Base.api_version before making a request."
178
+ def new(*_args)
179
+ raise NoMethodError, "NullVersion is an abstract class and cannot be instantiated."
118
180
  end
119
181
 
120
- def construct_api_path(*_path)
121
- raise ApiVersionNotSetError, "You must set ShopifyAPI::Base.api_version before making a request."
182
+ def matches?(version)
183
+ version.nil? || version == self
122
184
  end
123
185
 
124
- def construct_graphql_path
186
+ def raise_not_set_error(*_args)
125
187
  raise ApiVersionNotSetError, "You must set ShopifyAPI::Base.api_version before making a request."
126
188
  end
189
+ alias_method :stable?, :raise_not_set_error
190
+ alias_method :construct_api_path, :raise_not_set_error
191
+ alias_method :construct_graphql_path, :raise_not_set_error
192
+ alias_method :latest_supported?, :raise_not_set_error
193
+ alias_method :supported?, :raise_not_set_error
194
+ alias_method :verified?, :raise_not_set_error
195
+ alias_method :unstable?, :raise_not_set_error
196
+ alias_method :handle, :raise_not_set_error
197
+ alias_method :display_name, :raise_not_set_error
198
+ alias_method :supported, :raise_not_set_error
199
+ alias_method :verified, :raise_not_set_error
200
+ alias_method :latest_supported, :raise_not_set_error
201
+ alias_method :name, :raise_not_set_error
127
202
  end
128
203
  end
129
204
  end
@@ -0,0 +1,15 @@
1
+
2
+ # frozen_string_literal: true
3
+ module ShopifyAPI
4
+ class Meta < ActiveResource::Base
5
+ self.site = "https://app.shopify.com/services/"
6
+ self.element_name = 'api'
7
+ self.primary_key = :handle
8
+ self.timeout = 5
9
+
10
+ def self.admin_versions
11
+ all.find { |api| api.handle = :admin }.versions
12
+ end
13
+ end
14
+ end
15
+
@@ -29,8 +29,8 @@ module ShopifyAPI
29
29
 
30
30
  private
31
31
 
32
- AVAILABLE_IN_VERSION = ShopifyAPI::ApiVersion::Release.new('2019-10')
33
- AVAILABLE_IN_VERSION_EARLY = ShopifyAPI::ApiVersion::Release.new('2019-07')
32
+ AVAILABLE_IN_VERSION = ShopifyAPI::ApiVersion.find_version('2019-10')
33
+ AVAILABLE_IN_VERSION_EARLY = ShopifyAPI::ApiVersion.find_version('2019-07')
34
34
 
35
35
  def fetch_page(url)
36
36
  ensure_available
@@ -68,7 +68,7 @@ module ShopifyAPI
68
68
  end
69
69
 
70
70
  def api_version=(version)
71
- self._api_version = version.nil? ? ApiVersion::NullVersion : ApiVersion.coerce_to_version(version)
71
+ self._api_version = ApiVersion::NullVersion.matches?(version) ? ApiVersion::NullVersion : ApiVersion.find_version(version)
72
72
  end
73
73
 
74
74
  def prefix(options = {})
@@ -0,0 +1,14 @@
1
+ # frozen_string_literal: true
2
+
3
+ module ShopifyAPI
4
+ class Collection < Base
5
+ include Events
6
+ include Metafields
7
+
8
+ def products(options = {})
9
+ available_in_version = ShopifyAPI::ApiVersion.find_version(:unstable)
10
+ raise NotImplementedError unless ShopifyAPI::Base.api_version >= available_in_version
11
+ Product.find(:all, from: "#{self.class.prefix}collections/#{id}/products.json", params: options)
12
+ end
13
+ end
14
+ end
@@ -127,11 +127,11 @@ module ShopifyAPI
127
127
  end
128
128
 
129
129
  def api_version=(version)
130
- @api_version = version.nil? ? nil : ApiVersion.coerce_to_version(version)
130
+ @api_version = ApiVersion::NullVersion.matches?(version) ? ApiVersion::NullVersion : ApiVersion.find_version(version)
131
131
  end
132
132
 
133
133
  def valid?
134
- domain.present? && token.present? && api_version.present?
134
+ domain.present? && token.present? && api_version.is_a?(ApiVersion)
135
135
  end
136
136
 
137
137
  def expires_in
@@ -1,3 +1,3 @@
1
1
  module ShopifyAPI
2
- VERSION = "7.1.0"
2
+ VERSION = "8.0.0"
3
3
  end
@@ -2,110 +2,83 @@
2
2
  require 'test_helper'
3
3
 
4
4
  class ApiVersionTest < Test::Unit::TestCase
5
- def teardown
6
- super
7
- ShopifyAPI::ApiVersion.clear_defined_versions
8
- ShopifyAPI::ApiVersion.define_known_versions
5
+ test "find_version returns any version object given" do
6
+ version = ShopifyAPI::ApiVersion.new(handle: :unstable)
7
+ assert_same(version, ShopifyAPI::ApiVersion.find_version(version))
9
8
  end
10
9
 
11
- test "unstable version creates url that start with /admin/api/unstable/" do
12
- assert_equal(
13
- "/admin/api/unstable/resource_path/id.json",
14
- ShopifyAPI::ApiVersion::Unstable.new.construct_api_path("resource_path/id.json")
15
- )
16
- end
17
-
18
- test "unstable version creates graphql url that start with /admin/api/unstable/" do
19
- assert_equal(
20
- "/admin/api/unstable/graphql.json",
21
- ShopifyAPI::ApiVersion::Unstable.new.construct_graphql_path
22
- )
23
- end
24
-
25
- test "coerce_to_version returns any version object given" do
26
- version = ShopifyAPI::ApiVersion::Unstable.new
27
- assert_same(version, ShopifyAPI::ApiVersion.coerce_to_version(version))
28
- end
29
-
30
- test "coerce_to_version converts a known version into a version object" do
10
+ test "find_version converts a known version into a version object" do
31
11
  versions = [
32
- ShopifyAPI::ApiVersion::Unstable.new,
33
- ShopifyAPI::ApiVersion::Release.new('2019-01'),
12
+ ShopifyAPI::ApiVersion.new(handle: :unstable),
13
+ ShopifyAPI::ApiVersion.new(handle: '2019-01'),
34
14
  ]
35
15
 
36
16
  assert_equal(versions, [
37
- ShopifyAPI::ApiVersion.coerce_to_version('unstable'),
38
- ShopifyAPI::ApiVersion.coerce_to_version('2019-01'),
17
+ ShopifyAPI::ApiVersion.find_version('unstable'),
18
+ ShopifyAPI::ApiVersion.find_version('2019-01'),
39
19
  ])
40
20
  end
41
21
 
42
- test "coerce_to_version raises when coercing a string that doesn't match a known version" do
43
- assert_raises ShopifyAPI::ApiVersion::UnknownVersion do
44
- ShopifyAPI::ApiVersion.coerce_to_version('made up version')
45
- end
46
- end
22
+ test "find_version removes unverified versions from version set if mode is set to :raise_on_unknown" do
23
+ ShopifyAPI::ApiVersion.version_lookup_mode = :define_on_unknown
24
+ assert ShopifyAPI::ApiVersion.versions.values.all?(&:verified?)
25
+ assert_equal 5, ShopifyAPI::ApiVersion.versions.size
47
26
 
48
- test "additional defined versions will also be coerced" do
49
- versions = [
50
- TestApiVersion.new('my_name'),
51
- TestApiVersion.new('other_name'),
52
- ]
27
+ ShopifyAPI::ApiVersion.find_version('2019-30')
28
+ refute ShopifyAPI::ApiVersion.versions.values.all?(&:verified?)
29
+ assert_equal 6, ShopifyAPI::ApiVersion.versions.size
30
+ ShopifyAPI::ApiVersion.version_lookup_mode = :raise_on_unknown
53
31
 
54
- versions.each do |version|
55
- ShopifyAPI::ApiVersion.define_version(version)
56
- end
57
-
58
- assert_equal(versions, [
59
- ShopifyAPI::ApiVersion.coerce_to_version('my_name'),
60
- ShopifyAPI::ApiVersion.coerce_to_version('other_name'),
61
- ])
32
+ assert ShopifyAPI::ApiVersion.versions.values.all?(&:verified?)
33
+ assert_equal 5, ShopifyAPI::ApiVersion.versions.size
62
34
  end
63
35
 
64
- test 'allows a release version with the correct format format to be created' do
65
- assert ShopifyAPI::ApiVersion::Release.new('2019-03')
36
+ test "find_version does not raise when coercing a string if no versions are defined when version_lookup_mode is :define_on_unknown" do
37
+ ShopifyAPI::ApiVersion.clear_known_versions
38
+ ShopifyAPI::ApiVersion.version_lookup_mode = :define_on_unknown
39
+ assert_equal :define_on_unknown, ShopifyAPI::ApiVersion.version_lookup_mode
40
+ assert_nothing_raised do
41
+ ShopifyAPI::ApiVersion.find_version('made up version')
42
+ end
66
43
  end
67
44
 
68
- test 'release versions must follow the format' do
69
- assert_raises ShopifyAPI::ApiVersion::InvalidVersion do
70
- assert ShopifyAPI::ApiVersion::Release.new('crazy-name')
45
+ test "find_version does raise when coercing a string if no versions are defined when version_lookup_mode is :raise_on_unknown" do
46
+ refute ShopifyAPI::ApiVersion.versions['made up version']
47
+ ShopifyAPI::ApiVersion.version_lookup_mode = :raise_on_unknown
48
+ assert_raises ShopifyAPI::ApiVersion::UnknownVersion do
49
+ ShopifyAPI::ApiVersion.find_version('made up version')
71
50
  end
72
51
  end
73
52
 
74
- test 'release versions create a url that is /admin/api/<version_name>/' do
75
- assert_equal(
76
- '/admin/api/2022-03/shop.json',
77
- ShopifyAPI::ApiVersion::Release.new('2022-03').construct_api_path('shop.json')
78
- )
53
+ test "find_version raises ArgumentError when given an ShopifyAPI::ApiVersion::NullVersion object" do
54
+ ShopifyAPI::ApiVersion.clear_known_versions
55
+ ShopifyAPI::ApiVersion.version_lookup_mode = :define_on_unknown
56
+ assert_equal :define_on_unknown, ShopifyAPI::ApiVersion.version_lookup_mode
57
+ assert_raises ArgumentError do
58
+ ShopifyAPI::ApiVersion.find_version(ShopifyAPI::ApiVersion::NullVersion)
59
+ end
79
60
  end
80
61
 
81
62
  test 'two versions with the same version number are equal' do
82
- version_1 = ShopifyAPI::ApiVersion::Release.new('2018-09')
83
- version_2 = ShopifyAPI::ApiVersion::Release.new('2018-09')
63
+ version_1 = ShopifyAPI::ApiVersion.new(handle: '2018-09')
64
+ version_2 = ShopifyAPI::ApiVersion.new(handle: '2018-09')
84
65
 
85
66
  assert_equal version_2, version_1
86
67
  end
87
68
 
88
69
  test 'two versions with the different version numbers are not equal' do
89
- version_1 = ShopifyAPI::ApiVersion::Release.new('2019-07')
90
- version_2 = ShopifyAPI::ApiVersion::Release.new('2019-11')
70
+ version_1 = ShopifyAPI::ApiVersion.new(handle: '2019-07')
71
+ version_2 = ShopifyAPI::ApiVersion.new(handle: '2019-11')
91
72
 
92
73
  refute_equal version_2, version_1
93
74
  end
94
75
 
95
- test 'release verions are stable' do
96
- assert_predicate ShopifyAPI::ApiVersion::Release.new('2019-11'), :stable?
97
- end
98
-
99
- test 'no release version are not stable' do
100
- refute_predicate ShopifyAPI::ApiVersion::Unstable.new, :stable?
101
- end
102
-
103
- test 'release versions are ordered by version number with unstable always being the newest' do
104
- version_1 = ShopifyAPI::ApiVersion::Release.new('2017-11')
105
- version_2 = ShopifyAPI::ApiVersion::Release.new('2019-11')
106
- version_3 = ShopifyAPI::ApiVersion::Release.new('2039-01')
107
- version_4 = ShopifyAPI::ApiVersion::Release.new('2039-02')
108
- unstable = ShopifyAPI::ApiVersion::Unstable.new
76
+ test 'versions are ordered by version number with unstable always being the newest' do
77
+ version_1 = ShopifyAPI::ApiVersion.new(handle: '2017-11')
78
+ version_2 = ShopifyAPI::ApiVersion.new(handle: '2019-11')
79
+ version_3 = ShopifyAPI::ApiVersion.new(handle: '2039-01')
80
+ version_4 = ShopifyAPI::ApiVersion.new(handle: '2039-02')
81
+ unstable = ShopifyAPI::ApiVersion.new(handle: :unstable)
109
82
 
110
83
  assert_equal([
111
84
  version_1,
@@ -123,17 +96,28 @@ class ApiVersionTest < Test::Unit::TestCase
123
96
  end
124
97
 
125
98
  test 'latest_stable_version will return the version that is newest and stable' do
126
- ShopifyAPI::ApiVersion.clear_defined_versions
127
- ShopifyAPI::ApiVersion.define_version(ShopifyAPI::ApiVersion::Release.new('2017-11'))
128
- ShopifyAPI::ApiVersion.define_version(ShopifyAPI::ApiVersion::Release.new('2019-11'))
129
- ShopifyAPI::ApiVersion.define_version(ShopifyAPI::ApiVersion::Release.new('2039-01'))
130
- ShopifyAPI::ApiVersion.define_version(ShopifyAPI::ApiVersion::Release.new('2039-02'))
131
- ShopifyAPI::ApiVersion.define_version(ShopifyAPI::ApiVersion::Unstable.new)
132
-
133
99
  assert_equal(
134
- ShopifyAPI::ApiVersion::Release.new('2039-02'),
135
- ShopifyAPI::ApiVersion.latest_stable_version
100
+ ShopifyAPI::ApiVersion.versions,
101
+ {
102
+ "2019-01" => ShopifyAPI::ApiVersion.new(handle: '2019-01', supported: true, latest_supported: false),
103
+ "2019-04" => ShopifyAPI::ApiVersion.new(handle: '2019-04', supported: true, latest_supported: false),
104
+ "2019-07" => ShopifyAPI::ApiVersion.new(handle: '2019-07', supported: true, latest_supported: true),
105
+ "2019-10" => ShopifyAPI::ApiVersion.new(handle: '2019-10', supported: false, latest_supported: false),
106
+ "unstable" => ShopifyAPI::ApiVersion.new(handle: 'unstable', supported: false, latest_supported: false),
107
+ }
136
108
  )
109
+ silence_warnings do
110
+
111
+ refute_equal(
112
+ ShopifyAPI::ApiVersion.new(handle: '2019-01'),
113
+ ShopifyAPI::ApiVersion.latest_stable_version
114
+ )
115
+
116
+ assert_equal(
117
+ ShopifyAPI::ApiVersion.new(handle: '2019-07'),
118
+ ShopifyAPI::ApiVersion.latest_stable_version
119
+ )
120
+ end
137
121
  end
138
122
 
139
123
  test "NullVersion raises ApiVersionNotSetError" do
@@ -150,6 +134,20 @@ class ApiVersionTest < Test::Unit::TestCase
150
134
  end
151
135
  end
152
136
 
137
+ test "NullVersion cannot be instantiated and raises NoMethodError if attempted" do
138
+ assert_raises(NoMethodError) do
139
+ ShopifyAPI::ApiVersion::NullVersion.new
140
+ end
141
+ end
142
+
143
+ test "handle_to_date converts a version handle to a date" do
144
+ version_1 = ShopifyAPI::ApiVersion.new(handle: '2019-01')
145
+ version_2 = ShopifyAPI::ApiVersion.new(handle: 'unstable')
146
+
147
+ assert_equal(version_1.handle_as_date, Time.utc(2019, 01, 01))
148
+ assert_equal(version_2.handle_as_date, ShopifyAPI::ApiVersion::UNSTABLE_AS_DATE)
149
+ end
150
+
153
151
  class TestApiVersion < ShopifyAPI::ApiVersion
154
152
  def initialize(name)
155
153
  @version_name = name
@@ -168,6 +168,11 @@ class BaseTest < Test::Unit::TestCase
168
168
  assert_equal ShopifyAPI::ApiVersion::NullVersion, ShopifyAPI::Base.api_version
169
169
  end
170
170
 
171
+ test "#api_version= ShopifyAPI::ApiVersion::NullVersion should set ApiVersion to ShopifyAPI::ApiVersion::NullVersion" do
172
+ ShopifyAPI::Base.api_version = ShopifyAPI::ApiVersion::NullVersion
173
+ assert_equal ShopifyAPI::ApiVersion::NullVersion, ShopifyAPI::Base.api_version
174
+ end
175
+
171
176
  def clear_header(header)
172
177
  [ActiveResource::Base, ShopifyAPI::Base, ShopifyAPI::Product].each do |klass|
173
178
  klass.headers.delete(header)
@@ -40,7 +40,7 @@ class CollectionListingTest < Test::Unit::TestCase
40
40
  end
41
41
 
42
42
  def test_get_collection_listing_product_ids_multi_page_with_cursor
43
- version = ShopifyAPI::ApiVersion::Release.new('2019-07')
43
+ version = ShopifyAPI::ApiVersion.find_version('2019-07')
44
44
  ShopifyAPI::Base.api_version = version.to_s
45
45
 
46
46
  collection_listing = ShopifyAPI::CollectionListing.new(collection_id: 1)
@@ -0,0 +1,49 @@
1
+ require 'test_helper'
2
+
3
+ class CollectionTest < Test::Unit::TestCase
4
+ test "Collection get products gets all products in a collection on unstable version" do
5
+ unstable_version = ShopifyAPI::Session.new(domain: 'shop2.myshopify.com', token: 'token2', api_version: :unstable)
6
+ ShopifyAPI::Base.activate_session(unstable_version)
7
+
8
+ fake(
9
+ 'collections',
10
+ url: 'https://shop2.myshopify.com/admin/api/unstable/collections/1.json',
11
+ method: :get,
12
+ status: 200,
13
+ body: load_fixture('collection'),
14
+ extension: false
15
+ )
16
+
17
+ collection = ShopifyAPI::Collection.find(1)
18
+
19
+ fake(
20
+ 'products',
21
+ url: 'https://shop2.myshopify.com/admin/api/unstable/collections/1/products.json',
22
+ method: :get,
23
+ status: 200,
24
+ body: load_fixture('collection_products'),
25
+ extension: false
26
+ )
27
+ assert_equal [632910392, 921728736], collection.products.map(&:id)
28
+ end
29
+
30
+ test "Collection get products fails on older api version" do
31
+ unstable_version = ShopifyAPI::Session.new(domain: 'shop2.myshopify.com', token: 'token2', api_version: '2019-07')
32
+ ShopifyAPI::Base.activate_session(unstable_version)
33
+
34
+ fake(
35
+ 'collections',
36
+ url: 'https://shop2.myshopify.com/admin/api/2019-07/collections/1.json',
37
+ method: :get,
38
+ status: 200,
39
+ body: load_fixture('collection'),
40
+ extension: false
41
+ )
42
+
43
+ collection = ShopifyAPI::Collection.find(1)
44
+
45
+ assert_raises NotImplementedError do
46
+ collection.products
47
+ end
48
+ end
49
+ end
@@ -14,9 +14,14 @@ class LogSubscriberTest < Test::Unit::TestCase
14
14
  @request_headers = "Headers: {\"Accept\"=>\"application/json\", " \
15
15
  "#{@ua_header}, \"X-Shopify-Access-Token\"=>\"access_token\"}"
16
16
 
17
- ShopifyAPI::ApiVersion.define_version(ShopifyAPI::ApiVersion::Release.new('2019-01'))
18
-
19
17
  ShopifyAPI::Base.clear_session
18
+ fake("apis",
19
+ url: "https://app.shopify.com/services/apis.json",
20
+ method: :get,
21
+ status: 200,
22
+ api_version: :stub,
23
+ body: load_fixture('apis'))
24
+ ShopifyAPI::ApiVersion.fetch_known_versions
20
25
  session = ShopifyAPI::Session.new(
21
26
  domain: "https://this-is-my-test-shop.myshopify.com",
22
27
  token: "access_token",
@@ -29,6 +34,12 @@ class LogSubscriberTest < Test::Unit::TestCase
29
34
  ActiveResource::DetailedLogSubscriber.attach_to :active_resource_detailed
30
35
  end
31
36
 
37
+ def teardown
38
+ super
39
+ ShopifyAPI::ApiVersion.clear_known_versions
40
+ ShopifyAPI::ApiVersion.version_lookup_mode = :raise_on_unknown
41
+ end
42
+
32
43
  def set_logger(logger)
33
44
  ActiveResource::Base.logger = logger
34
45
  end
@@ -0,0 +1,32 @@
1
+ [
2
+ {
3
+ "handle": "2019-01",
4
+ "display_name": "2019-01",
5
+ "supported": true,
6
+ "latest_supported": false
7
+ },
8
+ {
9
+ "handle": "2019-04",
10
+ "display_name": "2019-04",
11
+ "supported": true,
12
+ "latest_supported": false
13
+ },
14
+ {
15
+ "handle": "2019-07",
16
+ "display_name": "2019-07 (Latest)",
17
+ "supported": true,
18
+ "latest_supported": true
19
+ },
20
+ {
21
+ "handle": "2019-10",
22
+ "display_name": "2019-10 (Release candidate)",
23
+ "supported": false,
24
+ "latest_supported": false
25
+ },
26
+ {
27
+ "handle": "unstable",
28
+ "display_name": "unstable",
29
+ "supported": false,
30
+ "latest_supported": false
31
+ }
32
+ ]
@@ -0,0 +1,36 @@
1
+ {
2
+ "apis": [{
3
+ "handle": "admin",
4
+ "versions": [{
5
+ "handle": "2019-01",
6
+ "display_name": "2019-01",
7
+ "supported": true,
8
+ "latest_supported": false
9
+ },{
10
+ "handle": "2019-04",
11
+ "latest_supported": false,
12
+ "display_name": "2019-04",
13
+ "supported": true
14
+ },
15
+ {
16
+ "handle": "2019-07",
17
+ "latest_supported": true,
18
+ "display_name": "2019-07 (Latest)",
19
+ "supported": true
20
+ },
21
+ {
22
+ "handle": "2019-10",
23
+ "latest_supported": false,
24
+ "display_name": "2019-10 (Release candidate)",
25
+ "supported": false
26
+ },
27
+ {
28
+ "handle": "unstable",
29
+ "latest_supported": false,
30
+ "display_name": "unstable",
31
+ "supported": false
32
+ }
33
+ ]
34
+ }
35
+ ]
36
+ }
@@ -0,0 +1,17 @@
1
+ {
2
+ "collection": {
3
+ "id": 1,
4
+ "handle": "test-collection",
5
+ "title": "test-collection",
6
+ "updated_at": "2016-03-17T16:58:37-04:00",
7
+ "body_html": null,
8
+ "published_at": "2016-03-17T16:58:37-04:00",
9
+ "sort_order": "alpha-asc",
10
+ "template_suffix": null,
11
+ "published_scope": "global",
12
+ "image": {
13
+ "created_at": "2016-03-17T16:58:37-04:00",
14
+ "src": "https:\/\/cdn.shopify.com\/s\/files\/1\/0006\/9093\/3842\/collections\/fd43f2c8883f6e9b680e3295fd990d2c.gif?v=1458248317"
15
+ }
16
+ }
17
+ }
@@ -0,0 +1,47 @@
1
+ {
2
+ "products": [
3
+ {
4
+ "product_type": "Cult Products",
5
+ "handle": "ipod-nano",
6
+ "created_at": "2011-10-20T14:05:13-04:00",
7
+ "body_html": "<p>It's the small iPod with one very big idea: Video. Now the world's most popular music player, available in 4GB and 8GB models, lets you enjoy TV shows, movies, video podcasts, and more. The larger, brighter display means amazing picture quality. In six eye-catching colors, iPod nano is stunning all around. And with models starting at just $149, little speaks volumes.</p>",
8
+ "title": "IPod Nano - 8GB",
9
+ "template_suffix": null,
10
+ "updated_at": "2011-10-20T14:05:13-04:00",
11
+ "id": 632910392,
12
+ "tags": "Emotive, Flash Memory, MP3, Music",
13
+ "images": [
14
+ {
15
+ "position": 1,
16
+ "created_at": "2011-10-20T14:05:13-04:00",
17
+ "product_id": 632910392,
18
+ "updated_at": "2011-10-20T14:05:13-04:00",
19
+ "src": "http://static.shopify.com/s/files/1/6909/3384/products/ipod-nano.png?0",
20
+ "id": 850703190
21
+ }
22
+ ],
23
+ "vendor": "Apple",
24
+ "published_at": "2007-12-31T19:00:00-05:00",
25
+ "manually_sorted": true,
26
+ "options": [
27
+ {
28
+ "name": "Title"
29
+ }
30
+ ]
31
+ },
32
+ {
33
+ "product_type": "Cult Products",
34
+ "handle": "ipod-touch",
35
+ "created_at": "2018-09-26T14:05:13-04:00",
36
+ "body_html": "<p>The iPod Touch has the iPhone's multi-touch interface, with a physical home button off the touch screen. The home screen has a list of buttons for the available applications.</p>",
37
+ "title": "IPod Touch 8GB",
38
+ "template_suffix": null,
39
+ "updated_at": "2018-09-26T14:05:13-04:00",
40
+ "id": 921728736,
41
+ "tags": null,
42
+ "vendor": "Apple",
43
+ "published_at": "2018-09-26T14:05:13-04:00",
44
+ "manually_sorted": true
45
+ }
46
+ ]
47
+ }
@@ -0,0 +1,43 @@
1
+ # frozen_string_literal: true
2
+ require 'test_helper'
3
+
4
+ class ApiVersionTest < Test::Unit::TestCase
5
+ test ".admin_versions returns array of api versions for admin" do
6
+ versions = [
7
+ {
8
+ "handle": "2019-01",
9
+ "display_name": "2019-01",
10
+ "supported": true,
11
+ "latest_supported": false,
12
+ },
13
+ {
14
+ "handle": "2019-04",
15
+ "latest_supported": false,
16
+ "display_name": "2019-04",
17
+ "supported": true,
18
+ },
19
+ {
20
+ "handle": "2019-07",
21
+ "latest_supported": true,
22
+ "display_name": "2019-07 (Latest)",
23
+ "supported": true,
24
+ },
25
+ {
26
+ "handle": "2019-10",
27
+ "latest_supported": false,
28
+ "display_name": "2019-10 (Release candidate)",
29
+ "supported": false,
30
+ },
31
+ {
32
+ "handle": "unstable",
33
+ "latest_supported": false,
34
+ "display_name": "unstable",
35
+ "supported": false,
36
+ },
37
+ ].to_json
38
+
39
+
40
+ assert_equal versions, ShopifyAPI::Meta.admin_versions.to_json
41
+
42
+ end
43
+ end
@@ -4,7 +4,7 @@ class PaginationTest < Test::Unit::TestCase
4
4
  def setup
5
5
  super
6
6
 
7
- @version = ShopifyAPI::ApiVersion::Release.new('2019-10')
7
+ @version = ShopifyAPI::ApiVersion.find_version('2019-10')
8
8
  ShopifyAPI::Base.api_version = @version.to_s
9
9
  @next_page_info = "eyJkaXJlY3Rpb24iOiJuZXh0IiwibGFzdF9pZCI6NDQwMDg5NDIzLCJsYXN0X3ZhbHVlIjoiNDQwMDg5NDIzIn0%3D"
10
10
  @previous_page_info = "eyJsYXN0X2lkIjoxMDg4MjgzMDksImxhc3RfdmFsdWUiOiIxMDg4MjgzMDkiLCJkaXJlY3Rpb24iOiJuZXh0In0%3D"
@@ -131,7 +131,7 @@ class PaginationTest < Test::Unit::TestCase
131
131
  end
132
132
 
133
133
  test "raises on an older API version" do
134
- version = ShopifyAPI::ApiVersion::Release.new('2019-04')
134
+ version = ShopifyAPI::ApiVersion.find_version('2019-04')
135
135
  ShopifyAPI::Base.api_version = version.to_s
136
136
 
137
137
  fake 'orders', :method => :get, :status => 200, api_version: version, :body => load_fixture('orders')
@@ -143,7 +143,7 @@ class PaginationTest < Test::Unit::TestCase
143
143
  end
144
144
 
145
145
  test "raises on 2019-07 API version for models that don't support new pagination yet" do
146
- version = ShopifyAPI::ApiVersion::Release.new('2019-07')
146
+ version = ShopifyAPI::ApiVersion.find_version('2019-07')
147
147
  ShopifyAPI::Base.api_version = version.to_s
148
148
 
149
149
  fake 'orders', :method => :get, :status => 200, api_version: version, :body => load_fixture('orders')
@@ -155,7 +155,7 @@ class PaginationTest < Test::Unit::TestCase
155
155
  end
156
156
 
157
157
  test "new pagination works on 2019-07 API version for select models" do
158
- version = ShopifyAPI::ApiVersion::Release.new('2019-07')
158
+ version = ShopifyAPI::ApiVersion.find_version('2019-07')
159
159
  ShopifyAPI::Base.api_version = version.to_s
160
160
 
161
161
  fake 'events', :method => :get, :status => 200, api_version: version, :body => load_fixture('events')
@@ -166,7 +166,7 @@ class PaginationTest < Test::Unit::TestCase
166
166
  end
167
167
 
168
168
  test "does not raise on the unstable version" do
169
- version = ShopifyAPI::ApiVersion::Unstable.new
169
+ version = ShopifyAPI::ApiVersion.find_version('unstable')
170
170
  ShopifyAPI::Base.api_version = version.to_s
171
171
  @next_link_header = "<https://this-is-my-test-shop.myshopify.com/admin/api/unstable/orders.json?page_info=#{@next_page_info}>; rel=\"next\""
172
172
 
@@ -39,7 +39,7 @@ class ProductListingTest < Test::Unit::TestCase
39
39
  end
40
40
 
41
41
  def test_get_product_listing_product_ids_multi_page_with_cursor
42
- version = ShopifyAPI::ApiVersion::Release.new('2019-10')
42
+ version = ShopifyAPI::ApiVersion.find_version('2019-10')
43
43
  ShopifyAPI::Base.api_version = version.to_s
44
44
 
45
45
  url = "https://this-is-my-test-shop.myshopify.com/admin/api/2019-10/product_listings/product_ids.json"
@@ -75,7 +75,7 @@ class ProductListingTest < Test::Unit::TestCase
75
75
  end
76
76
 
77
77
  def test_get_product_listing_product_ids_multi_page_with_cursor_fails_on_older_api_version
78
- version = ShopifyAPI::ApiVersion::Release.new('2019-07')
78
+ version = ShopifyAPI::ApiVersion.find_version('2019-07')
79
79
  ShopifyAPI::Base.api_version = version.to_s
80
80
 
81
81
  url = "https://this-is-my-test-shop.myshopify.com/admin/api/2019-07/product_listings/product_ids.json"
@@ -21,6 +21,9 @@ class SessionTest < Test::Unit::TestCase
21
21
  test "not be valid without an api version" do
22
22
  session = ShopifyAPI::Session.new(domain: "testshop.myshopify.com", token: "any-token", api_version: nil)
23
23
  assert_not session.valid?
24
+
25
+ session = ShopifyAPI::Session.new(domain: "testshop.myshopify.com", token: "any-token", api_version: ShopifyAPI::ApiVersion::NullVersion)
26
+ assert_not session.valid?
24
27
  end
25
28
 
26
29
  test "be valid with any token, any url and version" do
@@ -87,8 +90,8 @@ class SessionTest < Test::Unit::TestCase
87
90
  assert_equal('https://testshop.myshopify.com', @assigned_site.to_s)
88
91
  assert_equal('https://fakeshop.myshopify.com', ShopifyAPI::Base.site.to_s)
89
92
 
90
- assert_equal(ShopifyAPI::ApiVersion::Unstable.new, @assigned_version)
91
- assert_equal(ShopifyAPI::ApiVersion::Release.new('2019-01'), ShopifyAPI::Base.api_version)
93
+ assert_equal(ShopifyAPI::ApiVersion.new(handle: :unstable), @assigned_version)
94
+ assert_equal(ShopifyAPI::ApiVersion.new(handle: '2019-01'), ShopifyAPI::Base.api_version)
92
95
  end
93
96
 
94
97
  test "#with_session activates the session for the duration of the block" do
@@ -109,8 +112,8 @@ class SessionTest < Test::Unit::TestCase
109
112
  assert_equal('https://testshop.myshopify.com', @assigned_site.to_s)
110
113
  assert_equal('https://fakeshop.myshopify.com', ShopifyAPI::Base.site.to_s)
111
114
 
112
- assert_equal(ShopifyAPI::ApiVersion::Unstable.new, @assigned_version)
113
- assert_equal(ShopifyAPI::ApiVersion::Release.new('2019-01'), ShopifyAPI::Base.api_version)
115
+ assert_equal(ShopifyAPI::ApiVersion.new(handle: :unstable), @assigned_version)
116
+ assert_equal(ShopifyAPI::ApiVersion.new(handle: '2019-01'), ShopifyAPI::Base.api_version)
114
117
  end
115
118
 
116
119
  test "#with_session resets the activated session even if there an exception during the block" do
@@ -128,7 +131,7 @@ class SessionTest < Test::Unit::TestCase
128
131
  end
129
132
 
130
133
  assert_equal('https://fakeshop.myshopify.com', ShopifyAPI::Base.site.to_s)
131
- assert_equal(ShopifyAPI::ApiVersion::Release.new('2019-01'), ShopifyAPI::Base.api_version)
134
+ assert_equal(ShopifyAPI::ApiVersion.new(handle: '2019-01'), ShopifyAPI::Base.api_version)
132
135
  end
133
136
 
134
137
  test "#with_version will adjust the actvated api version for the duration of the block" do
@@ -143,8 +146,8 @@ class SessionTest < Test::Unit::TestCase
143
146
  assert_equal('https://fakeshop.myshopify.com', @assigned_site.to_s)
144
147
  assert_equal('https://fakeshop.myshopify.com', ShopifyAPI::Base.site.to_s)
145
148
 
146
- assert_equal(ShopifyAPI::ApiVersion::Unstable.new, @assigned_version)
147
- assert_equal(ShopifyAPI::ApiVersion::Release.new('2019-01'), ShopifyAPI::Base.api_version)
149
+ assert_equal(ShopifyAPI::ApiVersion.new(handle: :unstable), @assigned_version)
150
+ assert_equal(ShopifyAPI::ApiVersion.new(handle: '2019-01'), ShopifyAPI::Base.api_version)
148
151
  end
149
152
 
150
153
  test "create_permission_url returns correct url with single scope no redirect uri" do
@@ -240,7 +243,7 @@ class SessionTest < Test::Unit::TestCase
240
243
  end
241
244
 
242
245
  test "extra parameters are stored in session" do
243
- api_version = ShopifyAPI::ApiVersion::Unstable.new
246
+ api_version = ShopifyAPI::ApiVersion.new(handle: :unstable)
244
247
  fake nil,
245
248
  url: "https://testshop.myshopify.com/admin/oauth/access_token",
246
249
  method: :post,
@@ -345,6 +348,6 @@ class SessionTest < Test::Unit::TestCase
345
348
 
346
349
  def any_api_version
347
350
  version_name = ['2019-01', :unstable].sample(1).first
348
- ShopifyAPI::ApiVersion.coerce_to_version(version_name)
351
+ ShopifyAPI::ApiVersion.find_version(version_name)
349
352
  end
350
353
  end
@@ -7,9 +7,9 @@ require 'pry'
7
7
 
8
8
  $LOAD_PATH.unshift(File.dirname(__FILE__))
9
9
  $LOAD_PATH.unshift(File.join(File.dirname(__FILE__), '..', 'lib'))
10
- require 'shopify_api'
11
10
 
12
11
  WebMock.disable_net_connect!
12
+ require 'shopify_api'
13
13
 
14
14
  # setup ShopifyAPI with fake api_key and secret
15
15
  module Test
@@ -37,9 +37,16 @@ module Test
37
37
  end
38
38
  end
39
39
 
40
- ShopifyAPI::ApiVersion.define_version(ShopifyAPI::ApiVersion::Release.new('2019-01'))
41
-
42
40
  ShopifyAPI::Base.clear_session
41
+
42
+ fake("apis",
43
+ url: "https://app.shopify.com/services/apis.json",
44
+ method: :get,
45
+ status: 200,
46
+ api_version: :stub,
47
+ body: load_fixture('apis'))
48
+
49
+ ShopifyAPI::ApiVersion.fetch_known_versions
43
50
  session = ShopifyAPI::Session.new(
44
51
  domain: "https://this-is-my-test-shop.myshopify.com",
45
52
  token: "token_test_helper",
@@ -55,8 +62,8 @@ module Test
55
62
  ShopifyAPI::Base.password = nil
56
63
  ShopifyAPI::Base.user = nil
57
64
 
58
- ShopifyAPI::ApiVersion.clear_defined_versions
59
- ShopifyAPI::ApiVersion.define_known_versions
65
+ ShopifyAPI::ApiVersion.clear_known_versions
66
+ ShopifyAPI::ApiVersion.version_lookup_mode = :raise_on_unknown
60
67
  end
61
68
 
62
69
  # Custom Assertions
@@ -88,7 +95,7 @@ module Test
88
95
  body = options.has_key?(:body) ? options.delete(:body) : load_fixture(endpoint)
89
96
  format = options.delete(:format) || :json
90
97
  method = options.delete(:method) || :get
91
- api_version = options.delete(:api_version) || ShopifyAPI::ApiVersion.coerce_to_version('2019-01')
98
+ api_version = options.delete(:api_version) || ShopifyAPI::ApiVersion.find_version('2019-01')
92
99
  extension = ".#{options.delete(:extension)||'json'}" unless options[:extension]==false
93
100
  status = options.delete(:status) || 200
94
101
  url = if options.has_key?(:url)
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.1.0
4
+ version: 8.0.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-08-29 00:00:00.000000000 Z
11
+ date: 2019-09-05 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: activeresource
@@ -210,10 +210,10 @@ files:
210
210
  - lib/shopify_api/api_version.rb
211
211
  - lib/shopify_api/connection.rb
212
212
  - lib/shopify_api/countable.rb
213
- - lib/shopify_api/defined_versions.rb
214
213
  - lib/shopify_api/disable_prefix_check.rb
215
214
  - lib/shopify_api/events.rb
216
215
  - lib/shopify_api/limits.rb
216
+ - lib/shopify_api/meta.rb
217
217
  - lib/shopify_api/metafields.rb
218
218
  - lib/shopify_api/paginated_collection.rb
219
219
  - lib/shopify_api/pagination_link_headers.rb
@@ -236,6 +236,7 @@ files:
236
236
  - lib/shopify_api/resources/cart.rb
237
237
  - lib/shopify_api/resources/checkout.rb
238
238
  - lib/shopify_api/resources/collect.rb
239
+ - lib/shopify_api/resources/collection.rb
239
240
  - lib/shopify_api/resources/collection_listing.rb
240
241
  - lib/shopify_api/resources/collection_publication.rb
241
242
  - lib/shopify_api/resources/comment.rb
@@ -325,6 +326,7 @@ files:
325
326
  - test/collect_test.rb
326
327
  - test/collection_listing_test.rb
327
328
  - test/collection_publication_test.rb
329
+ - test/collection_test.rb
328
330
  - test/countable_test.rb
329
331
  - test/currency_test.rb
330
332
  - test/custom_collection_test.rb
@@ -337,6 +339,8 @@ files:
337
339
  - test/fixtures/abandoned_checkouts.json
338
340
  - test/fixtures/access_scopes.json
339
341
  - test/fixtures/access_token_delegate.json
342
+ - test/fixtures/api_versions.json
343
+ - test/fixtures/apis.json
340
344
  - test/fixtures/application_charge.json
341
345
  - test/fixtures/application_charges.json
342
346
  - test/fixtures/application_credit.json
@@ -353,10 +357,12 @@ files:
353
357
  - test/fixtures/checkout.json
354
358
  - test/fixtures/checkouts.json
355
359
  - test/fixtures/collect.json
360
+ - test/fixtures/collection.json
356
361
  - test/fixtures/collection_listing.json
357
362
  - test/fixtures/collection_listing_product_ids.json
358
363
  - test/fixtures/collection_listing_product_ids2.json
359
364
  - test/fixtures/collection_listings.json
365
+ - test/fixtures/collection_products.json
360
366
  - test/fixtures/collection_publication.json
361
367
  - test/fixtures/collection_publications.json
362
368
  - test/fixtures/currencies.json
@@ -450,6 +456,7 @@ files:
450
456
  - test/limits_test.rb
451
457
  - test/location_test.rb
452
458
  - test/marketing_event_test.rb
459
+ - test/meta_test.rb
453
460
  - test/metafield_test.rb
454
461
  - test/order_risk_test.rb
455
462
  - test/order_test.rb
@@ -1,11 +0,0 @@
1
- # frozen_string_literal: true
2
- module ShopifyAPI
3
- module DefinedVersions
4
- def define_known_versions
5
- define_version(ShopifyAPI::ApiVersion::Unstable.new)
6
- define_version(ShopifyAPI::ApiVersion::Release.new('2019-04'))
7
- define_version(ShopifyAPI::ApiVersion::Release.new('2019-07'))
8
- define_version(ShopifyAPI::ApiVersion::Release.new('2019-10'))
9
- end
10
- end
11
- end