api_client_base 1.4.1 → 1.9.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: 16b20a668021e8155ac1a9f45863a2bf24c8671d529d6050d4c7d351d4a67475
4
- data.tar.gz: 295d032174dbbf604bc1f7fa39ad81e53fd6fb0466a48325f96e2c4a728726d3
3
+ metadata.gz: 8b9fd36954265d22fd5c8b2ae143ccf63a54b941ffbfd4230022683501e5b674
4
+ data.tar.gz: 5bf06572c3e6c65ccc66dd6c98e650c8cd33b639f720b5cbd56a397daa8815e1
5
5
  SHA512:
6
- metadata.gz: 715769a66ce42746dff5ed6b09e4fd9c20e7476e2dbc76d0780f3d542a4d6ddc4ec7ab06d2a325de5da9f4888db10efc1e45ed06857cd7eb0d55c57387758fe4
7
- data.tar.gz: 8091fb4977f8b329a9f55865913351e51ba1fd1be20f8f018d76fe7fc6fd91b1b86540f9f76f6cb6c21a952d66027fedef2bbea63a6bb59cd68e717a586c0e91
6
+ metadata.gz: d4e2dcc49429d9d20a65daff58d433aeb0170e0b5b0bbf9fc2feb2121be17ea28894e8a196175e095eb8f29526042d4418e2d0822a22e1c80aecc0c8eec56638
7
+ data.tar.gz: 441e6aeeb41f95255f35522f43e558370df1cc25b6954684c5eea40b0a4d0bffb6d47e10be187b209f9fd21515f3f4559a70a7a4d557d971edbedd408a5c8491
data/.gitignore CHANGED
@@ -7,3 +7,5 @@
7
7
  /pkg/
8
8
  /spec/reports/
9
9
  /tmp/
10
+
11
+ /.smartgf*
@@ -1,5 +1,5 @@
1
1
  sudo: false
2
2
  language: ruby
3
3
  rvm:
4
- - 2.3.0
5
- before_install: gem install bundler -v 1.13.1
4
+ - 2.6.3
5
+ before_install: gem install bundler -v 2.1.4
@@ -4,6 +4,27 @@ 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.9.0] - 2020-06-30
8
+ ### Added
9
+ - Allow users to override typhoeus_options to pass any args that we haven't defined
10
+
11
+ ## [1.8.0] - 2020-06-30
12
+ ### Added
13
+ - Allow all Typhoeus options to be passed to BuildTyphoeusOptions. This is useful when overriding the method `typhoeus_options` in requests
14
+
15
+ ## [1.7.0] - 2020-04-15
16
+ ### Added
17
+ - Add `Response#body` which is `raw_response`'s `body`
18
+
19
+ ## [1.6.0] - 2020-04-09
20
+ ### Added
21
+ - Move http-related code to Request#run. This is the one that should be overridden, instead of call, since `#call` calls other methods like `before_call`
22
+ - Set `#proxy` attribute to requests. This is passed to Typhoeus if present
23
+
24
+ ## [1.5.0] - 2019-04-03
25
+ ### Added
26
+ - Allow developer to define `before_call` in requests to execute code
27
+
7
28
  ## [1.4.1] - 2019-01-30
8
29
  ### Fixed
9
30
  - `host` configuration should not remove the path
data/Gemfile CHANGED
@@ -3,5 +3,7 @@ source 'https://rubygems.org'
3
3
  # Specify your gem's dependencies in api_client_base.gemspec
4
4
  gemspec
5
5
 
6
- gem "pry-byebug"
6
+ ruby "2.6.5"
7
+
8
+ gem "pry-byebug", "~> 3.9"
7
9
  gem "typhoeus"
data/README.md CHANGED
@@ -154,6 +154,14 @@ module MyGem
154
154
  def default_action
155
155
  :post # defaults to :get
156
156
  end
