grac 4.3.1 → 4.4.1

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: 28067fc75dea820ec4be62b98fae9a97d526f3d1ccaf5fbd6aedfdb4b969610d
4
- data.tar.gz: 0bd4a5f096e14751ad64d1e14dc603e3c02ccf3bf1d4aef5f7bda30757b443e5
3
+ metadata.gz: '014856f6d0cb348e58f94c2a6af0219e6e3cf8cfc7e347702dd31fee356132a8'
4
+ data.tar.gz: 366ff7b21060668da66611517675a45e5102fda1d321d393bc6b84319fa3ba33
5
5
  SHA512:
6
- metadata.gz: df0f0b16ea7d9f9e0ff399b6c0821b5b14eb1a8a742bc0f1a27fe6af7962fae36e2f7d6988443c316fec8d578c7182141b11d934d1e9ad6007b822b600373cc9
7
- data.tar.gz: a0533567a6d25acedc0d51634337559be9c35e60f2101ee44306234f54569129564211d0ae4ffba1b95ae3412ddd5739db6e052e8b08614ce93700ef1c6169a7
6
+ metadata.gz: ed2781017bd764ac99b6a1bbab63095d174fbd5682fc9fb170c19ee56d27907f386301b920c0c795786d84889361db80be1db48b43ce431409370f289babac08
7
+ data.tar.gz: 616322e1feeccffb38acf4ad5a30d9ca58e8bc7878690401ccff7768e8f679a198e851bc99f24ef4f52272b9836fcaff47b2055980663f29d4b6b6a19c6731e3
data/lib/grac/client.rb CHANGED
@@ -21,11 +21,13 @@ module Grac
21
21
  params: options[:params] || {},
22
22
  headers: {
23
23
  'User-Agent' => "Grac v#{Grac::VERSION}",
24
- 'Content-Type' => 'application/json;charset=utf-8'
24
+ 'Content-Type' => 'application/json;charset=utf-8',
25
25
  }.merge(options[:headers] || {}),
26
26
  postprocessing: {},
27
27
  middleware: options[:middleware] || [],
28
28
  retry_get_head: options.fetch(:retry_get_head, true),
29
+ proxy: options[:proxy],
30
+ ssl: options[:ssl],
29
31
  }
30
32
 
31
33
  if options[:postprocessing]
@@ -43,8 +45,8 @@ module Grac
43
45
 
44
46
  @options.freeze
45
47
 
46
- [:params, :headers, :postprocessing, :middleware].each do |k|
47
- @options[k].freeze
48
+ [:params, :headers, :postprocessing, :middleware, :proxy, :ssl].each do |k|
49
+ @options[k]&.freeze
48
50
  end
49
51
 
50
52
  @uri.freeze
@@ -55,6 +57,8 @@ module Grac
55
57
  {
56
58
  headers: @options[:headers].merge(options[:headers] || {}),
57
59
  middleware: @options[:middleware] + (options[:middleware] || []),
60
+ proxy: merge_option_hash(options, :proxy),
61
+ ssl: merge_option_hash(options, :ssl),
58
62
  },
59
63
  )
60
64
 
@@ -85,12 +89,14 @@ module Grac
85
89
  def call(opts, request_uri, method, params, body)
86
90
  request_hash = {
87
91
  method: method,
88
- params: params, # Query params are escaped by Typhoeus
92
+ params: params, # Query params are escaped by Typhoeus
89
93
  body: body,
90
94
  connecttimeout: opts[:connecttimeout],
91
95
  timeout: opts[:timeout],
92
96
  headers: opts[:headers],
93
97
  }
98
+ apply_proxy_options(request_hash, opts[:proxy])
99
+ apply_ssl_options(request_hash, opts[:ssl])
94
100
 
95
101
  request = ::Typhoeus::Request.new(request_uri, request_hash)
96
102
  response = request.run
@@ -244,5 +250,34 @@ module Grac
244
250
  CGI::escape(value).gsub('+', '%20')
245
251
  end
246
252
 
253
+ def merge_option_hash(options, key)
254
+ existing = @options[key] || {}
255
+ new_val = options[key]
256
+
257
+ return existing if new_val == nil
258
+
259
+ existing.merge(new_val)
260
+ end
261
+
262
+ # map proxy options from our format to typhoeus format
263
+ def apply_proxy_options(request_hash, proxy)
264
+ return if proxy == nil
265
+
266
+ request_hash[:proxy] = proxy[:url] if proxy[:url] != nil
267
+ request_hash[:proxyusername] = proxy[:username] if proxy[:username] != nil
268
+ request_hash[:proxypassword] = proxy[:password] if proxy[:password] != nil
269
+ end
270
+
271
+ # map ssl options from our format to typhoeus format
272
+ def apply_ssl_options(request_hash, ssl)
273
+ return if ssl == nil
274
+
275
+ request_hash[:ssl_verifypeer] = ssl[:verify_peer] if ssl[:verify_peer] != nil
276
+ request_hash[:ssl_verifyhost] = ssl[:verify_host] if ssl[:verify_host] != nil
277
+ request_hash[:sslcert] = ssl[:cert] if ssl[:cert] != nil
278
+ request_hash[:sslkey] = ssl[:key] if ssl[:key] != nil
279
+ request_hash[:cainfo] = ssl[:ca_info] if ssl[:ca_info] != nil
280
+ end
281
+
247
282
  end
248
283
  end
data/lib/grac/version.rb CHANGED
@@ -1,3 +1,7 @@
1
+ # frozen_string_literal: true
2
+
1
3
  module Grac
2
- VERSION = "4.3.1"
4
+
5
+ VERSION = '4.4.1'
6
+
3
7
  end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: grac
3
3
  version: !ruby/object:Gem::Version
4
- version: 4.3.1
4
+ version: 4.4.1
5
5
  platform: ruby
6
6
  authors:
7
7
  - Tobias Schoknecht
@@ -121,6 +121,20 @@ dependencies:
121
121
  - - "~>"
122
122
  - !ruby/object:Gem::Version
123
123
  version: '1'
124
+ - !ruby/object:Gem::Dependency
125
+ name: logger
126
+ requirement: !ruby/object:Gem::Requirement
127
+ requirements:
128
+ - - ">="
129
+ - !ruby/object:Gem::Version
130
+ version: '0'
131
+ type: :runtime
132
+ prerelease: false
133
+ version_requirements: !ruby/object:Gem::Requirement
134
+ requirements:
135
+ - - ">="
136
+ - !ruby/object:Gem::Version
137
+ version: '0'
124
138
  description: Generic REST API Client
125
139
  email:
126
140
  - tobias.schoknecht@viafintech.com
@@ -151,7 +165,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
151
165
  - !ruby/object:Gem::Version
152
166
  version: '0'
153
167
  requirements: []
154
- rubygems_version: 3.6.9
168
+ rubygems_version: 4.0.3
155
169
  specification_version: 4
156
170
  summary: Very generic client for REST API with basic error handling
157
171
  test_files: []