api_client_base 1.4.0 → 1.8.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/.gitignore +2 -0
- data/.travis.yml +2 -2
- data/CHANGELOG.md +21 -0
- data/Gemfile +3 -1
- data/README.md +12 -0
- data/api_client_base.gemspec +2 -2
- data/lib/api_client_base.rb +2 -0
- data/lib/api_client_base/request.rb +33 -13
- data/lib/api_client_base/response.rb +5 -0
- data/lib/api_client_base/services/build_typhoeus_options.rb +13 -0
- data/lib/api_client_base/version.rb +1 -1
- metadata +13 -13
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 6220f14a790ce1548a85cd97a5f870cd0e6e05c0c14c3a815c97499b4dc5a88b
|
4
|
+
data.tar.gz: 2d1e16d307a3fd1859e35cde544833db19279fccc03968f4c929fa7f2d704e01
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 4ac762090b5b39591e73181a804ac9932fae90e3f26213e6ba08bd4a3916b4e5a7e4a5ec786ee4b1536fddfc2ad873e98ba69941aea855ddb33e2b17a3c0f6bf
|
7
|
+
data.tar.gz: 4ef26be532375b6714c4d426755888b5371f2d08727f0c89690a189d5fcca83ba369f13ca6b87b4226c150b3517463d2ca2fd4222d35d56e22917913465e6df6
|
data/.travis.yml
CHANGED
data/CHANGELOG.md
CHANGED
@@ -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
|
+
## [Unreleased]
|
8
|
+
### Added
|
9
|
+
- Allow all Typhoeus options to be passed to BuildTyphoeusOptions. This is useful when overriding the method `typhoeus_options` in requests
|
10
|
+
|
11
|
+
## [1.7.0] - 2020-04-15
|
12
|
+
### Added
|
13
|
+
- Add `Response#body` which is `raw_response`'s `body`
|
14
|
+
|
15
|
+
## [1.6.0] - 2020-04-09
|
16
|
+
### Added
|
17
|
+
- 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`
|
18
|
+
- Set `#proxy` attribute to requests. This is passed to Typhoeus if present
|
19
|
+
|
20
|
+
## [1.5.0] - 2019-04-03
|
21
|
+
### Added
|
22
|
+
- Allow developer to define `before_call` in requests to execute code
|
23
|
+
|
24
|
+
## [1.4.1] - 2019-01-30
|
25
|
+
### Fixed
|
26
|
+
- `host` configuration should not remove the path
|
27
|
+
|
7
28
|
## [1.4.0] - 2018-09-04
|
8
29
|
### Added
|
9
30
|
- Support `host` configurations that already have a path
|
data/Gemfile
CHANGED
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
|
data/api_client_base.gemspec
CHANGED
@@ -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
|
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
|
data/lib/api_client_base.rb
CHANGED
@@ -1,11 +1,13 @@
|
|
1
1
|
require "active_support/concern"
|
2
2
|
require "active_support/core_ext/class/attribute"
|
3
3
|
require "active_support/core_ext/module/attribute_accessors"
|
4
|
+
require "active_support/core_ext/object/blank"
|
4
5
|
require "active_support/inflector"
|
5
6
|
require "gem_config"
|
6
7
|
require "virtus"
|
7
8
|
require "api_client_base/version"
|
8
9
|
require "api_client_base/services/validate"
|
10
|
+
require "api_client_base/services/build_typhoeus_options"
|
9
11
|
require "api_client_base/base"
|
10
12
|
require "api_client_base/base/class_methods"
|
11
13
|
require "api_client_base/client"
|
@@ -29,27 +29,26 @@ 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,
|
43
|
-
)
|
44
|
-
|
45
|
+
request = Typhoeus::Request.new(uri, typhoeus_options)
|
45
46
|
request.run
|
46
47
|
else
|
47
|
-
fail "Either override #
|
48
|
+
fail "Either override #run or make sure Typhoeus is available for use."
|
48
49
|
end
|
49
50
|
end
|
50
51
|
|
51
|
-
private
|
52
|
-
|
53
52
|
def headers ; {} ; end
|
54
53
|
def body ; nil ; end
|
55
54
|
def params ; {} ; end
|
@@ -59,8 +58,17 @@ module APIClientBase
|
|
59
58
|
end
|
60
59
|
|
61
60
|
def default_uri
|
62
|
-
uri = if
|
63
|
-
URI.
|
61
|
+
uri = if api_client_base_path.present?
|
62
|
+
path = URI.parse(host).path
|
63
|
+
if path.present?
|
64
|
+
URI.join(
|
65
|
+
host,
|
66
|
+
[path, "/"].join,
|
67
|
+
api_client_base_path[1..-1]
|
68
|
+
)
|
69
|
+
else
|
70
|
+
URI.join(host, api_client_base_path)
|
71
|
+
end
|
64
72
|
else
|
65
73
|
URI(host)
|
66
74
|
end
|
@@ -77,5 +85,17 @@ module APIClientBase
|
|
77
85
|
end
|
78
86
|
end
|
79
87
|
|
88
|
+
def before_call; end
|
89
|
+
|
90
|
+
def typhoeus_options
|
91
|
+
BuildTyphoeusOptions.(
|
92
|
+
method: action,
|
93
|
+
headers: headers,
|
94
|
+
body: body,
|
95
|
+
params: params,
|
96
|
+
proxy: proxy,
|
97
|
+
)
|
98
|
+
end
|
99
|
+
|
80
100
|
end
|
81
101
|
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
|
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
|
+
version: 1.8.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:
|
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
|
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
|
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
|
-
|
203
|
-
|
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: []
|