157
+
158
+ def before_call
159
+ # You need not define this, but it might be helpful if you want to log things, for example, before the http request is executed.
160
+ # The following example would require you to define a `logger` attribute
161
+
162
+ self.logger.debug "Will make a #{action} call: #{body}"
163
+ end
164
+
157
165
  end
158
166
  end
159
167
  ```
@@ -189,6 +197,9 @@ client = MyGem::Client.new #...
189
197
  client.get_user(user_id: nil) # -> this raises an ArgumentError "[user_id: 'must be filled']"
190
198
  ```
191
199
 
200
+ ##### Proxy
201
+ Requests automatically have `proxy`. If set and you are relying on using Typhoeus, proxy will be passed on and used by Typhoeus.
202
+
192
203
  #### Responses
193
204
 
194
205
  ```ruby
@@ -198,6 +209,7 @@ module MyGem
198
209
  # - has `#status` method that is delegated to `raw_response.status`
199
210
  # - has `#code` method to get the response's code
200
211
  # - has `#raw_response` which is a Typhoeus response object
212
+ # - has `#success` which is delegated to `raw_response.success?`. May be accessed via `#success?`
201
213
 
202
214
  # You're encouraged to use Virtus attributes to extract information cleanly
203
215
  attribute :id, Integer, lazy: true, default: :default_id
@@ -34,11 +34,11 @@ Gem::Specification.new do |spec|
34
34
  spec.add_dependency "virtus", ">= 1.0"
35
35
  spec.add_dependency "gem_config", ">= 0.3.1"
36
36
 
37
- spec.add_development_dependency "bundler", "~> 1.13"
37
+ spec.add_development_dependency "bundler", "~> 2.1"
38
38
  spec.add_development_dependency "rake", "~> 10.0"
39
39
  spec.add_development_dependency "rspec", "~> 3.0"
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"
43
+ spec.add_development_dependency "dry-validation", "< 1.0"
44
44
  end
@@ -7,6 +7,7 @@ require "gem_config"
7
7
  require "virtus"
8
8
  require "api_client_base/version"
9
9
  require "api_client_base/services/validate"
10
+ require "api_client_base/services/build_typhoeus_options"
10
11
  require "api_client_base/base"
11
12
  require "api_client_base/base/class_methods"
12
13
  require "api_client_base/client"
@@ -29,27 +29,35 @@ module APIClientBase
29
29
  lazy: true,
30
30
  default: :default_api_client_base_path,
31
31
  })
32
+ attribute :proxy, String
32
33
  end
33
34
 
34
35
  def call
36
+ before_call
37
+ run
38
+ end
39
+
40
+ private
41
+
42
+ def run
35
43
  require "typhoeus"
36
44
  if defined?(Typhoeus)
