shopify_api 8.0.0 → 8.1.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: 971668a584dc96aa673c1648c5c8da796e64adfd63a30515da9376b460efbd2a
4
- data.tar.gz: d161f78b00baaf4def4c4effc51a802143b483af08281afc043b93e0e8eba940
3
+ metadata.gz: c6b6467bc9d4c7e3180f0385a0b7c6f75921b391659e7d0566796fb34f5fe63d
4
+ data.tar.gz: 6bcd7084be9a692d3e960c5659b4ed4e25abd629e6f91f58faa9934f55f720a1
5
5
  SHA512:
6
- metadata.gz: ca615cd5b6ea53fccc3cd75a0ff4f994ceb6c086034232f36c64a1e2d11abe948faa12cf4b63603e2d9d98f2714038199950b2baa0561dde343b042f551b49e0
7
- data.tar.gz: 9043ff8baf6e9f22f536c0ca68d85ba96d542648aea47da73a35909c86949036be7b310de82fa266a689786af7b9ca15c975677f048b70e64fb1399197161b80
6
+ metadata.gz: 4ab61dddb0c4fe44d89c9bced7e328c8e76932c9876803d2aeef6ea0a7c9eace8eaa728841f9445a2c59e53b555d8c16c40b4ed881b8630069f2e8343c2f3971
7
+ data.tar.gz: 5808669808de2b254c33d2a0d4f120f9b47a4868bb992575824f2a9348ecd74a1c54231b3ed821e694de1c2ed63ae6653c5138b6e86874d88c2a10fcee080965
data/CHANGELOG.md CHANGED
@@ -1,3 +1,12 @@
1
+ == Version 8.1.0
2
+
3
+ * Release 2020-01 REST ADMIN API VERSION [#656](https://github.com/Shopify/shopify_api/pull/656)
4
+ * Release new Endpoint `collection.products` and `collection.find()` in 2020-01 REST API version [#657](https://github.com/Shopify/shopify_api/pull/657)
5
+ * Enrich 4xx errors with error message from response body [#647](https://github.com/Shopify/shopify_api/pull/647)
6
+ * Make relative cursor based pagination work across page loads [#625](https://github.com/Shopify/shopify_api/pull/625)
7
+ * Small ruby compat fix [#623](https://github.com/Shopify/shopify_api/pull/623)
8
+ * Small consistency change [#621](https://github.com/Shopify/shopify_api/pull/621)
9
+
1
10
  == Version 8.0.0
2
11
 
3
12
  * Api Version changes [#600](https://github.com/Shopify/shopify_api/pull/600)
@@ -27,9 +27,9 @@ module ActiveResource
27
27
  payload[:response].each do |header_name, header_value|
28
28
  case header_name.downcase
29
29
  when 'x-shopify-api-deprecated-reason'
30
- warning_message = <<~MSG
31
- [DEPRECATED] ShopifyAPI made a call to #{payload[:method].upcase} #{payload[:path]}, and this call made
32
- use of a deprecated endpoint, behaviour, or parameter. See #{header_value} for more details.
30
+ warning_message = <<-MSG
31
+ [DEPRECATED] ShopifyAPI made a call to #{payload[:method].upcase} #{payload[:path]}, and this call made
32
+ use of a deprecated endpoint, behaviour, or parameter. See #{header_value} for more details.
33
33
  MSG
34
34
 
35
35
  warn warning_message
data/lib/shopify_api.rb CHANGED
@@ -20,6 +20,7 @@ require 'shopify_api/metafields'
20
20
  require 'shopify_api/countable'
21
21
  require 'shopify_api/resources'
22
22
  require 'shopify_api/session'
23
+ require 'shopify_api/message_enricher'
23
24
  require 'shopify_api/connection'
24
25
  require 'shopify_api/pagination_link_headers'
25
26
 
@@ -4,7 +4,7 @@ module ShopifyAPI
4
4
 
5
5
  module ResponseCapture
6
6
  def handle_response(response)
7
- @response = super
7
+ @response = super(ShopifyAPI::MessageEnricher.new(response))
8
8
  end
9
9
  end
10
10
 
@@ -0,0 +1,17 @@
1
+ module ShopifyAPI
2
+ class MessageEnricher < SimpleDelegator
3
+ def message
4
+ return super unless (400...500).include?(code.to_i)
5
+
6
+ @_cached_message ||= begin
7
+ detailed_error = begin
8
+ JSON.parse(body)['error'].to_s
9
+ rescue JSON::ParserError
10
+ nil
11
+ end
12
+
13
+ detailed_error.present? ? "#{super} (#{detailed_error})" : super
14
+ end
15
+ end
16
+ end
17
+ end
@@ -27,6 +27,14 @@ module ShopifyAPI
27
27
  fetch_page(@previous_url)
28
28
  end
29
29
 
30
+ def next_page_info
31
+ extract_page_info(@next_url)
32
+ end
33
+
34
+ def previous_page_info
35
+ extract_page_info(@previous_url)
36
+ end
37
+
30
38
  private
31
39
 
32
40
  AVAILABLE_IN_VERSION = ShopifyAPI::ApiVersion.find_version('2019-10')
@@ -50,6 +58,10 @@ module ShopifyAPI
50
58
  return if ShopifyAPI::Base.api_version >= AVAILABLE_IN_VERSION_EARLY && resource_class.early_july_pagination?
51
59
  raise NotImplementedError
52
60
  end
61
+
62
+ def extract_page_info(url)
63
+ CGI.escape(Rack::Utils.parse_query(URI(url).query)['page_info']) if url.present?
64
+ end
53
65
  end
54
66
 
55
67
  include CollectionPagination
@@ -6,7 +6,7 @@ module ShopifyAPI
6
6
  include Metafields
7
7
 
8
8
  def products(options = {})
9
- available_in_version = ShopifyAPI::ApiVersion.find_version(:unstable)
9
+ available_in_version = ShopifyAPI::ApiVersion.find_version('2020-01')
10
10
  raise NotImplementedError unless ShopifyAPI::Base.api_version >= available_in_version
11
11
  Product.find(:all, from: "#{self.class.prefix}collections/#{id}/products.json", params: options)
12
12
  end
@@ -104,7 +104,7 @@ module ShopifyAPI
104
104
  raise ShopifyAPI::ValidationException, "Invalid Signature: Possible malicious login"
105
105
  end
106
106
 
107
- response = access_token_request(params['code'])
107
+ response = access_token_request(params[:code])
108
108
  if response.code == "200"
109
109
  self.extra = JSON.parse(response.body)
110
110
  self.token = extra.delete('access_token')
@@ -1,3 +1,3 @@
1
1
  module ShopifyAPI
2
- VERSION = "8.0.0"
2
+ VERSION = "8.1.0"
3
3
  end
@@ -22,15 +22,15 @@ class ApiVersionTest < Test::Unit::TestCase
22
22
  test "find_version removes unverified versions from version set if mode is set to :raise_on_unknown" do
23
23
  ShopifyAPI::ApiVersion.version_lookup_mode = :define_on_unknown
24
24
  assert ShopifyAPI::ApiVersion.versions.values.all?(&:verified?)
25
- assert_equal 5, ShopifyAPI::ApiVersion.versions.size
25
+ assert_equal 6, ShopifyAPI::ApiVersion.versions.size
26
26
 
27
27
  ShopifyAPI::ApiVersion.find_version('2019-30')
28
28
  refute ShopifyAPI::ApiVersion.versions.values.all?(&:verified?)
29
- assert_equal 6, ShopifyAPI::ApiVersion.versions.size
29
+ assert_equal 7, ShopifyAPI::ApiVersion.versions.size
30
30
  ShopifyAPI::ApiVersion.version_lookup_mode = :raise_on_unknown
31
31
 
32
32
  assert ShopifyAPI::ApiVersion.versions.values.all?(&:verified?)
33
- assert_equal 5, ShopifyAPI::ApiVersion.versions.size
33
+ assert_equal 6, ShopifyAPI::ApiVersion.versions.size
34
34
  end
35
35
 
36
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
@@ -101,8 +101,9 @@ class ApiVersionTest < Test::Unit::TestCase
101
101
  {
102
102
  "2019-01" => ShopifyAPI::ApiVersion.new(handle: '2019-01', supported: true, latest_supported: false),
103
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),
104
+ "2019-07" => ShopifyAPI::ApiVersion.new(handle: '2019-07', supported: true, latest_supported: false),
105
105
  "2019-10" => ShopifyAPI::ApiVersion.new(handle: '2019-10', supported: false, latest_supported: false),
106
+ "2020-01" => ShopifyAPI::ApiVersion.new(handle: '2020-01', supported: false, latest_supported: true),
106
107
  "unstable" => ShopifyAPI::ApiVersion.new(handle: 'unstable', supported: false, latest_supported: false),
107
108
  }
108
109
  )
@@ -114,7 +115,7 @@ class ApiVersionTest < Test::Unit::TestCase
114
115
  )
115
116
 
116
117
  assert_equal(
117
- ShopifyAPI::ApiVersion.new(handle: '2019-07'),
118
+ ShopifyAPI::ApiVersion.new(handle: '2020-01'),
118
119
  ShopifyAPI::ApiVersion.latest_stable_version
119
120
  )
120
121
  end
@@ -1,13 +1,13 @@
1
1
  require 'test_helper'
2
2
 
3
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)
4
+ test "Collection get products gets all products in a collection on 2020-01 version" do
5
+ available_version = ShopifyAPI::Session.new(domain: 'shop2.myshopify.com', token: 'token2', api_version: '2020-01')
6
+ ShopifyAPI::Base.activate_session(available_version)
7
7
 
8
8
  fake(
9
9
  'collections',
10
- url: 'https://shop2.myshopify.com/admin/api/unstable/collections/1.json',
10
+ url: 'https://shop2.myshopify.com/admin/api/2020-01/collections/1.json',
11
11
  method: :get,
12
12
  status: 200,
13
13
  body: load_fixture('collection'),
@@ -18,7 +18,7 @@ class CollectionTest < Test::Unit::TestCase
18
18
 
19
19
  fake(
20
20
  'products',
21
- url: 'https://shop2.myshopify.com/admin/api/unstable/collections/1/products.json',
21
+ url: 'https://shop2.myshopify.com/admin/api/2020-01/collections/1/products.json',
22
22
  method: :get,
23
23
  status: 200,
24
24
  body: load_fixture('collection_products'),
@@ -28,12 +28,12 @@ class CollectionTest < Test::Unit::TestCase
28
28
  end
29
29
 
30
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)
31
+ old_version = ShopifyAPI::Session.new(domain: 'shop2.myshopify.com', token: 'token2', api_version: '2019-10')
32
+ ShopifyAPI::Base.activate_session(old_version)
33
33
 
34
34
  fake(
35
35
  'collections',
36
- url: 'https://shop2.myshopify.com/admin/api/2019-07/collections/1.json',
36
+ url: 'https://shop2.myshopify.com/admin/api/2019-10/collections/1.json',
37
37
  method: :get,
38
38
  status: 200,
39
39
  body: load_fixture('collection'),
@@ -7,26 +7,32 @@
7
7
  },
8
8
  {
9
9
  "handle": "2019-04",
10
+ "latest_supported": false,
10
11
  "display_name": "2019-04",
11
- "supported": true,
12
- "latest_supported": false
12
+ "supported": true
13
13
  },
14
14
  {
15
15
  "handle": "2019-07",
16
- "display_name": "2019-07 (Latest)",
17
- "supported": true,
18
- "latest_supported": true
16
+ "latest_supported": false,
17
+ "display_name": "2019-07",
18
+ "supported": true
19
19
  },
20
20
  {
21
21
  "handle": "2019-10",
22
- "display_name": "2019-10 (Release candidate)",
23
- "supported": false,
24
- "latest_supported": false
22
+ "latest_supported": false,
23
+ "display_name": "2019-10",
24
+ "supported": true
25
+ },
26
+ {
27
+ "handle": "2020-01",
28
+ "latest_supported": true,
29
+ "display_name": "2020-01 (Latest)",
30
+ "supported": true
25
31
  },
26
32
  {
27
33
  "handle": "unstable",
34
+ "latest_supported": false,
28
35
  "display_name": "unstable",
29
- "supported": false,
30
- "latest_supported": false
36
+ "supported": false
31
37
  }
32
38
  ]
@@ -14,15 +14,21 @@
14
14
  },
15
15
  {
16
16
  "handle": "2019-07",
17
- "latest_supported": true,
18
- "display_name": "2019-07 (Latest)",
17
+ "latest_supported": false,
18
+ "display_name": "2019-07",
19
19
  "supported": true
20
20
  },
21
21
  {
22
22
  "handle": "2019-10",
23
23
  "latest_supported": false,
24
- "display_name": "2019-10 (Release candidate)",
25
- "supported": false
24
+ "display_name": "2019-10",
25
+ "supported": true
26
+ },
27
+ {
28
+ "handle": "2020-01",
29
+ "latest_supported": true,
30
+ "display_name": "2020-01 (Latest)",
31
+ "supported": true
26
32
  },
27
33
  {
28
34
  "handle": "unstable",
@@ -0,0 +1,33 @@
1
+ require 'test_helper'
2
+
3
+ class MessageEnricherTest < Test::Unit::TestCase
4
+
5
+ def test_enriches_initial_message_when_body_is_passed
6
+ response = enriched_response(422, 'InitialMessage', { error: 'My Error' })
7
+
8
+ assert_equal 'InitialMessage (My Error)', response.message
9
+ end
10
+
11
+ def test_returns_initial_message_when_code_is_200
12
+ response = enriched_response(200, 'InitialMessage', { result: 'Success' })
13
+
14
+ assert_equal 'InitialMessage', response.message
15
+ end
16
+
17
+ def test_returns_initial_message_when_body_cant_be_parsed
18
+ response = enriched_response(422, 'InitialMessage', 'not a json')
19
+
20
+ assert_equal 'InitialMessage', response.message
21
+ end
22
+
23
+ private
24
+
25
+ def enriched_response(code, message, body)
26
+ mock_response =
27
+ Struct
28
+ .new(:code, :message, :body)
29
+ .new(code.to_s, message.to_s, body.to_json)
30
+
31
+ ShopifyAPI::MessageEnricher.new(mock_response)
32
+ end
33
+ end
data/test/meta_test.rb CHANGED
@@ -8,32 +8,38 @@ class ApiVersionTest < Test::Unit::TestCase
8
8
  "handle": "2019-01",
9
9
  "display_name": "2019-01",
10
10
  "supported": true,
11
- "latest_supported": false,
11
+ "latest_supported": false
12
12
  },
13
13
  {
14
14
  "handle": "2019-04",
15
15
  "latest_supported": false,
16
16
  "display_name": "2019-04",
17
- "supported": true,
17
+ "supported": true
18
18
  },
19
19
  {
20
20
  "handle": "2019-07",
21
- "latest_supported": true,
22
- "display_name": "2019-07 (Latest)",
23
- "supported": true,
21
+ "latest_supported": false,
22
+ "display_name": "2019-07",
23
+ "supported": true
24
24
  },
25
25
  {
26
26
  "handle": "2019-10",
27
27
  "latest_supported": false,
28
- "display_name": "2019-10 (Release candidate)",
29
- "supported": false,
28
+ "display_name": "2019-10",
29
+ "supported": true
30
+ },
31
+ {
32
+ "handle": "2020-01",
33
+ "latest_supported": true,
34
+ "display_name": "2020-01 (Latest)",
35
+ "supported": true
30
36
  },
31
37
  {
32
38
  "handle": "unstable",
33
39
  "latest_supported": false,
34
40
  "display_name": "unstable",
35
- "supported": false,
36
- },
41
+ "supported": false
42
+ }
37
43
  ].to_json
