bima-shark-sdk 2.4.3 → 2.5.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 +5 -5
- data/.rubocop.yml +1 -1
- data/.travis.yml +3 -3
- data/CHANGELOG.md +8 -0
- data/README.md +15 -0
- data/lib/shark/client/connection.rb +1 -3
- data/lib/shark/configuration.rb +0 -8
- data/lib/shark/double_opt_in/execution.rb +2 -2
- data/lib/shark/mailing_service/mailer.rb +0 -2
- data/lib/shark/rspec/helpers.rb +0 -1
- data/lib/shark/version.rb +1 -1
- data/lib/shark.rb +21 -9
- metadata +6 -11
- data/lib/shark/rspec/fake_subscription_service/object_cache.rb +0 -54
- data/lib/shark/rspec/fake_subscription_service/request.rb +0 -100
- data/lib/shark/rspec/fake_subscription_service.rb +0 -19
- data/lib/shark/subscription.rb +0 -43
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
|
-
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
2
|
+
SHA256:
|
3
|
+
metadata.gz: 8ab74483354f85310c09fe0f53a00143fbd8042e81b0ed8d7226d77909ff2e24
|
4
|
+
data.tar.gz: 4c2d6b001cd4dfbd451c59c2e27368b55ecca753fd0a63f4a4350216b790be91
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 26060a07b63c8f2c37a5fe505a5e4aee3bb907ebe1a75340ae4676b05dbdc3377d2e6175ef12fe62e019d98f77680df720527b947f8ffd4e1e0ccb4066ce44fa
|
7
|
+
data.tar.gz: 13f5e6dd6a7b1b83c98f8e40232349e6d8eaa30f60058363d838491596eb06ee2f8a37cf08868ea71316bd77b5d08c90d5bbd7c151db5120fce8fcf2edb91e24
|
data/.rubocop.yml
CHANGED
data/.travis.yml
CHANGED
data/CHANGELOG.md
CHANGED
@@ -1,5 +1,13 @@
|
|
1
1
|
## Changelog
|
2
2
|
|
3
|
+
#### 2.5.0
|
4
|
+
- Extend `with_service_token` with `with_auth_token` which allows to send custom `Authorization` header, not only `Bearer`
|
5
|
+
- remove `Shark::Subscription`
|
6
|
+
|
7
|
+
#### 2.4.4
|
8
|
+
* lowest supported Ruby version is 2.7
|
9
|
+
* add `recipient` to `Shark::DoubleOptIn::Execution`
|
10
|
+
|
3
11
|
#### 2.4.3
|
4
12
|
- allow `Shark::MailingService::Mailer#mail` to use separate layouts
|
5
13
|
- rename `Shark::MailingService::Mailers::BaseMailer` to `Shark::MailingService::Mailer`
|
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/configuration.rb
CHANGED
@@ -29,12 +29,6 @@ module Shark
|
|
29
29
|
end
|
30
30
|
end
|
31
31
|
|
32
|
-
module SubscriptionService
|
33
|
-
module Resource
|
34
|
-
mattr_accessor :site
|
35
|
-
end
|
36
|
-
end
|
37
|
-
|
38
32
|
module SurveyService
|
39
33
|
module Resource
|
40
34
|
mattr_accessor :site
|
@@ -65,7 +59,6 @@ module Shark
|
|
65
59
|
attr_reader :form_service
|
66
60
|
attr_reader :survey_service
|
67
61
|
attr_reader :notification_service
|
68
|
-
attr_reader :subscription_service
|
69
62
|
attr_reader :asset_service
|
70
63
|
attr_reader :mailing_service
|
71
64
|
|
@@ -76,7 +69,6 @@ module Shark
|
|
76
69
|
@form_service = Service.new
|
77
70
|
@mailing_service = Service.new
|
78
71
|
@notification_service = NotificationService::Resource
|
79
|
-
@subscription_service = SubscriptionService::Resource
|
80
72
|
@survey_service = SurveyService::Resource
|
81
73
|
end
|
82
74
|
end
|
@@ -5,7 +5,7 @@ module Shark
|
|
5
5
|
class Execution < Base
|
6
6
|
extend DoubleOptIn::Resource
|
7
7
|
|
8
|
-
attr_accessor :payload, :request_type
|
8
|
+
attr_accessor :payload, :request_type, :recipient
|
9
9
|
|
10
10
|
def self.verify(verification_token)
|
11
11
|
response = connection.run(:post, "/executions/#{verification_token}/verify")
|
@@ -37,7 +37,7 @@ module Shark
|
|
37
37
|
end
|
38
38
|
|
39
39
|
def initialize(data)
|
40
|
-
%w[payload request_type].each do |key|
|
40
|
+
%w[payload request_type recipient].each do |key|
|
41
41
|
public_send("#{key}=", data['attributes'][key])
|
42
42
|
end
|
43
43
|
end
|
data/lib/shark/rspec/helpers.rb
CHANGED
@@ -5,7 +5,6 @@ require_relative 'helpers/cache_helper'
|
|
5
5
|
require_relative 'fake_asset_service'
|
6
6
|
require_relative 'fake_contact_service'
|
7
7
|
require_relative 'fake_notification_service'
|
8
|
-
require_relative 'fake_subscription_service'
|
9
8
|
require_relative 'fake_double_opt_in'
|
10
9
|
require_relative 'fake_mailing_service'
|
11
10
|
require_relative 'fake_survey_service'
|
data/lib/shark/version.rb
CHANGED
data/lib/shark.rb
CHANGED
@@ -32,28 +32,41 @@ module Shark
|
|
32
32
|
# @param token [String] The service token for the authorization header
|
33
33
|
# @param block [Block] The block where service token authorization will be set for
|
34
34
|
# @api public
|
35
|
-
def self.with_service_token(token)
|
35
|
+
def self.with_service_token(token, &block)
|
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, &block)
|
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
|
#
|
@@ -82,7 +95,6 @@ require 'shark/membership'
|
|
82
95
|
require 'shark/notification'
|
83
96
|
require 'shark/package'
|
84
97
|
require 'shark/permission'
|
85
|
-
require 'shark/subscription'
|
86
98
|
require 'shark/survey'
|
87
99
|
require 'shark/survey_participant'
|
88
100
|
require 'shark/contact_log'
|
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: 2.
|
4
|
+
version: 2.5.0
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- bima-team@justrelate.com
|
8
|
-
autorequire:
|
8
|
+
autorequire:
|
9
9
|
bindir: exe
|
10
10
|
cert_chain: []
|
11
|
-
date:
|
11
|
+
date: 2024-11-04 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: activesupport
|
@@ -244,9 +244,6 @@ files:
|
|
244
244
|
- lib/shark/rspec/fake_mailing_service/request.rb
|
245
245
|
- lib/shark/rspec/fake_notification_service.rb
|
246
246
|
- lib/shark/rspec/fake_notification_service/request.rb
|
247
|
-
- lib/shark/rspec/fake_subscription_service.rb
|
248
|
-
- lib/shark/rspec/fake_subscription_service/object_cache.rb
|
249
|
-
- lib/shark/rspec/fake_subscription_service/request.rb
|
250
247
|
- lib/shark/rspec/fake_survey_service.rb
|
251
248
|
- lib/shark/rspec/fake_survey_service/object_cache.rb
|
252
249
|
- lib/shark/rspec/fake_survey_service/request.rb
|
@@ -257,14 +254,13 @@ files:
|
|
257
254
|
- lib/shark/rspec/helpers/fixtures.rb
|
258
255
|
- lib/shark/rspec/helpers/form_service_helper.rb
|
259
256
|
- lib/shark/rspec/helpers/response.rb
|
260
|
-
- lib/shark/subscription.rb
|
261
257
|
- lib/shark/survey.rb
|
262
258
|
- lib/shark/survey_participant.rb
|
263
259
|
- lib/shark/version.rb
|
264
260
|
homepage: https://github.com/infopark-customers/bima-shark-sdk
|
265
261
|
licenses: []
|
266
262
|
metadata: {}
|
267
|
-
post_install_message:
|
263
|
+
post_install_message:
|
268
264
|
rdoc_options: []
|
269
265
|
require_paths:
|
270
266
|
- lib
|
@@ -279,9 +275,8 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
279
275
|
- !ruby/object:Gem::Version
|
280
276
|
version: '0'
|
281
277
|
requirements: []
|
282
|
-
|
283
|
-
|
284
|
-
signing_key:
|
278
|
+
rubygems_version: 3.5.17
|
279
|
+
signing_key:
|
285
280
|
specification_version: 4
|
286
281
|
summary: ''
|
287
282
|
test_files: []
|
@@ -1,54 +0,0 @@
|
|
1
|
-
# frozen_string_literal: true
|
2
|
-
|
3
|
-
module Shark
|
4
|
-
module RSpec
|
5
|
-
module FakeSubscriptionService
|
6
|
-
class ObjectCache
|
7
|
-
include Singleton
|
8
|
-
attr_accessor :objects
|
9
|
-
|
10
|
-
def initialize
|
11
|
-
@objects = []
|
12
|
-
end
|
13
|
-
|
14
|
-
def self.clear
|
15
|
-
instance.objects = []
|
16
|
-
end
|
17
|
-
|
18
|
-
def add(payload_data)
|
19
|
-
id = payload_data.delete('id')
|
20
|
-
|
21
|
-
if id && !objects.find { |subscription| subscription['id'] == id }
|
22
|
-
object = {
|
23
|
-
id: id,
|
24
|
-
attributes: payload_data
|
25
|
-
}
|
26
|
-
|
27
|
-
objects << object
|
28
|
-
else
|
29
|
-
objects << {
|
30
|
-
id: SecureRandom.uuid,
|
31
|
-
attributes: payload_data
|
32
|
-
}
|
33
|
-
end
|
34
|
-
objects.last
|
35
|
-
end
|
36
|
-
|
37
|
-
def add_multiple(payload_data)
|
38
|
-
added = []
|
39
|
-
payload_data.each { |subscription| added << add(subscription) }
|
40
|
-
added.compact
|
41
|
-
end
|
42
|
-
|
43
|
-
def remove(id)
|
44
|
-
objects.delete_if { |subscription| subscription[:id] == id }
|
45
|
-
end
|
46
|
-
|
47
|
-
def remove_multiple(payload_data)
|
48
|
-
payload_data.each { |subscription| remove(subscription['id']) }
|
49
|
-
objects
|
50
|
-
end
|
51
|
-
end
|
52
|
-
end
|
53
|
-
end
|
54
|
-
end
|
@@ -1,100 +0,0 @@
|
|
1
|
-
# frozen_string_literal: true
|
2
|
-
|
3
|
-
require 'webmock/rspec'
|
4
|
-
|
5
|
-
module Shark
|
6
|
-
module RSpec
|
7
|
-
module FakeSubscriptionService
|
8
|
-
class Request
|
9
|
-
include Singleton
|
10
|
-
|
11
|
-
ALLOWED_FILTERS = %w[name subscriberId].freeze
|
12
|
-
|
13
|
-
def self.setup
|
14
|
-
instance = self.instance
|
15
|
-
instance.stub_requests
|
16
|
-
end
|
17
|
-
|
18
|
-
def stub_requests
|
19
|
-
WebMock.stub_request(:post, %r{^#{host}/subscriptions}).to_return do |request|
|
20
|
-
log_info "Faking POST request with body: #{request.body}"
|
21
|
-
|
22
|
-
payload_data = JSON.parse(request.body)['data']['attributes']
|
23
|
-
|
24
|
-
object_data = ObjectCache.instance.add(payload_data)
|
25
|
-
|
26
|
-
SharkSpec.fake_response(201, data: object_data)
|
27
|
-
end
|
28
|
-
|
29
|
-
WebMock.stub_request(
|
30
|
-
:post,
|
31
|
-
%r{^#{host}/subscriptions/bulk_creation}
|
32
|
-
).to_return do |request|
|
33
|
-
log_info "Faking POST request with body: #{request.body}"
|
34
|
-
|
35
|
-
payload_data = JSON.parse(request.body)['data']['attributes']['subscriptions']
|
36
|
-
|
37
|
-
objects_data = ObjectCache.instance.add_multiple(payload_data)
|
38
|
-
|
39
|
-
SharkSpec.fake_response(201, data: objects_data)
|
40
|
-
end
|
41
|
-
|
42
|
-
WebMock.stub_request(
|
43
|
-
:post,
|
44
|
-
%r{^#{host}/subscriptions/bulk_deletion}
|
45
|
-
).to_return do |request|
|
46
|
-
log_info "Faking POST request with body: #{request.body}"
|
47
|
-
|
48
|
-
payload_data = JSON.parse(request.body)['data']['attributes']['subscriptions']
|
49
|
-
ObjectCache.instance.remove_multiple(payload_data)
|
50
|
-
|
51
|
-
SharkSpec.fake_response(204, nil)
|
52
|
-
end
|
53
|
-
|
54
|
-
WebMock.stub_request(:delete, %r{^#{host}/subscriptions/.+}).to_return do |request|
|
55
|
-
log_info "Faking DELETE request with body: #{request.body}"
|
56
|
-
|
57
|
-
id = request.uri.path.split('/')[2]
|
58
|
-
|
59
|
-
ObjectCache.instance.remove(id)
|
60
|
-
|
61
|
-
SharkSpec.fake_response(204, nil)
|
62
|
-
end
|
63
|
-
|
64
|
-
WebMock.stub_request(:get, %r{^#{host}/subscriptions}).to_return do |request|
|
65
|
-
log_info 'Faking GET request'
|
66
|
-
|
67
|
-
query_parameters = request.uri.query_values
|
68
|
-
|
69
|
-
objects_data = if query_parameters
|
70
|
-
params = {}
|
71
|
-
query_parameters.each do |key, value|
|
72
|
-
parsed_key = key.match(/filter\[(.*)\]/)[1].camelize(:lower)
|
73
|
-
params[parsed_key] = value if ALLOWED_FILTERS.include?(parsed_key)
|
74
|
-
end
|
75
|
-
|
76
|
-
ObjectCache.instance.objects.select do |subscription|
|
77
|
-
conditions = params.map do |param, value|
|
78
|
-
subscription[:attributes][param] == value
|
79
|
-
end
|
80
|
-
conditions.all?
|
81
|
-
end
|
82
|
-
else
|
83
|
-
ObjectCache.instance.objects
|
84
|
-
end
|
85
|
-
|
86
|
-
SharkSpec.fake_response(200, data: objects_data)
|
87
|
-
end
|
88
|
-
end
|
89
|
-
|
90
|
-
def host
|
91
|
-
Shark.configuration.subscription_service.site
|
92
|
-
end
|
93
|
-
|
94
|
-
def log_info(message)
|
95
|
-
Shark.logger.info "[Shark::SubscriptionService] #{message}"
|
96
|
-
end
|
97
|
-
end
|
98
|
-
end
|
99
|
-
end
|
100
|
-
end
|
@@ -1,19 +0,0 @@
|
|
1
|
-
# frozen_string_literal: true
|
2
|
-
|
3
|
-
require_relative 'fake_subscription_service/object_cache'
|
4
|
-
require_relative 'fake_subscription_service/request'
|
5
|
-
|
6
|
-
module Shark
|
7
|
-
module RSpec
|
8
|
-
module FakeSubscriptionService
|
9
|
-
def self.setup
|
10
|
-
ObjectCache.clear
|
11
|
-
Request.setup
|
12
|
-
end
|
13
|
-
|
14
|
-
def self.reset
|
15
|
-
ObjectCache.clear
|
16
|
-
end
|
17
|
-
end
|
18
|
-
end
|
19
|
-
end
|
data/lib/shark/subscription.rb
DELETED
@@ -1,43 +0,0 @@
|
|
1
|
-
# frozen_string_literal: true
|
2
|
-
|
3
|
-
module Shark
|
4
|
-
class Subscription < Base
|
5
|
-
extend SubscriptionService::Resource
|
6
|
-
|
7
|
-
custom_endpoint :bulk_creation, on: :collection, request_method: :post
|
8
|
-
custom_endpoint :bulk_deletion, on: :collection, request_method: :post
|
9
|
-
|
10
|
-
def self.create_multiple(attributes)
|
11
|
-
bulk_creation(subscriptions_attributes(attributes))
|
12
|
-
end
|
13
|
-
|
14
|
-
def self.destroy_multiple(attributes)
|
15
|
-
bulk_deletion(subscriptions_attributes(attributes))
|
16
|
-
end
|
17
|
-
|
18
|
-
def save
|
19
|
-
if self['id'].present?
|
20
|
-
raise Shark::ActionNotSupportedError,
|
21
|
-
'Shark::Subscription#save is not supported for persisted subscriptions'
|
22
|
-
else
|
23
|
-
super
|
24
|
-
end
|
25
|
-
end
|
26
|
-
|
27
|
-
def update_attributes(_attributes = {})
|
28
|
-
raise Shark::ActionNotSupportedError,
|
29
|
-
'Shark::Subscription#update_attributes is not supported'
|
30
|
-
end
|
31
|
-
|
32
|
-
def self.subscriptions_attributes(attributes)
|
33
|
-
{
|
34
|
-
data: {
|
35
|
-
type: 'bulk-subscriptions',
|
36
|
-
attributes: {
|
37
|
-
subscriptions: attributes
|
38
|
-
}
|
39
|
-
}
|
40
|
-
}
|
41
|
-
end
|
42
|
-
end
|
43
|
-
end
|