bima-shark-sdk 3.0.0 → 3.1.1

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: d78520920a648b39f4efce4f0f09cf03ae7c1b9ae65022311dfc8d6f7e557f82
4
+ data.tar.gz: 10d37b688c20efe9010f33e0734cbb0fbe5c45eef667c037e4614fb5e132bcd9
5
5
  SHA512:
6
- metadata.gz: '078265caf5dd06022b0ae91356fd4bd9f8093a879c1191a55297280786be708950652563cf1d5ccb9df8a51c5b9bec7a66f7f8b534eb865ad6142b757310a216'
7
- data.tar.gz: ae7031d4aee957a60d2791122b650a713c77b75fa0c661b84444830cc463c5f40ac69dda0f19ed296cf22d7acee21f76346973e523ccb8316bf16ce4ed178ab6
6
+ metadata.gz: 79cba1cf92c07d7f73a2344b7de0c6c70d8fe03e0722c7331adcece266d348f4976ac980ad12e3c09d3fcb47f20bbb573bb48b7ac1218353e1de031ebdd8ca63
7
+ data.tar.gz: 9f6242f47a12c9f7a9761f2eeae415d930546c76346c01390482c024afbf42cb70eb92fd8132855589d3b604bebb0936e9190555bb86e40f6dafd60e7a53b095
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,11 @@
1
1
  ## Changelog
2
2
 
3
+ #### 3.1.1
4
+ - Extend Shark::Configuration with `access_id` and `secret_key`
5
+
6
+ #### 3.1.0
7
+ - Extend `with_service_token` with `with_auth_token` which allows to send custom `Authorization` header, not only `Bearer`
8
+
3
9
  #### 3.0.0
4
10
  - new minimum requirements are `Ruby 3.0` and `faraday 2.0`
5
11
  - 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
  ```
data/bin/console CHANGED
@@ -7,17 +7,11 @@ require 'shark'
7
7
  # You can add fixtures and/or initialization code here to make experimenting
8
8
  # with your gem easier. You can also use a different console, if you like.
9
9
 
10
- # (If you use this, don't forget to add pry to your Gemfile!)
11
- # require "pry"
12
- # Pry.start
13
-
14
- # TODO
15
10
  Shark.configure do |config|
16
11
  config.contact_service.site = 'https://contactservice-development.bundesimmo.de/api/'
17
12
  config.survey_service.site = 'https://milacrm-development.bundesimmo.de/api/v1/'
18
13
  config.form_service.site = 'https://formservice-development.bundesimmo.de/api/v1/'
19
14
  config.notification_service.site = 'https://api-development.bundesimmo.de/notification-service/'
20
- config.subscription_service.site = 'https://api-development.bundesimmo.de/subscription-service/'
21
15
  end
22
16
 
23
17
  require 'irb'
@@ -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)
@@ -53,6 +53,7 @@ module Shark
53
53
  # Shark Configuration
54
54
  #
55
55
  attr_accessor :cache, :logger
56
+ attr_accessor :access_id, :secret_key
56
57
  attr_reader :contact_service
57
58
  attr_reader :consent_service
58
59
  attr_reader :double_opt_in
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.1'
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.1
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-11-08 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: ''