38
44
 
39
45
 
@@ -97,6 +97,20 @@ class PaginationTest < Test::Unit::TestCase
97
97
  refute orders.next_page?
98
98
  end
99
99
 
100
+ test "#next_page_info returns next_page_info if next page is present" do
101
+ fake 'orders', :method => :get, :status => 200, api_version: @version, :body => load_fixture('orders'), :link => @next_link_header
102
+ orders = ShopifyAPI::Order.all
103
+
104
+ assert_equal @next_page_info, orders.next_page_info
105
+ end
106
+
107
+ test "#next_page_info returns nil if next page is not present" do
108
+ fake 'orders', :method => :get, :status => 200, api_version: @version, :body => load_fixture('orders'), :link => @previous_link_header
109
+ orders = ShopifyAPI::Order.all
110
+
111
+ assert_nil orders.next_page_info
112
+ end
113
+
100
114
  test "#previous_page? returns true if previous page is present" do
101
115
  fake 'orders', :method => :get, :status => 200, api_version: @version, :body => load_fixture('orders'), :link => @previous_link_header
102
116
  orders = ShopifyAPI::Order.all
@@ -111,6 +125,20 @@ class PaginationTest < Test::Unit::TestCase
111
125
  refute orders.previous_page?
112
126
  end
113
127
 
