api_client_base 1.5.0 → 1.6.0

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: ab81c1e64a88897c1acdc27560853545889693a32398fce9ae64b5ba4b29c4ca
4
- data.tar.gz: cea3469155ef8e303d168d8a3e9b6f28ce08915fd2b072ce4be433e909998846
3
+ metadata.gz: 4944507aab7a50bfa722d2ee9c712467c515dcb8fe030087ad98fd0f417a1129
4
+ data.tar.gz: 05662a54b48237e43bf69f07d1f21c505e3d6782a3f5cc9814b9109666ef26ef
5
5
  SHA512:
6
- metadata.gz: 3983bbe59413269d8a4fa4e9b8d9791c6ec2ee1e4f4b8013aa570640575117ee7643420515bc9cf12fa9c5b7e27408090b75373f01219524c550e2c8f7937071
7
- data.tar.gz: acd06f3eb25ce1337d47df1f95ab6a8db983db6243bd8f16562e0b4577dc7fdb862925ce145e19f57167a2781a4a3e9f01cff08e0523ac84a8beedf710bba40f
6
+ metadata.gz: d8179471df1171101b4701e16c1d8473c941c37e0a3eca87ed33fc02c908808a50cb4412186997baa77fade63ca963a6072d87920f7aade180856a07e1a5d41b
7
+ data.tar.gz: e840dee362e45038426e39958ab265787d3659c5248a95929f4346355786eae0f6c95a07960ae696f7a8946dc86691fd70fff3e915b6aa2840f3afa98302240d
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,11 @@ 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.6.0] - 2020-04-09
8
+ ### Added
9
+ - 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`
10
+ - Set `#proxy` attribute to requests. This is passed to Typhoeus if present
11
+
7
12
  ## [1.5.0] - 2019-04-03
8
13
  ### Added
9
14
  - Allow developer to define `before_call` in requests to execute code
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.3"
7
+
8
+ gem "pry-byebug", "~> 3.9"
7
9
  gem "typhoeus"
data/README.md CHANGED
@@ -197,6 +197,9 @@ client = MyGem::Client.new #...
197
197
  client.get_user(user_id: nil) # -> this raises an ArgumentError "[user_id: 'must be filled']"
198
198
  ```
199
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
+
200
203
  #### Responses
201
204
 
202
205
  ```ruby
@@ -206,6 +209,7 @@ module MyGem
206
209
  # - has `#status` method that is delegated to `raw_response.status`
207
210
  # - has `#code` method to get the response's code
208
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?`
209
213
 
210
214
  # You're encouraged to use Virtus attributes to extract information cleanly
211
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,29 +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
35
36
  before_call
37
+ run
38
+ end
39
+
40
+ private
36
41
 
42
+ def run
37
43
  require "typhoeus"
38
44
  if defined?(Typhoeus)
39
- request = Typhoeus::Request.new(
40
- uri,
41
- method: action,
42
- headers: headers,
43
- body: body,
44
- params: params,
45
- )
46
-
45
+ request = Typhoeus::Request.new(uri, typhoeus_options)
47
46
  request.run
48
47
  else
49
- fail "Either override #call or make sure Typhoeus is available for use."
48
+ fail "Either override #run or make sure Typhoeus is available for use."
50
49
  end
51
50
  end
52
51
 
53
- private
54
-
55
52
  def headers ; {} ; end
56
53
  def body ; nil ; end
57
54
  def params ; {} ; end
@@ -90,5 +87,15 @@ module APIClientBase
90
87
 
91
88
  def before_call; end
92
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
+
93
100
  end
94
101
  end
@@ -0,0 +1,26 @@
1
+ module APIClientBase
2
+ class BuildTyphoeusOptions
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
20
+ end
21
+
22
+ opts
23
+ end
24
+
25
+ end
26
+ end
@@ -1,3 +1,3 @@
1
1
  module APIClientBase
2
- VERSION = "1.5.0"
2
+ VERSION = "1.6.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.5.0
4
+ version: 1.6.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Ramon Tayag
8
8
  autorequire:
9
9
  bindir: exe
10
10
  cert_chain: []
11
- date: 2019-04-03 00:00:00.000000000 Z
11
+ date: 2020-04-09 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
@@ -199,8 +200,7 @@ 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
203
+ rubygems_version: 3.0.8
204
204
  signing_key:
205
205
  specification_version: 4
206
206
  summary: Abstractions to help author API wrappers in Ruby.