gecko-ruby 0.11.1 → 0.12.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: d199e8dad0e8cfc71dab3994fd32e91d9862fbacd17e5ef33b7ea56042a0c47b
4
- data.tar.gz: d588aafb7703430db428da743fda7f5acab475759b5c45cb007f843b0fe41822
3
+ metadata.gz: ebfbdacb19b2e0dbc4478c614578298de91e01e1ee79d29ace8833da5ef5ce4d
4
+ data.tar.gz: 4d4e8551a79728045733fb7fa336a30b655e779c152ae7d0a8ec49af1c746aff
5
5
  SHA512:
6
- metadata.gz: ded7f2c92168eb1266b892d91d81902715893ba6df9c3b3d5b738b7655ea8a3a031046324718d170741b9dd9397316aa403d129234eed16dcfb5175ca0bc0dea
7
- data.tar.gz: 0c4684e13aef815bb59a2b09a49c7cb6625c9201a85af9b9cbad569a2291287a10dc2c9bdb006ac9a31581a1b3ae8bc8651ac0c1b30ba4090158799425578f1e
6
+ metadata.gz: 92333d13c62ab98a009c8d8a6396dcd89be342fa3d58fb152a024330f419d44d113aaa19aedbe34de10ba7a3741bb8fd54bab20ee6bb33597edee8131629f386
7
+ data.tar.gz: e74fb5237da5c6a1a023517c6cc8fa76f5f45f4674362f887ccb82d7887d159aa95f3e329a6faf65fa8bcdfe359874735791db1d3d1b08362e5c2a67afee28cb
@@ -1,3 +1,8 @@
1
+ ## 0.12.0 (2020-07-09)
2
+ - Silence warnings in Ruby 2.7
3
+ - Ensure response is passed to `ActiveSupport::Notifications` on error
4
+ - Ensure `adapter.last_response` is set on error response
5
+
1
6
  ## 0.11.1 (2020-04-30)
2
7
  - Fix addresses on Invoice
3
8
 
@@ -72,7 +72,7 @@ module Gecko
72
72
  []
73
73
  end
74
74
 
75
- build_collection_proxy(collection, {
75
+ build_collection_proxy(collection, **{
76
76
  embedded: options[:embedded],
77
77
  class_name: class_name,
78
78
  association_name: association_name
@@ -100,7 +100,7 @@ module Gecko
100
100
  #
101
101
  # @api private
102
102
  def build_collection_proxy(target, association_name:, class_name:, embedded:)
103
- CollectionProxy.new({
103
+ CollectionProxy.new(**{
104
104
  parent: self,
105
105
  target: target,
106
106
  embedded: embedded,
@@ -111,7 +111,7 @@ module Gecko
111
111
  #
112
112
  # @api public
113
113
  def where(params = {})
114
- response = @last_response = request(:get, plural_path, params: params)
114
+ response = request(:get, plural_path, params: params)
115
115
  parsed_response = response.parsed
116
116
  set_pagination(response.headers)
117
117
  parse_records(parsed_response)
@@ -203,7 +203,7 @@ module Gecko
203
203
  # @api private
204
204
  def fetch(id) # rubocop:disable Metrics/MethodLength
205
205
  verify_id_presence!(id)
206
- response = @last_response = request(:get, plural_path + '/' + id.to_s)
206
+ response = request(:get, plural_path + '/' + id.to_s)
207
207
  record_json = extract_record(response.parsed)
208
208
  instantiate_and_register_record(record_json)
209
209
  rescue OAuth2::Error => e
@@ -343,7 +343,7 @@ module Gecko
343
343
  #
344
344
  # @api private
345
345
  def create_record(record, opts = {})
346
- response = @last_response = request(:post, plural_path, {
346
+ response = request(:post, plural_path, {
347
347
  body: record.as_json,
348
348
  raise_errors: false
349
349
  }.merge(headers: headers_from_opts(opts)))
@@ -356,7 +356,7 @@ module Gecko
356
356
  #
357
357
  # @api private
358
358
  def update_record(record, opts = {})
359
- response = @last_response = request(:put, plural_path + "/" + record.id.to_s, {
359
+ response = request(:put, plural_path + "/" + record.id.to_s, {
360
360
  body: record.as_json,
361
361
  raise_errors: false
362
362
  }.merge(headers: headers_from_opts(opts)))
@@ -431,18 +431,24 @@ module Gecko
431
431
  # @return [OAuth2::Response]
432
432
  #
433
433
  # @api private
434
- def request(verb, path, options = {}) # rubocop:disable Metrics/MethodLength
434
+ def request(verb, path, options = {}) # rubocop:disable Metrics/AbcSize, Metrics/MethodLength
435
435
  ActiveSupport::Notifications.instrument('request.gecko') do |payload|
436
436
  payload[:verb] = verb
437
437
  payload[:params] = options[:params]
438
438
  payload[:body] = options[:body]
439
439
  payload[:model_class] = model_class
440
440
  payload[:request_path] = path
441
+
441
442
  options[:headers] = options.fetch(:headers, {}).tap do |headers|
442
443
  headers['Content-Type'] = 'application/json'
443
444
  end
444
- options[:body] = options[:body].to_json if options[:body]
445
- payload[:response] = @client.access_token.request(verb, path, options)
445
+
446
+ options[:body] = options[:body].to_json if options[:body]
447
+
448
+ @client.access_token.request(verb, path, options.merge(raise_errors: false)).tap do |response|
449
+ payload[:response] = @last_response = response
450
+ raise response.error if response.error && options[:raise_errors] != false
451
+ end
446
452
  end
447
453
  end
448
454
 
@@ -1,5 +1,5 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  module Gecko
4
- VERSION = '0.11.1'
4
+ VERSION = '0.12.0'
5
5
  end
@@ -147,7 +147,7 @@ module SharedAdapterExamples # rubocop:disable Metrics/ModuleLength
147
147
  def test_saving_record_with_idempotency_key # rubocop:disable Metrics/MethodLength
148
148
  record = adapter.build
149
149
  mock_token = mock
150
- mock_response = mock(status: 200, parsed: { plural_name.singularize => { id: 123 } })
150
+ mock_response = mock(status: 200, parsed: { plural_name.singularize => { id: 123 } }, error: nil)
151
151
  mock_token.expects(:request)
152
152
  .with(:post, plural_name, {
153
153
  body: record.as_json.to_json,
@@ -165,7 +165,7 @@ private
165
165
 
166
166
  def mock_api_request(record, request, response)
167
167
  mock_token = mock
168
- mock_response = mock(status: response[0], parsed: response[1])
168
+ mock_response = mock(status: response[0], parsed: response[1], error: nil)
169
169
  mock_token.expects(:request)
170
170
  .with(request[0], request[1], {
171
171
  body: record.as_json.to_json,
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: gecko-ruby
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.11.1
4
+ version: 0.12.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Bradley Priest
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2020-04-29 00:00:00.000000000 Z
11
+ date: 2020-07-09 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: bundler