37
- request = Typhoeus::Request.new(
38
- uri,
39
- method: action,
40
- headers: headers,
41
- body: body,
42
- params: params,
45
+ opts = BuildTyphoeusOptions.(
46
+ {
47
+ method: action,
48
+ headers: headers,
49
+ body: body,
50
+ params: params,
51
+ proxy: proxy,
52
+ }.merge(typhoeus_options)
43
53
  )
44
-
54
+ request = Typhoeus::Request.new(uri, opts)
45
55
  request.run
46
56
  else
47
- fail "Either override #call or make sure Typhoeus is available for use."
57
+ fail "Either override #run or make sure Typhoeus is available for use."
48
58
  end
49
59
  end
50
60
 
51
- private
52
-
53
61
  def headers ; {} ; end
54
62
  def body ; nil ; end
55
63
  def params ; {} ; end
@@ -63,8 +71,8 @@ module APIClientBase
63
71
  path = URI.parse(host).path
64
72
  if path.present?
65
73
  URI.join(
66
- host,
67
- [path, "/"].join,
74
+ host,
75
+ [path, "/"].join,
68
76
  api_client_base_path[1..-1]
69
77
  )
70
78
  else
@@ -86,5 +94,11 @@ module APIClientBase
86
94
  end
87
95
  end
88
96
 
97
+ def before_call; end
98
+
99
+ def typhoeus_options
100
+ {}
101
+ end
102
+
89
103
  end
90
104
  end
@@ -25,6 +25,7 @@ module APIClientBase
25
25
  attribute :raw_response, Object
26
26
  attribute :success, self::Boolean, lazy: true, default: :default_success
27
27
  attribute :code, Integer, lazy: true, default: :default_code
28
+ attribute :body, String, lazy: true, default: :default_body
28
29
  end
29
30
 
30
31
  def default_success
@@ -35,5 +36,9 @@ module APIClientBase
35
36
  raw_response.code
36
37
  end
37
38
 
39
+ def default_body
40
+ raw_response.body
41
+ end
42
+
38
43
  end
39
44
  end
@@ -0,0 +1,13 @@
1
+ module APIClientBase
2
+ class BuildTyphoeusOptions
3
+
4
+ def self.call(opts={})
5
+ if opts[:proxy].blank?
6
+ opts = opts.except(:proxy)
7
+ end
8
+
9
+ opts
10
+ end
11
+
12
+ end
13
+ end
@@ -1,3 +1,3 @@
1
1
  module APIClientBase
2
- VERSION = "1.4.1"
2
+ VERSION = "1.9.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.4.1
4
+ version: 1.9.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: 2019-01-30 00:00:00.000000000 Z
11
+ date: 2020-06-30 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: activesupport
@@ -58,14 +58,14 @@ dependencies:
58
58
  requirements:
59
59
  - - "~>"
60
60
  - !ruby/object:Gem::Version
61
- version: '1.13'
61
+ version: '2.1'
62
62
  type: :development
63
63
  prerelease: false
64
64
  version_requirements: !ruby/object:Gem::Requirement
65
65
  requirements:
66
66
  - - "~>"
67
67
  - !ruby/object:Gem::Version
68
- version: '1.13'
68
+ version: '2.1'
69
69
  - !ruby/object:Gem::Dependency
70
70
  name: rake
71
71
  requirement: !ruby/object:Gem::Requirement
@@ -140,16 +140,16 @@ dependencies:
140
140
  name: dry-validation
141
141
  requirement: !ruby/object:Gem::Requirement
142
142
  requirements:
143
- - - ">="
143
+ - - "<"
144
144
  - !ruby/object:Gem::Version
145
- version: '0'
145
+ version: '1.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: '0'
152
+ version: '1.0'
153
153
  description: Abstractions to help author API wrappers in Ruby.
154
154
  email:
155
155
  - ramon.tayag@gmail.com
@@ -177,6 +177,7 @@ files:
177
177
  - lib/api_client_base/client/class_methods.rb
178
178
  - lib/api_client_base/request.rb
179
179
  - lib/api_client_base/response.rb
180
+ - lib/api_client_base/services/build_typhoeus_options.rb
180
181
  - lib/api_client_base/services/validate.rb
181
182
  - lib/api_client_base/version.rb
182
183
  homepage: https://github.com/imacchiato/api_client-ruby
@@ -184,7 +185,7 @@ licenses:
184
185
  - MIT
185
186
  metadata:
186
187
  allowed_push_host: https://rubygems.org
187
- post_install_message:
188
+ post_install_message:
188
189
  rdoc_options: []
189
190
  require_paths:
190
191
  - lib
@@ -199,9 +200,8 @@ required_rubygems_version: !ruby/object:Gem::Requirement
199
200
  - !ruby/object:Gem::Version
200
201
  version: '0'
201
202
  requirements: []
202
- rubyforge_project:
203
- rubygems_version: 2.7.8
204
- signing_key:
203
+ rubygems_version: 3.0.8
204
+ signing_key:
205
205
  specification_version: 4
206
206
  summary: Abstractions to help author API wrappers in Ruby.
207
207
  test_files: []