128
+ test "#previous_page_info returns previous_page_info if next page is present" do
129
+ fake 'orders', :method => :get, :status => 200, api_version: @version, :body => load_fixture('orders'), :link => @previous_link_header
130
+ orders = ShopifyAPI::Order.all
131
+
132
+ assert_equal @previous_page_info, orders.previous_page_info
133
+ end
134
+
135
+ test "#previous_page_info returns nil if next page is not present" do
136
+ fake 'orders', :method => :get, :status => 200, api_version: @version, :body => load_fixture('orders'), :link => @next_link_header
137
+ orders = ShopifyAPI::Order.all
138
+
139
+ assert_nil orders.previous_page_info
140
+ end
141
+
114
142
  test "pagination handles no link headers" do
115
143
  fake 'orders', :method => :get, :status => 200, api_version: @version, :body => load_fixture('orders')
116
144
  orders = ShopifyAPI::Order.all
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: 8.0.0
4
+ version: 8.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-09-05 00:00:00.000000000 Z
11
+ date: 2019-12-23 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: activeresource
@@ -213,6 +213,7 @@ files:
213
213
  - lib/shopify_api/disable_prefix_check.rb
214
214
  - lib/shopify_api/events.rb
215
215
  - lib/shopify_api/limits.rb
216
+ - lib/shopify_api/message_enricher.rb
216
217
  - lib/shopify_api/meta.rb
217
218
  - lib/shopify_api/metafields.rb
218
219
  - lib/shopify_api/paginated_collection.rb
@@ -456,6 +457,7 @@ files:
456
457
  - test/limits_test.rb
457
458
  - test/location_test.rb
458
459
  - test/marketing_event_test.rb
460
+ - test/message_enricher_test.rb
459
461
  - test/meta_test.rb
460
462
  - test/metafield_test.rb
461
463
  - test/order_risk_test.rb