bima-shark-sdk 2.3.0 → 2.4.1

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
  SHA1:
3
- metadata.gz: 7a9cc4def17d9461b6ddc032cba99930bfa2337d
4
- data.tar.gz: f6c2eeb6ee700a7ffd6a2d711ef4cfe81d7e0092
3
+ metadata.gz: c8147ff5d815f0cf58c4af42b9dc59fd12c42403
4
+ data.tar.gz: 0ccf7a38e06b849c464eedb854ed08e3ed529ad8
5
5
  SHA512:
6
- metadata.gz: 304bedeaea5bb6a8ed37b6c48f89c7173775d4c3e9b42c04838776b29d115c5820d7cca37d950a3d63252ea4d067b73b81f773413d12689f2d55efa6fb41787d
7
- data.tar.gz: f3f64da6335e24a50aa4e4b7e996a2773980fafc9ca7d25076c9157f33ef884c93f2836d5a84b60a93d6e3d8362fcc3c3305f62df03c161cf8e3da6e2798d841
6
+ metadata.gz: 3c38fb56121825215c37f16a0dde2aa4ff4b29b25adc7e8390bcfec1319844938fc19bb01e696d6bc857241ad5aaa0ca29d319fed5ac47ea45e71155bc177500
7
+ data.tar.gz: 4445572bb6d832693da5c3ff66405cada2c3b39332c994c32b71a4d3a6b1d6256837eb8d913db60f331e3b29e04a05dfe2a653620b96d397972b25e8797a78b1
data/CHANGELOG.md CHANGED
@@ -1,5 +1,14 @@
1
1
  ## Changelog
2
2
 
3
+ #### 2.4.1
4
+ - [fix] Form Service: Added missing `versions` association to `Form`
5
+
6
+ #### 2.4.0
7
+ - added `Shark::Contact#consents` and `Shark::Contact#create_contract`
8
+
9
+ #### 2.3.1
10
+ - [fix] expose `Shark::ContactLog`
11
+
3
12
  #### 2.3.0
4
13
  - `Shark::MailingService` template can `#render` partials
5
14
 
@@ -13,12 +13,6 @@ module Shark
13
13
  end
14
14
  end
15
15
 
16
- module ConsentService
17
- module Resource
18
- mattr_accessor :site
19
- end
20
- end
21
-
22
16
  module DoubleOptIn
23
17
  class ExceededNumberOfVerificationRequestsError < Error; end
24
18
  class RequestedUnverifiedExecutionError < Error; end
@@ -78,7 +72,6 @@ module Shark
78
72
  def initialize
79
73
  @asset_service = AssetService::Resource
80
74
  @contact_service = ContactService::Resource
81
- @consent_service = ConsentService::Resource
82
75
  @double_opt_in = DoubleOptIn::Resource
83
76
  @form_service = Service.new
84
77
  @mailing_service = Service.new
data/lib/shark/consent.rb CHANGED
@@ -2,27 +2,24 @@
2
2
 
3
3
  module Shark
4
4
  class Consent < Base
5
- extend ConsentService::Resource
5
+ extend ContactService::Resource
6
6
 
7
- def self.all
8
- raise Shark::ActionNotSupportedError,
9
- 'Shark::ConsentService::Consent.all is not supported'
10
- end
7
+ belongs_to :contact
11
8
 
12
9
  def update_attributes(_attributes = {})
13
10
  raise Shark::ActionNotSupportedError,
14
- 'Shark::ConsentService::Consent#update_attributes is not supported'
11
+ 'Shark::Consent#update_attributes is not supported'
15
12
  end
16
13
 
17
14
  def destroy
18
15
  raise Shark::ActionNotSupportedError,
19
- 'Shark::ConsentService::Consent#destroy is not supported'
16
+ 'Shark::Consent#destroy is not supported'
20
17
  end
21
18
 
22
19
  def save
23
20
  if self['id'].present?
24
21
  raise Shark::ActionNotSupportedError,
25
- 'Shark::ConsentService::Consent#save is not supported for persisted consents'
22
+ 'Shark::Consent#save is not supported for persisted consents'
26
23
  else
27
24
  super
28
25
  end
data/lib/shark/contact.rb CHANGED
@@ -36,5 +36,13 @@ module Shark
36
36
 
37
37
  Shark::Account.find(account_id).first
38
38
  end
39
+
40
+ def consents
41
+ Shark::Consent.where(contact_id: id)
42
+ end
43
+
44
+ def create_contract(params)
45
+ Shark::Contract.create(params.merge(contact_id: id))
46
+ end
39
47
  end
40
48
  end
