api_client_base 1.7.0 → 1.11.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: a3f8720f9cc4a7e78d381e5d5daf8f09ba26337a10d774d79f5999ada7f0c6f3
4
- data.tar.gz: 51720f6e8feceded8672331f3cd353869c9c82f1e5e1cab91a9c94ccc428f35f
3
+ metadata.gz: e748c8549dc84cfd16776fe9a92be6aafb043328916a80d88c5dbfd08e7b75d2
4
+ data.tar.gz: 145246c9dac0f31dace95aa41cf2b0183e706cfe112ba05831b7673f8ab8bd2e
5
5
  SHA512:
6
- metadata.gz: dfe2012281611438c8fd924a8777e6262d9259842fe49920c9dacde9d544e9278bc22b27bd8bc01bb6462cf7bd1eee3c3d862bd5bba6763d0570407160a53b41
7
- data.tar.gz: ff934bd6e815e670530926337c83e764ab9f27631f2a4df3b07222c1bf65f05516a51aaf603ab6b0bfa52849f06ea0b1f37c20d353bb138712652ac4c68c6549
6
+ metadata.gz: 418ac87d1b08d87a1f2931a977f88c7da8f4a2ddbe49d0d7d3933be3fc73a2f598358aa8eae468023b50ff677319f044efbf303dc0d246d4d6e6131affcedbcf
7
+ data.tar.gz: 3351c32d99bed922cb89e388ad815976819a09cf46bf8e995fd9fdfb0df1600fe5c88e13500401dca83c7c7d3203dbd224ec9a9d02287b2cb950386a4aec10cc
@@ -0,0 +1,37 @@
1
+ # This workflow uses actions that are not certified by GitHub.
2
+ # They are provided by a third-party and are governed by
3
+ # separate terms of service, privacy policy, and support
4
+ # documentation.
5
+ # This workflow will download a prebuilt Ruby version, install dependencies and run tests with Rake
6
+ # For more information see: https://github.com/marketplace/actions/setup-ruby-jruby-and-truffleruby
7
+
8
+ name: Ruby
9
+
10
+ on:
11
+ push:
12
+ branches: [ master ]
13
+ pull_request:
14
+ branches: [ master ]
15
+
16
+ jobs:
17
+ test:
18
+
19
+ runs-on: ubuntu-latest
20
+ strategy:
21
+ matrix:
22
+ ruby-version: ['2.6', '2.7']
23
+
24
+ steps:
25
+ - uses: actions/checkout@v2
26
+ - name: Set up Ruby
27
+ # To automatically get bug fixes and new Ruby versions for ruby/setup-ruby,
28
+ # change this to (see https://github.com/ruby/setup-ruby#versioning):
29
+ # uses: ruby/setup-ruby@v1
30
+ uses: ruby/setup-ruby@473e4d8fe5dd94ee328fdfca9f8c9c7afc9dae5e
31
+ with:
32
+ ruby-version: ${{ matrix.ruby-version }}
33
+ bundler-cache: true # runs 'bundle install' and caches installed gems automatically
34
+ - name: Install appraisal gems
35
+ run: bundle exec appraisal install
36
+ - name: Run tests
37
+ run: bundle exec appraisal rspec
data/Appraisals ADDED
@@ -0,0 +1,7 @@
1
+ appraise "dry-validation-0.x" do
2
+ gem "dry-validation", "~> 0.13"
3
+ end
4
+
5
+ appraise "dry-validation-1.x" do
6
+ gem "dry-validation", "~> 1.6"
7
+ end
data/CHANGELOG.md CHANGED
@@ -4,6 +4,23 @@ All notable changes to this project will be documented in this file.
4
4
  The format is based on [Keep a Changelog](http://keepachangelog.com/)
5
5
  and this project adheres to [Semantic Versioning](http://semver.org/).
6
6
 
7
+ ## [1.11.0] - 2021-11-26
8
+ ### Added
9
+ - `after_response` hook
10
+ - Add `#headers` and `#header(key)` methods to response for easy access to the headers
11
+
12
+ ## [1.10.0] - 2021-06-15
13
+ ### Added
14
+ - `dry-validation` 1.x support (0.x support has not been dropped)
15
+
16
+ ## [1.9.0] - 2020-06-30
17
+ ### Added
18
+ - Allow users to override typhoeus_options to pass any args that we haven't defined
19
+
20
+ ## [1.8.0] - 2020-06-30
21
+ ### Added
22
+ - Allow all Typhoeus options to be passed to BuildTyphoeusOptions. This is useful when overriding the method `typhoeus_options` in requests
23
+
7
24
  ## [1.7.0] - 2020-04-15
8
25
  ### Added
9
26
  - Add `Response#body` which is `raw_response`'s `body`
data/Gemfile CHANGED
@@ -3,7 +3,5 @@ source 'https://rubygems.org'
3
3
  # Specify your gem's dependencies in api_client_base.gemspec
4
4
  gemspec
5
5
 
6
- ruby "2.6.3"
7
-
8
6
  gem "pry-byebug", "~> 3.9"
9
7
  gem "typhoeus"
data/README.md CHANGED
@@ -42,6 +42,8 @@ MyGem.configure do |c|
42
42
  end
43
43
  ```
44
44
 
45
+ Note: there is a default configuration setting called `after_response`. See the "Response hooks" section for more details.
46
+
45
47
  - instantiate `MyGem::Client` by calling `MyGem.new(host: "https://api.com", username: "user", password: "password")`. If you do not specify an option, it will use the gem's default.
46
48
 
47
49
  ### Configuring the `Client`
@@ -240,7 +242,36 @@ module MyGem
240
242
  end
241
243
  ```
242
244
 
243
- You can an example gem at https://github.com/imacchiato/bridge_client-ruby.
245
+ You can an example gem [here](https://github.com/bloom-solutions/binance_client-ruby).
246
+
247
+ #### Response hooks
248
+
249
+ If you want to give the applications access to the request and response objects after each response (useful when tracking rate limits that are reported in the response, for example), then:
250
+
251
+ ```ruby
252
+ MyGem.configure do |c|
253
+ c.after_request = ->(request, response) do
254
+ if response.header("remaining-requets") < 20
255
+ Rails.logger.warn "mayday!"
256
+ end
257
+ end
258
+ end
259
+ ```
260
+
261
+ Note: the request and response objects are the request and response instances such as:
262
+ - `GetUserResponse`
263
+ - `GetUserRequest`
264
+
265
+ You can assign any object that response to `call`:
266
+
267
+ ```ruby
268
+ class AfterMyGemResponse
269
+ def self.call(request, response)
270
+ end
271
+ end
272
+ ```
273
+
274
+ Note: avoid putting long running/expensive requests here because this will block the Ruby process.
244
275
 
245
276
  ## Development
246
277
 
@@ -250,7 +281,7 @@ To install this gem onto your local machine, run `bundle exec rake install`. To
250
281
 
251
282
  ## Contributing
252
283
 
253
- Bug reports and pull requests are welcome on GitHub at https://github.com/imacchiato/api_client-ruby. This project is intended to be a safe, welcoming space for collaboration, and contributors are expected to adhere to the [Contributor Covenant](http://contributor-covenant.org) code of conduct.
284
+ Bug reports and pull requests are welcome on GitHub at https://github.com/bloom-solutions/api_client-ruby. This project is intended to be a safe, welcoming space for collaboration, and contributors are expected to adhere to the [Contributor Covenant](http://contributor-covenant.org) code of conduct.
254
285
 
255
286
  ## License
256
287
 
@@ -11,7 +11,7 @@ Gem::Specification.new do |spec|
11
11
 
12
12
  spec.summary = %q{Abstractions to help author API wrappers in Ruby.}
13
13
  spec.description = %q{Abstractions to help author API wrappers in Ruby.}
14
- spec.homepage = "https://github.com/imacchiato/api_client-ruby"
14
+ spec.homepage = "https://github.com/bloom-solutions/api_client-ruby"
15
15
  spec.license = "MIT"
16
16
 
17
17
  # Prevent pushing this gem to RubyGems.org. To allow pushes either set the 'allowed_push_host'
@@ -40,5 +40,6 @@ Gem::Specification.new do |spec|
40
40
  spec.add_development_dependency "virtus-matchers"
41
41
  spec.add_development_dependency "vcr", "~> 3.0"
42
42
  spec.add_development_dependency "webmock"
43
- spec.add_development_dependency "dry-validation", "< 1.0"
43
+ spec.add_development_dependency "dry-validation", "< 2.0"
44
+ spec.add_development_dependency "appraisal"
44
45
  end
@@ -0,0 +1,2 @@
1
+ ---
2
+ BUNDLE_RETRY: "1"
@@ -0,0 +1,9 @@
1
+ # This file was generated by Appraisal
2
+
3
+ source "https://rubygems.org"
4
+
5
+ gem "pry-byebug", "~> 3.9"
6
+ gem "typhoeus"
7
+ gem "dry-validation", "~> 0.13"
8
+
9
+ gemspec path: "../"
@@ -0,0 +1,140 @@
1
+ PATH
2
+ remote: ..
3
+ specs:
4
+ api_client_base (1.9.0)
5
+ activesupport (>= 3.0)
6
+ gem_config (>= 0.3.1)
7
+ virtus (>= 1.0)
8
+
9
+ GEM
10
+ remote: https://rubygems.org/
11
+ specs:
12
+ activesupport (6.1.3.1)
13
+ concurrent-ruby (~> 1.0, >= 1.0.2)
14
+ i18n (>= 1.6, < 2)
15
+ minitest (>= 5.1)
16
+ tzinfo (~> 2.0)
17
+ zeitwerk (~> 2.3)
18
+ addressable (2.7.0)
19
+ public_suffix (>= 2.0.2, < 5.0)
20
+ appraisal (2.4.0)
21
+ bundler
22
+ rake
23
+ thor (>= 0.14.0)
24
+ axiom-types (0.1.1)
25
+ descendants_tracker (~> 0.0.4)
26
+ ice_nine (~> 0.11.0)
27
+ thread_safe (~> 0.3, >= 0.3.1)
28
+ byebug (11.1.3)
29
+ coderay (1.1.3)
30
+ coercible (1.0.0)
31
+ descendants_tracker (~> 0.0.1)
32
+ concurrent-ruby (1.1.8)
33
+ crack (0.4.5)
34
+ rexml
35
+ descendants_tracker (0.0.4)
36
+ thread_safe (~> 0.3, >= 0.3.1)
37
+ diff-lcs (1.4.4)
38
+ dry-configurable (0.11.5)
39
+ concurrent-ruby (~> 1.0)
40
+ dry-core (~> 0.4, >= 0.4.7)
41
+ dry-equalizer (~> 0.2)
42
+ dry-container (0.7.2)
43
+ concurrent-ruby (~> 1.0)
44
+ dry-configurable (~> 0.1, >= 0.1.3)
45
+ dry-core (0.4.9)
46
+ concurrent-ruby (~> 1.0)
47
+ dry-equalizer (0.3.0)
48
+ dry-inflector (0.2.0)
49
+ dry-logic (0.6.1)
50
+ concurrent-ruby (~> 1.0)
51
+ dry-core (~> 0.2)
52
+ dry-equalizer (~> 0.2)
53
+ dry-types (0.14.1)
54
+ concurrent-ruby (~> 1.0)
55
+ dry-container (~> 0.3)
56
+ dry-core (~> 0.4, >= 0.4.4)
57
+ dry-equalizer (~> 0.2)
58
+ dry-inflector (~> 0.1, >= 0.1.2)
59
+ dry-logic (~> 0.5, >= 0.5)
60
+ dry-validation (0.13.3)
61
+ concurrent-ruby (~> 1.0)
62
+ dry-configurable (~> 0.1, >= 0.1.3)
63
+ dry-core (~> 0.2, >= 0.2.1)
64
+ dry-equalizer (~> 0.2)
65
+ dry-logic (~> 0.5, >= 0.5.0)
66
+ dry-types (~> 0.14.0)
67
+ equalizer (0.0.11)
68
+ ethon (0.12.0)
69
+ ffi (>= 1.3.0)
70
+ ffi (1.15.0)
71
+ gem_config (0.3.2)
72
+ hashdiff (1.0.1)
73
+ i18n (1.8.10)
74
+ concurrent-ruby (~> 1.0)
75
+ ice_nine (0.11.2)
76
+ method_source (1.0.0)
77
+ minitest (5.14.4)
78
+ pry (0.13.1)
79
+ coderay (~> 1.1)
80
+ method_source (~> 1.0)
81
+ pry-byebug (3.9.0)
82
+ byebug (~> 11.0)
83
+ pry (~> 0.13.0)
84
+ public_suffix (4.0.6)
85
+ rake (10.5.0)
86
+ rexml (3.2.4)
87
+ rspec (3.10.0)
88
+ rspec-core (~> 3.10.0)
89
+ rspec-expectations (~> 3.10.0)
90
+ rspec-mocks (~> 3.10.0)
91
+ rspec-core (3.10.1)
92
+ rspec-support (~> 3.10.0)
93
+ rspec-expectations (3.10.1)
94
+ diff-lcs (>= 1.2.0, < 2.0)
95
+ rspec-support (~> 3.10.0)
96
+ rspec-mocks (3.10.1)
97
+ diff-lcs (>= 1.2.0, < 2.0)
98
+ rspec-support (~> 3.10.0)
99
+ rspec-support (3.10.1)
100
+ thor (1.1.0)
101
+ thread_safe (0.3.6)
102
+ typhoeus (1.4.0)
103
+ ethon (>= 0.9.0)
104
+ tzinfo (2.0.4)
105
+ concurrent-ruby (~> 1.0)
106
+ vcr (3.0.3)
107
+ virtus (1.0.5)
108
+ axiom-types (~> 0.1)
109
+ coercible (~> 1.0)
110
+ descendants_tracker (~> 0.0, >= 0.0.3)
111
+ equalizer (~> 0.0, >= 0.0.9)
112
+ virtus-matchers (0.4.0)
113
+ virtus (~> 1.0.0)
114
+ webmock (3.11.1)
115
+ addressable (>= 2.3.6)
116
+ crack (>= 0.3.2)
117
+ hashdiff (>= 0.4.0, < 2.0.0)
118
+ zeitwerk (2.4.2)
119
+
120
+ PLATFORMS
121
+ ruby
122
+
123
+ DEPENDENCIES
124
+ api_client_base!
125
+ appraisal
126
+ bundler (~> 2.1)
127
+ dry-validation (~> 0.13)
128
+ pry-byebug (~> 3.9)
129
+ rake (~> 10.0)
130
+ rspec (~> 3.0)
131
+ typhoeus
132
+ vcr (~> 3.0)
133
+ virtus-matchers
134
+ webmock
135
+
136
+ RUBY VERSION
137
+ ruby 2.7.3p183
138
+
139
+ BUNDLED WITH
140
+ 2.1.4
@@ -0,0 +1,9 @@
1
+ # This file was generated by Appraisal
2
+
3
+ source "https://rubygems.org"
4
+
5
+ gem "pry-byebug", "~> 3.9"
6
+ gem "typhoeus"
7
+ gem "dry-validation", "~> 1.6"
8
+
9
+ gemspec path: "../"
@@ -0,0 +1,145 @@
1
+ PATH
2
+ remote: ..
3
+ specs:
4
+ api_client_base (1.9.0)
5
+ activesupport (>= 3.0)
6
+ gem_config (>= 0.3.1)
7
+ virtus (>= 1.0)
8
+
9
+ GEM
10
+ remote: https://rubygems.org/
11
+ specs:
12
+ activesupport (6.1.3.2)
13
+ concurrent-ruby (~> 1.0, >= 1.0.2)
14
+ i18n (>= 1.6, < 2)
15
+ minitest (>= 5.1)
16
+ tzinfo (~> 2.0)
17
+ zeitwerk (~> 2.3)
18
+ addressable (2.7.0)
19
+ public_suffix (>= 2.0.2, < 5.0)
20
+ appraisal (2.4.0)
21
+ bundler
22
+ rake
23
+ thor (>= 0.14.0)
24
+ axiom-types (0.1.1)
25
+ descendants_tracker (~> 0.0.4)
26
+ ice_nine (~> 0.11.0)
27
+ thread_safe (~> 0.3, >= 0.3.1)
28
+ byebug (11.1.3)
29
+ coderay (1.1.3)
30
+ coercible (1.0.0)
31
+ descendants_tracker (~> 0.0.1)
32
+ concurrent-ruby (1.1.9)
33
+ crack (0.4.5)
34
+ rexml
35
+ descendants_tracker (0.0.4)
36
+ thread_safe (~> 0.3, >= 0.3.1)
37
+ diff-lcs (1.4.4)
38
+ dry-configurable (0.12.1)
39
+ concurrent-ruby (~> 1.0)
40
+ dry-core (~> 0.5, >= 0.5.0)
41
+ dry-container (0.8.0)
42
+ concurrent-ruby (~> 1.0)
43
+ dry-configurable (~> 0.1, >= 0.1.3)
44
+ dry-core (0.6.0)
45
+ concurrent-ruby (~> 1.0)
46
+ dry-equalizer (0.3.0)
47
+ dry-inflector (0.2.0)
48
+ dry-initializer (3.0.4)
49
+ dry-logic (1.2.0)
50
+ concurrent-ruby (~> 1.0)
51
+ dry-core (~> 0.5, >= 0.5)
52
+ dry-schema (1.6.2)
53
+ concurrent-ruby (~> 1.0)
54
+ dry-configurable (~> 0.8, >= 0.8.3)
55
+ dry-core (~> 0.5, >= 0.5)
56
+ dry-initializer (~> 3.0)
57
+ dry-logic (~> 1.0)
58
+ dry-types (~> 1.5)
59
+ dry-types (1.5.1)
60
+ concurrent-ruby (~> 1.0)
61
+ dry-container (~> 0.3)
62
+ dry-core (~> 0.5, >= 0.5)
63
+ dry-inflector (~> 0.1, >= 0.1.2)
64
+ dry-logic (~> 1.0, >= 1.0.2)
65
+ dry-validation (1.6.0)
66
+ concurrent-ruby (~> 1.0)
67
+ dry-container (~> 0.7, >= 0.7.1)
68
+ dry-core (~> 0.4)
69
+ dry-equalizer (~> 0.2)
70
+ dry-initializer (~> 3.0)
71
+ dry-schema (~> 1.5, >= 1.5.2)
72
+ equalizer (0.0.11)
73
+ ethon (0.14.0)
74
+ ffi (>= 1.15.0)
75
+ ffi (1.15.1)
76
+ gem_config (0.3.2)
77
+ hashdiff (1.0.1)
78
+ i18n (1.8.10)
79
+ concurrent-ruby (~> 1.0)
80
+ ice_nine (0.11.2)
81
+ method_source (1.0.0)
82
+ minitest (5.14.4)
83
+ pry (0.13.1)
84
+ coderay (~> 1.1)
85
+ method_source (~> 1.0)
86
+ pry-byebug (3.9.0)
87
+ byebug (~> 11.0)
88
+ pry (~> 0.13.0)
89
+ public_suffix (4.0.6)
90
+ rake (10.5.0)
91
+ rexml (3.2.5)
92
+ rspec (3.10.0)
93
+ rspec-core (~> 3.10.0)
94
+ rspec-expectations (~> 3.10.0)
95
+ rspec-mocks (~> 3.10.0)
96
+ rspec-core (3.10.1)
97
+ rspec-support (~> 3.10.0)
98
+ rspec-expectations (3.10.1)
99
+ diff-lcs (>= 1.2.0, < 2.0)
100
+ rspec-support (~> 3.10.0)
101
+ rspec-mocks (3.10.2)
102
+ diff-lcs (>= 1.2.0, < 2.0)
103
+ rspec-support (~> 3.10.0)
104
+ rspec-support (3.10.2)
105
+ thor (1.1.0)
106
+ thread_safe (0.3.6)
107
+ typhoeus (1.4.0)
108
+ ethon (>= 0.9.0)
109
+ tzinfo (2.0.4)
110
+ concurrent-ruby (~> 1.0)
111
+ vcr (3.0.3)
112
+ virtus (1.0.5)
113
+ axiom-types (~> 0.1)
114
+ coercible (~> 1.0)
115
+ descendants_tracker (~> 0.0, >= 0.0.3)
116
+ equalizer (~> 0.0, >= 0.0.9)
117
+ virtus-matchers (0.4.0)
118
+ virtus (~> 1.0.0)
119
+ webmock (3.13.0)
120
+ addressable (>= 2.3.6)
121
+ crack (>= 0.3.2)
122
+ hashdiff (>= 0.4.0, < 2.0.0)
123
+ zeitwerk (2.4.2)
124
+
125
+ PLATFORMS
126
+ ruby
127
+
128
+ DEPENDENCIES
129
+ api_client_base!
130
+ appraisal
131
+ bundler (~> 2.1)
132
+ dry-validation (~> 1.6)
133
+ pry-byebug (~> 3.9)
134
+ rake (~> 10.0)
135
+ rspec (~> 3.0)
136
+ typhoeus
137
+ vcr (~> 3.0)
138
+ virtus-matchers
139
+ webmock
140
+
141
+ RUBY VERSION
142
+ ruby 2.7.3p183
143
+
144
+ BUNDLED WITH
145
+ 2.1.4
@@ -21,6 +21,10 @@ module APIClientBase
21
21
 
22
22
  included do
23
23
  include GemConfig::Base
24
+
25
+ with_configuration do
26
+ has :after_response
27
+ end
24
28
  end
25
29
 
26
30
  end
@@ -10,7 +10,7 @@ module APIClientBase
10
10
  private
11
11
 
12
12
  def self.inherit_attributes!(klass)
13
- parent_module = klass.name.deconstantize.constantize
13
+ parent_module = _api_client_parent_module(klass)
14
14
  return unless parent_module.respond_to?(:configuration)
15
15
  parent_module.configuration.rules.each do |rule|
16
16
  self.inherit_attribute!(klass, rule)
@@ -21,6 +21,10 @@ module APIClientBase
21
21
  klass.attribute rule[0]
22
22
  end
23
23
 
24
+ def self._api_client_parent_module(klass)
25
+ klass.name.deconstantize.constantize
26
+ end
27
+
24
28
  end
25
29
  end
26
30
  end
@@ -28,7 +28,11 @@ module APIClientBase
28
28
 
29
29
  request = request_class.new(request_args)
30
30
  raw_response = request.()
31
- response_class.new(raw_response: raw_response)
31
+ response = response_class.new(raw_response: raw_response)
32
+
33
+ _api_client_call_hook_with request, response
34
+
35
+ response
32
36
  end
33
37
  end
34
38
 
@@ -22,6 +22,24 @@ module APIClientBase
22
22
  included do
23
23
  include APIClientBase::Client::Attributes
24
24
  extend APIClientBase::Client::ClassMethods
25
+
26
+ private
27
+
28
+ def _api_client_call_hook_with(request, response)
29
+ hook = _api_client_after_response
30
+ return if hook.nil?
31
+
32
+ hook.(request, response)
33
+ end
34
+
35
+ def _api_client_gem_module
36
+ @_api_client_gem_module ||= self.class.name.deconstantize.constantize
37
+ end
38
+
39
+ def _api_client_after_response
40
+ return nil if not _api_client_gem_module.respond_to?(:configuration)
41
+ _api_client_gem_module.configuration.after_response
42
+ end
25
43
  end
26
44
 
27
45
  end
@@ -42,7 +42,16 @@ module APIClientBase
42
42
  def run
43
43
  require "typhoeus"
44
44
  if defined?(Typhoeus)
45
- request = Typhoeus::Request.new(uri, typhoeus_options)
45
+ opts = BuildTyphoeusOptions.(
46
+ {
47
+ method: action,
48
+ headers: headers,
49
+ body: body,
50
+ params: params,
51
+ proxy: proxy,
52
+ }.merge(typhoeus_options)
53
+ )
54
+ request = Typhoeus::Request.new(uri, opts)
46
55
  request.run
47
56
  else
48
57
  fail "Either override #run or make sure Typhoeus is available for use."
@@ -62,8 +71,8 @@ module APIClientBase
62
71
  path = URI.parse(host).path
63
72
  if path.present?
64
73
  URI.join(
65
- host,
66
- [path, "/"].join,
74
+ host,
75
+ [path, "/"].join,
67
76
  api_client_base_path[1..-1]
68
77
  )
69
78
  else
@@ -88,13 +97,7 @@ module APIClientBase
88
97
  def before_call; end
89
98
 
90
99
  def typhoeus_options
91
- BuildTyphoeusOptions.(
92
- method: action,
93
- headers: headers,
94
- body: body,
95
- params: params,
96
- proxy: proxy,
97
- )
100
+ {}
98
101
  end
99
102
 
100
103
  end
@@ -26,6 +26,7 @@ module APIClientBase
26
26
  attribute :success, self::Boolean, lazy: true, default: :default_success
27
27
  attribute :code, Integer, lazy: true, default: :default_code
28
28
  attribute :body, String, lazy: true, default: :default_body
29
+ attribute :headers, Hash, lazy: true, default: :default_headers
29
30
  end
30
31
 
31
32
  def default_success
@@ -40,5 +41,13 @@ module APIClientBase
40
41
  raw_response.body
41
42
  end
42
43
 
44
+ def default_headers
45
+ (raw_response.headers || {}).transform_keys {|key| key.upcase }
46
+ end
47
+
48
+ def header(key)
49
+ headers[key.upcase]
50
+ end
51
+
43
52
  end
44
53
  end
@@ -1,22 +1,9 @@
1
1
  module APIClientBase
2
2
  class BuildTyphoeusOptions
3
3
 
4
- def self.call(
5
- method: nil,
6
- headers: nil,
7
- body: nil,
8
- params: nil,
9
- proxy: nil
10
- )
11
- opts = {
12
- method: method,
13
- headers: headers,
14
- body: body,
15
- params: params,
16
- }
17
-
18
- if proxy.present?
19
- opts[:proxy] = proxy
4
+ def self.call(opts={})
5
+ if opts[:proxy].blank?
6
+ opts = opts.except(:proxy)
20
7
  end
21
8
 
22
9
  opts
@@ -11,11 +11,16 @@ module APIClientBase
11
11
  def self.errors_of(klass, attrs)
12
12
  schema = schema_of(klass)
13
13
  return [] if schema.nil?
14
- schema.(attrs).errors
14
+
15
+ schema.(attrs).errors.to_h
15
16
  end
16
17
 
17
18
  def self.schema_of(klass)
18
- "#{klass.name}Schema".constantize
19
+ contract_class = "#{klass.name}Schema".constantize
20
+
21
+ return contract_class if Dry::Validation.const_defined?("Schema")
22
+
23
+ contract_class.new
19
24
  rescue NameError
20
25
  end
21
26
 
@@ -1,3 +1,3 @@
1
1
  module APIClientBase
2
- VERSION = "1.7.0"
2
+ VERSION = "1.11.0"
3
3
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: api_client_base
3
3
  version: !ruby/object:Gem::Version
4
- version: 1.7.0
4
+ version: 1.11.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Ramon Tayag
8
- autorequire:
8
+ autorequire:
9
9
  bindir: exe
10
10
  cert_chain: []
11
- date: 2020-04-15 00:00:00.000000000 Z
11
+ date: 2021-11-26 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: activesupport
@@ -142,14 +142,28 @@ dependencies:
142
142
  requirements:
143
143
  - - "<"
144
144
  - !ruby/object:Gem::Version
145
- version: '1.0'
145
+ version: '2.0'
146
146
  type: :development
147
147
  prerelease: false
148
148
  version_requirements: !ruby/object:Gem::Requirement
149
149
  requirements:
150
150
  - - "<"
151
151
  - !ruby/object:Gem::Version
152
- version: '1.0'
152
+ version: '2.0'
153
+ - !ruby/object:Gem::Dependency
154
+ name: appraisal
155
+ requirement: !ruby/object:Gem::Requirement
156
+ requirements:
157
+ - - ">="
158
+ - !ruby/object:Gem::Version
159
+ version: '0'
160
+ type: :development
161
+ prerelease: false
162
+ version_requirements: !ruby/object:Gem::Requirement
163
+ requirements:
164
+ - - ">="
165
+ - !ruby/object:Gem::Version
166
+ version: '0'
153
167
  description: Abstractions to help author API wrappers in Ruby.
154
168
  email:
155
169
  - ramon.tayag@gmail.com
@@ -157,9 +171,10 @@ executables: []
157
171
  extensions: []
158
172
  extra_rdoc_files: []
159
173
  files:
174
+ - ".github/workflows/ruby.yml"
160
175
  - ".gitignore"
161
176
  - ".rspec"
162
- - ".travis.yml"
177
+ - Appraisals
163
178
  - CHANGELOG.md
164
179
  - CODE_OF_CONDUCT.md
165
180
  - Gemfile
@@ -169,6 +184,11 @@ files:
169
184
  - api_client_base.gemspec
170
185
  - bin/console
171
186
  - bin/setup
187
+ - gemfiles/.bundle/config
188
+ - gemfiles/dry_validation_0.x.gemfile
189
+ - gemfiles/dry_validation_0.x.gemfile.lock
190
+ - gemfiles/dry_validation_1.x.gemfile
191
+ - gemfiles/dry_validation_1.x.gemfile.lock
172
192
  - lib/api_client_base.rb
173
193
  - lib/api_client_base/base.rb
174
194
  - lib/api_client_base/base/class_methods.rb
@@ -180,12 +200,12 @@ files:
180
200
  - lib/api_client_base/services/build_typhoeus_options.rb
181
201
  - lib/api_client_base/services/validate.rb
182
202
  - lib/api_client_base/version.rb
183
- homepage: https://github.com/imacchiato/api_client-ruby
203
+ homepage: https://github.com/bloom-solutions/api_client-ruby
184
204
  licenses:
185
205
  - MIT
186
206
  metadata:
187
207
  allowed_push_host: https://rubygems.org
188
- post_install_message:
208
+ post_install_message:
189
209
  rdoc_options: []
190
210
  require_paths:
191
211
  - lib
@@ -200,8 +220,8 @@ required_rubygems_version: !ruby/object:Gem::Requirement
200
220
  - !ruby/object:Gem::Version
201
221
  version: '0'
202
222
  requirements: []
203
- rubygems_version: 3.0.8
204
- signing_key:
223
+ rubygems_version: 3.1.6
224
+ signing_key:
205
225
  specification_version: 4
206
226
  summary: Abstractions to help author API wrappers in Ruby.
207
227
  test_files: []
data/.travis.yml DELETED
@@ -1,5 +0,0 @@
1
- sudo: false
2
- language: ruby
3
- rvm:
4
- - 2.6.3
5
- before_install: gem install bundler -v 2.1.4