shopify_api 9.0.0 → 9.0.1

Sign up to get free protection for your applications and to get access to all the features.
@@ -1,8 +1,10 @@
1
1
  module ActiveResource
2
2
  class DetailedLogSubscriber < ActiveSupport::LogSubscriber
3
+ VERSION_EOL_WARNING_HEADER = 'x-shopify-api-version-warning'
4
+ VERSION_DEPRECATION_HEADER = 'x-shopify-api-deprecated-reason'
3
5
  def request(event)
4
6
  log_request_response_details(event)
5
- warn_on_deprecated_header(event)
7
+ warn_on_deprecated_header_or_version_eol_header(event)
6
8
  end
7
9
 
8
10
  def logger
@@ -21,17 +23,25 @@ module ActiveResource
21
23
  info "Response:\n#{event.payload[:response].body}"
22
24
  end
23
25
 
24
- def warn_on_deprecated_header(event)
26
+ def warn_on_deprecated_header_or_version_eol_header(event)
25
27
  payload = event.payload
26
28
 
27
29
  payload[:response].each do |header_name, header_value|
28
30
  case header_name.downcase
29
- when 'x-shopify-api-deprecated-reason'
31
+ when VERSION_DEPRECATION_HEADER
30
32
  warning_message = <<-MSG
31
33
  [DEPRECATED] ShopifyAPI made a call to #{payload[:method].upcase} #{payload[:path]}, and this call made
32
34
  use of a deprecated endpoint, behaviour, or parameter. See #{header_value} for more details.
33
35
  MSG
34
36
 
37
+ warn warning_message
38
+
39
+ when VERSION_EOL_WARNING_HEADER
40
+ warning_message = <<-MSG
41
+ [API Version Warning] ShopifyAPI made a call to #{payload[:method].upcase} #{payload[:path]}, and this call used
42
+ an API version that is unsupported or will become unsupported within 30 days. See #{header_value} for more details.
43
+ MSG
44
+
35
45
  warn warning_message
36
46
  end
37
47
  end
@@ -5,7 +5,13 @@ module ShopifyAPI
5
5
 
6
6
  @_cached_message ||= begin
7
7
  detailed_error = begin
8
- JSON.parse(body)['error'].to_s
8
+ parsed_body = JSON.parse(body)
9
+
10
+ if parsed_body['error']
11
+ parsed_body['error'].to_s
12
+ elsif parsed_body['errors']
13
+ Array(parsed_body['errors']).join('; ')
14
+ end
9
15
  rescue JSON::ParserError
10
16
  nil
11
17
  end
@@ -1,3 +1,3 @@
1
1
  module ShopifyAPI
2
- VERSION = "9.0.0"
2
+ VERSION = "9.0.1"
3
3
  end
@@ -114,4 +114,26 @@ class LogSubscriberTest < Test::Unit::TestCase
114
114
  @logger.logged(:warn).first
115
115
  )
116
116
  end
117
+
118
+ test "warns when the server responds with a x-shopify-api-version-warning header" do
119
+ fake(
120
+ "pages/1",
121
+ method: :get,
122
+ body: @page,
123
+ x_shopify_api_version_warning: 'https://shopify.dev/concepts/about-apis/versioning'
124
+ )
125
+
126
+ ShopifyAPI::Page.find(1)
127
+
128
+ assert_equal 1, @logger.logged(:warn).size
129
+
130
+ assert_match(
131
+ %r{\[API Version Warning\] ShopifyAPI made a call to GET /admin/api/2019-01/pages/1.json},
132
+ @logger.logged(:warn).first
133
+ )
134
+ assert_match(
135
+ %r{See https:\/\/shopify.dev\/concepts\/about-apis\/versioning for more details.},
136
+ @logger.logged(:warn).first
137
+ )
138
+ end
117
139
  end
@@ -2,12 +2,24 @@ require 'test_helper'
2
2
 
3
3
  class MessageEnricherTest < Test::Unit::TestCase
4
4
 
5
- def test_enriches_initial_message_when_body_is_passed
5
+ def test_enriches_initial_message_when_body_contains_error
6
6
  response = enriched_response(422, 'InitialMessage', { error: 'My Error' })
7
7
 
8
8
  assert_equal 'InitialMessage (My Error)', response.message
9
9
  end
10
10
 
11
+ def test_enriches_initial_message_when_body_contains_errors_array
12
+ response = enriched_response(422, 'InitialMessage', { errors: ['My Error1', 'My Error2'] })
13
+
14
+ assert_equal 'InitialMessage (My Error1; My Error2)', response.message
15
+ end
16
+
17
+ def test_enriches_initial_message_when_body_contains_errors_single_value
18
+ response = enriched_response(422, 'InitialMessage', { errors: 'My Error1' })
19
+
20
+ assert_equal 'InitialMessage (My Error1)', response.message
21
+ end
22
+
11
23
  def test_returns_initial_message_when_code_is_200
12
24
  response = enriched_response(200, 'InitialMessage', { result: 'Success' })
13
25
 
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: 9.0.0
4
+ version: 9.0.1
5
5
  platform: ruby
6
6
  authors:
7
7
  - Shopify
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2020-01-27 00:00:00.000000000 Z
11
+ date: 2020-02-24 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: activeresource