@@ -0,0 +1,28 @@
1
+ # frozen_string_literal: true
2
+
3
+ module Shark
4
+ class Contract < Base
5
+ extend ContactService::Resource
6
+
7
+ belongs_to :contact
8
+
9
+ def update_attributes(_attributes = {})
10
+ raise Shark::ActionNotSupportedError,
11
+ 'Shark::Contract#update_attributes is not supported'
12
+ end
13
+
14
+ def destroy
15
+ raise Shark::ActionNotSupportedError,
16
+ 'Shark::Contract#destroy is not supported'
17
+ end
18
+
19
+ def save
20
+ if self['id'].present?
21
+ raise Shark::ActionNotSupportedError,
22
+ 'Shark::Contract#save is not supported for persisted consents'
23
+ else
24
+ super
25
+ end
26
+ end
27
+ end
28
+ end
@@ -4,6 +4,8 @@ module Shark
4
4
  module FormService
5
5
  module V2
6
6
  class Form < V2::Base
7
+ has_many :versions
8
+
7
9
  # @example
8
10
  # form = Shark::FormService::V2::Form.find(id)
9
11
  # form.activate
@@ -32,7 +32,7 @@ module Shark
32
32
  log_info '[Shark][ContactService] Faking GET request'
33
33
  log_info request.uri.to_s
34
34
 
35
- type = request.uri.path.split('/')[2]
35
+ type = request.uri.path.split('/')[-1]
36
36
  params = query_params_to_object(request.uri)
37
37
 
38
38
  objects = if %w[contacts accounts].include?(type) && params['filter'].present?
@@ -52,8 +52,8 @@ module Shark
52
52
  log_info '[Shark][ContactService] Faking GET request with ID'
53
53
  log_info request.uri.to_s
54
54
 
55
- type = request.uri.path.split('/')[2]
56
- id = request.uri.path.split('/')[3]
55
+ type = request.uri.path.split('/')[-2]
56
+ id = request.uri.path.split('/')[-1]
57
57
  query = request.uri.query_values
58
58
 
59
59
  object = cache.find(type, id)
@@ -84,11 +84,10 @@ module Shark
84
84
  log_info '[Shark][ContactService] Faking GET memberships request'
85
85
  log_info request.uri.to_s
86
86
 
87
- type = request.uri.path.split('/')[2]
88
- group_id = request.uri.path.split('/')[3]
87
+ group_id = request.uri.path.split('/')[-2]
89
88
  contact_id = query_params_to_object(request.uri)['filter']['contact_id']
90
89
 
91
- group = cache.find(type, group_id)
90
+ group = cache.find('groups', group_id)
92
91
 
93
92
  if group.present?
94
93
  contacts = group.dig('relationships', 'contacts', 'data')
@@ -107,8 +106,8 @@ module Shark
107
106
  log_info "[Shark][ContactService] Faking PATCH request with body: #{request.body}"
108
107
  log_info request.uri.to_s
109
108
 
110
- type = request.uri.path.split('/')[2]
111
- id = request.uri.path.split('/')[3]
109
+ type = request.uri.path.split('/')[-2]
110
+ id = request.uri.path.split('/')[-1]
112
111
  parsed_data = JSON.parse(request.body)['data']
113
112
 
114
113
  object = cache.find(type, id)
@@ -134,8 +133,8 @@ module Shark
134
133
  log_info '[Shark][ContactService] Faking DELETE request'
135
134
  log_info request.uri.to_s
136
135
 
137
- type = request.uri.path.split('/')[2]
138
- id = request.uri.path.split('/')[3]
136
+ type = request.uri.path.split('/')[-2]
137
+ id = request.uri.path.split('/')[-1]
139
138
 
140
139
  object = cache.find(type, id)
141
140
 
@@ -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_consent_service'
9
8
  require_relative 'fake_subscription_service'
10
9
  require_relative 'fake_double_opt_in'
11
10
  require_relative 'fake_mailing_service'
data/lib/shark/version.rb CHANGED
@@ -1,5 +1,5 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  module Shark
4
- VERSION = '2.3.0'
4
+ VERSION = '2.4.1'
5
5
  end
data/lib/shark.rb CHANGED
@@ -74,6 +74,7 @@ require 'shark/account'
74
74
  require 'shark/activity'
75
75
  require 'shark/consent'
76
76
  require 'shark/contact'
77
+ require 'shark/contract'
77
78
  require 'shark/double_opt_in/execution'
78
79
  require 'shark/double_opt_in/request'
79
80
  require 'shark/group'
@@ -84,6 +85,7 @@ require 'shark/permission'
84
85
  require 'shark/subscription'
85
86
  require 'shark/survey'
