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 +4 -4
- data/.travis.yml +1 -1
- data/CHANGELOG.md +3 -0
- data/README.md +15 -0
- data/lib/shark/client/connection.rb +1 -3
- data/lib/shark/version.rb +1 -1
- data/lib/shark.rb +20 -7
- metadata +3 -3
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: c940902ca2481c64fa2c9713c82fae4a654be44bf52aac78f130975109d2e2d6
|
4
|
+
data.tar.gz: f9de212a3cda286061798bc1f058e1152bb3a6c36a91c26a95ed449fc6526ffe
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: dc9ee1ce1f478ba2f41df518b7bbcdd3b966d75c2a60fc19ad45d39d77eb449bb2e8e44412536b4ca353f91531d8c6198289e0b333c4ce9ff9174d09412c09e6
|
7
|
+
data.tar.gz: b568b142df1967556f5771e9439ed319c87f30e46691ed6c33a9d1fede56e83a8b8867c1599cbb72ca35f9b16d724915cfac615a1cb20dcdeb07cdb9a1fc4e36
|
data/.travis.yml
CHANGED
data/CHANGELOG.md
CHANGED
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.
|
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
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
|
-
|
37
|
+
auth_token = "Bearer #{token}"
|
38
38
|
elsif token.respond_to?(:jwt)
|
39
|
-
|
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.
|
59
|
+
self.auth_token = nil
|
47
60
|
end
|
48
61
|
|
49
62
|
# @api public
|
50
|
-
def self.
|
51
|
-
Thread.current['shark-
|
63
|
+
def self.auth_token
|
64
|
+
Thread.current['shark-auth-token']
|
52
65
|
end
|
53
66
|
|
54
67
|
# @api private
|
55
|
-
def self.
|
56
|
-
Thread.current['shark-
|
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.
|
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-
|
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.
|
264
|
+
rubygems_version: 3.2.22
|
265
265
|
signing_key:
|
266
266
|
specification_version: 4
|
267
267
|
summary: ''
|