bima-shark-sdk 3.0.0 → 3.1.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: 5c3d5438f91e3e0715d520cae493446b62571f4f63baa1dcf4b4ff1ce9a97380
4
- data.tar.gz: 7d321474ad227eabb72a5c9f64806e2219a606ce9b804b1c36bf78b8e6176b48
3
+ metadata.gz: c940902ca2481c64fa2c9713c82fae4a654be44bf52aac78f130975109d2e2d6
4
+ data.tar.gz: f9de212a3cda286061798bc1f058e1152bb3a6c36a91c26a95ed449fc6526ffe
5
5
  SHA512:
6
- metadata.gz: '078265caf5dd06022b0ae91356fd4bd9f8093a879c1191a55297280786be708950652563cf1d5ccb9df8a51c5b9bec7a66f7f8b534eb865ad6142b757310a216'
7
- data.tar.gz: ae7031d4aee957a60d2791122b650a713c77b75fa0c661b84444830cc463c5f40ac69dda0f19ed296cf22d7acee21f76346973e523ccb8316bf16ce4ed178ab6
6
+ metadata.gz: dc9ee1ce1f478ba2f41df518b7bbcdd3b966d75c2a60fc19ad45d39d77eb449bb2e8e44412536b4ca353f91531d8c6198289e0b333c4ce9ff9174d09412c09e6
7
+ data.tar.gz: b568b142df1967556f5771e9439ed319c87f30e46691ed6c33a9d1fede56e83a8b8867c1599cbb72ca35f9b16d724915cfac615a1cb20dcdeb07cdb9a1fc4e36
data/.travis.yml CHANGED
@@ -1,5 +1,5 @@
1
1
  language: ruby
2
- cache: bundler
2
+ # cache: bundler
3
3
  rvm:
4
4
  - 2.7.6
5
5
  - 3.0.2
data/CHANGELOG.md CHANGED
@@ -1,5 +1,8 @@
1
1
  ## Changelog
2
2
 
3
+ #### 3.1.0
4
+ - Extend `with_service_token` with `with_auth_token` which allows to send custom `Authorization` header, not only `Bearer`
5
+
3
6
  #### 3.0.0
4
7
  - new minimum requirements are `Ruby 3.0` and `faraday 2.0`
5
8
  - remove `Shark::Subscription`
data/README.md CHANGED
@@ -42,6 +42,21 @@ Shark::MailingService.use_shark_mailer do |mailer|
42
42
  end
43
43
  ```
44
44
 
45
+ To sign your requests with custom tokens, for instance with JWT:
46
+ ```ruby
47
+ def deliver
48
+ access_id = 'access_id'
49
+ secret_key = 'secret_key'
50
+
51
+ signature = JWT.encode({ exp: Time.now.to_i + (1 * 60) }, secret_key, 'HS256')
52
+
53
+ Shark.with_auth_token("JWT #{access_id}:#{signature}") do
54
+ super
55
+ end
56
+ end
57
+
58
+ ```
59
+
45
60
  ## Testing
46
61
 
47
62
  ```
@@ -38,9 +38,7 @@ module Shark
38
38
  request_headers = connection_options_headers.merge(headers || {})
39
39
  request_params = connection_options_params.merge(params || {})
40
40
 
41
- if Shark.service_token.present?
42
- request_headers['Authorization'] = "Bearer #{Shark.service_token}"
43
- end
41
+ request_headers['Authorization'] = Shark.auth_token if Shark.auth_token.present?
44
42
 
45
43
  @connection.send(request_action) do |request|
46
44
  request.url(url)
data/lib/shark/version.rb CHANGED
@@ -1,5 +1,5 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  module Shark
4
- VERSION = '3.0.0'
4
+ VERSION = '3.1.0'
5
5
  end
data/lib/shark.rb CHANGED
@@ -34,26 +34,39 @@ module Shark
34
34
  # @api public
35
35
  def self.with_service_token(token)
36
36
  if token.is_a?(String)
37
- self.service_token = token
37
+ auth_token = "Bearer #{token}"
38
38
  elsif token.respond_to?(:jwt)
39
- self.service_token = token.jwt
39
+ auth_token = "Bearer #{token.jwt}"
40
40
  else
41
41
  raise ArgumentError, 'Parameter :token must be kind of String.'
42
42
  end
43
43
 
44
+ with_auth_token(auth_token)
45
+ end
46
+
47
+ # Within the given block, add the authorization header token to all api requests.
48
+ #
49
+ # @param token [String] The token for the authorization header
50
+ # @param block [Block] The block where authorization token will be set for
51
+ # @api public
52
+ def self.with_auth_token(token)
53
+ raise ArgumentError, 'Parameter :token must be kind of String.' unless token.is_a?(String)
54
+
55
+ self.auth_token = token
56
+
44
57
  yield
45
58
  ensure
46
- self.service_token = nil
59
+ self.auth_token = nil
47
60
  end
48
61
 
49
62
  # @api public
50
- def self.service_token
51
- Thread.current['shark-service-token']
63
+ def self.auth_token
64
+ Thread.current['shark-auth-token']
52
65
  end
53
66
 
54
67
  # @api private
55
- def self.service_token=(value)
56
- Thread.current['shark-service-token'] = value
68
+ def self.auth_token=(value)
69
+ Thread.current['shark-auth-token'] = value
57
70
  end
58
71
 
59
72
  #
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: bima-shark-sdk
3
3
  version: !ruby/object:Gem::Version
4
- version: 3.0.0
4
+ version: 3.1.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - bima-team@justrelate.com
8
8
  autorequire:
9
9
  bindir: exe
10
10
  cert_chain: []
11
- date: 2024-09-19 00:00:00.000000000 Z
11
+ date: 2024-10-31 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: activesupport
@@ -261,7 +261,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
261
261
  - !ruby/object:Gem::Version
262
262
  version: '0'
263
263
  requirements: []
264
- rubygems_version: 3.4.19
264
+ rubygems_version: 3.2.22
265
265
  signing_key:
266
266
  specification_version: 4
267
267
  summary: ''