86
87
  require 'shark/survey_participant'
88
+ require 'shark/contact_log'
87
89
 
88
90
  require 'shark/form_service'
89
91
  require 'shark/mailing_service'
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: bima-shark-sdk
3
3
  version: !ruby/object:Gem::Version
4
- version: 2.3.0
4
+ version: 2.4.1
5
5
  platform: ruby
6
6
  authors:
7
7
  - Huy Dinh
@@ -10,7 +10,7 @@ authors:
10
10
  autorequire:
11
11
  bindir: exe
12
12
  cert_chain: []
13
- date: 2022-01-04 00:00:00.000000000 Z
13
+ date: 2022-07-01 00:00:00.000000000 Z
14
14
  dependencies:
15
15
  - !ruby/object:Gem::Dependency
16
16
  name: activesupport
@@ -199,6 +199,7 @@ files:
199
199
  - lib/shark/consent.rb
200
200
  - lib/shark/contact.rb
201
201
  - lib/shark/contact_log.rb
202
+ - lib/shark/contract.rb
202
203
  - lib/shark/double_opt_in/execution.rb
203
204
  - lib/shark/double_opt_in/request.rb
204
205
  - lib/shark/error.rb
@@ -235,9 +236,6 @@ files:
235
236
  - lib/shark/rspec/fake_asset_service/object_cache.rb
236
237
  - lib/shark/rspec/fake_asset_service/public_id.rb
237
238
  - lib/shark/rspec/fake_asset_service/request.rb
238
- - lib/shark/rspec/fake_consent_service.rb
239
- - lib/shark/rspec/fake_consent_service/object_cache.rb
240
- - lib/shark/rspec/fake_consent_service/request.rb
241
239
  - lib/shark/rspec/fake_contact_service.rb
242
240
  - lib/shark/rspec/fake_contact_service/object_cache.rb
243
241
  - lib/shark/rspec/fake_contact_service/request.rb
@@ -1,44 +0,0 @@
1
- # frozen_string_literal: true
2
-
3
- module Shark
4
- module RSpec
5
- module FakeConsentService
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['attributes']['legal_subject_id']
20
- existing_object = objects.detect { |o| o['id'] == id }
21
-
22
- items = (existing_object.present? && existing_object['attributes']['items']) || {}
23
-
24
- (payload_data['attributes']['items'] || {}).each do |name, attrs|
25
- items[name] = attrs.merge({ 'updated_at' => Time.now })
26
- end
27
-
28
- objects.delete_if { |o| o['id'] == id }
29
-
30
- object = {
31
- 'id' => id,
32
- 'attributes' => {
33
- 'items' => items
34
- },
35
- 'type' => 'consents'
36
- }
37
-
38
- objects.push(object)
39
- object
40
- end
41
- end
42
- end
43
- end
44
- end
@@ -1,53 +0,0 @@
1
- # frozen_string_literal: true
2
-
3
- require 'webmock/rspec'
4
-
5
- module Shark
6
- module RSpec
7
- module FakeConsentService
8
- class Request
9
- include Singleton
10
-
11
- def self.setup
12
- instance = self.instance
13
- instance.stub_requests
14
- end
15
-
16
- def stub_requests
17
- WebMock.stub_request(:post, %r{^#{host}/consents}).to_return do |request|
18
- log_info "[Shark][ConsentService] Faking POST request with body: #{request.body}"
19
-
20
- payload_data = JSON.parse(request.body)['data']
21
- object_data = ObjectCache.instance.add(payload_data)
22
-
23
- SharkSpec.fake_response(200, data: object_data)
24
- end
25
-
26
- WebMock.stub_request(:get, %r{^#{host}/consents/.+}).to_return do |request|
27
- log_info '[Shark][ConsentService] Faking GET request'
28
-
29
- id = request.uri.path.split('/')[2]
30
-
31
- object_data = ObjectCache.instance.objects.detect do |object|
32
- object['id'] == id
33
- end
34
-
35
- if object_data.present?
36
- SharkSpec.fake_response(200, data: object_data)
37
- else
38
- SharkSpec.fake_response(404, errors: [])
39
- end
40
- end
41
- end
42
-
43
- def host
44
- Shark.configuration.consent_service.site
45
- end
46
-
47
- def log_info(message)
48
- Shark.logger.info message
49
- end
50
- end
51
- end
52
- end
53
- end
@@ -1,19 +0,0 @@
1
- # frozen_string_literal: true
2
-
3
- require_relative 'fake_consent_service/object_cache'
4
- require_relative 'fake_consent_service/request'
5
-
6
- module Shark
7
- module RSpec
8
- module FakeConsentService
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