grac 4.3.1 → 4.4.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: 28067fc75dea820ec4be62b98fae9a97d526f3d1ccaf5fbd6aedfdb4b969610d
4
- data.tar.gz: 0bd4a5f096e14751ad64d1e14dc603e3c02ccf3bf1d4aef5f7bda30757b443e5
3
+ metadata.gz: 061003ad2cd97921474d31303c4257061bcc15836c47303149f73519757848cb
4
+ data.tar.gz: fc62c7fd354b21f7ea929870fbc2f69a0b3c4c7f838f10c4f501c451dba05db9
5
5
  SHA512:
6
- metadata.gz: df0f0b16ea7d9f9e0ff399b6c0821b5b14eb1a8a742bc0f1a27fe6af7962fae36e2f7d6988443c316fec8d578c7182141b11d934d1e9ad6007b822b600373cc9
7
- data.tar.gz: a0533567a6d25acedc0d51634337559be9c35e60f2101ee44306234f54569129564211d0ae4ffba1b95ae3412ddd5739db6e052e8b08614ce93700ef1c6169a7
6
+ metadata.gz: 9f341acf25ddbf2e17551adfa3c7c75b0b157f06867c1b9f8aa62e141080eff04072598f0419ad1a9eab4c77d7b86934471db240a862e2ff856ccb2ae28d17e5
7
+ data.tar.gz: 54091341a2859c9a4fa98e8f253e24f7d0b34caa199a8dca476a9397c3934f38cfb31aa5f1db77632534dda5dcbd8d49f60e3baa151dcdfb4349bb6c8d7ca46a
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.0'
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.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Tobias Schoknecht