tokyo_api 1.1.0 → 1.1.2

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: bdd1545cc1b4afe1f6eafc3340d94c7ddb37c0cd90e7fe503141379bb9376e53
4
- data.tar.gz: a9fdad05531bea8f72116ae4acfecf1e63ce175bb746ee174f14dae41f4c8053
3
+ metadata.gz: 5502304c73c869022683e520632e96fc836a552bfb98b876498476121bfb620e
4
+ data.tar.gz: 517684ab971c1d9ed655991090a11c87688414cefee2df384b1d4e642dcbc627
5
5
  SHA512:
6
- metadata.gz: af6a4d89de242ddea6be9ea408d8294467cd6188421a777f489032b3b35fdb872e220ba4b319695895fc8a93b3519cf910d2891d17f8e3310e9674d61f5642c1
7
- data.tar.gz: ae88b3862d4cd5e703f7dcb87c6e2f9a2b9fb96cb7697441a1596fd307054d1ee9439110ffb8792abaab9ad2bf726a182547306a506ad144807cc66c2e34c7c6
6
+ metadata.gz: 0e0b6958e59a6fa7c3ede1d910b3a75fe002bd1741d999b7330bfa79d071590ef12bad60af9769fb9c4af43f3b06e05fbc271dc8996a4ee1bf8b60f713f3f1ce
7
+ data.tar.gz: d10d735108fefa5a62bde79320e3a4184f62f108e878d813c2e7f0de3631aa0f6f91529298e701aacf0302f20bfe7967498a0dbea06dcc473973c7317897d115
data/VERSION CHANGED
@@ -1 +1 @@
1
- 1.1.0
1
+ 1.1.2
@@ -8,22 +8,46 @@ module TokyoApi
8
8
  client.get_request("#{normalized_base_path}full_user/#{url_escape(id)}").body
9
9
  end
10
10
 
11
- def tokyo_identity_user_path(id, required_fields: nil)
11
+ def tokyo_identity_user_path(id, with_subscription_status: false, required_fields: nil, opt_in_public_ids: nil, minimum_consent_level: nil)
12
12
  path = "/#{normalized_base_path}user/#{url_escape(id)}"
13
13
 
14
+ params = []
14
15
  unless required_fields.nil?
15
- path << "?#{required_fields_param(required_fields)}"
16
+ params << required_fields_param(required_fields)
16
17
  end
18
+
19
+ if with_subscription_status
20
+ params << 'with_subscription_status=true'
21
+ additional_subscription_parameters = path_for_subscription_status_params(opt_in_public_ids, minimum_consent_level)
22
+ unless additional_subscription_parameters.blank?
23
+ params << additional_subscription_parameters
24
+ end
25
+ end
26
+
27
+ if params.any?
28
+ path << "?#{params.join('&')}"
29
+ end
30
+
17
31
  path
18
32
  end
19
33
 
20
34
  def subscription_status_path(id, opt_in_public_ids: nil, minimum_consent_level: nil)
21
35
  raise 'must provide opt_in_public_ids' if opt_in_public_ids.nil?
22
36
 
23
- path = "/#{normalized_base_path}subscription_status/#{url_escape(id)}?opt_in_public_ids=#{url_escape(opt_in_public_ids.join(','))}"
37
+ "/#{normalized_base_path}subscription_status/#{url_escape(id)}?#{path_for_subscription_status_params(opt_in_public_ids, minimum_consent_level)}"
38
+ end
39
+
40
+ private
41
+
42
+ def path_for_subscription_status_params(opt_in_public_ids, minimum_consent_level)
43
+ path = ''
44
+
45
+ if opt_in_public_ids.present?
46
+ path = "opt_in_public_ids=#{url_escape(opt_in_public_ids.join(','))}"
47
+ end
24
48
 
25
49
  if minimum_consent_level
26
- path = "#{path}&minimum_consent_level=#{url_escape(minimum_consent_level)}"
50
+ path << "&minimum_consent_level=#{url_escape(minimum_consent_level)}"
27
51
  end
28
52
 
29
53
  path
@@ -25,8 +25,11 @@ module TokyoApi
25
25
  end
26
26
  end
27
27
 
28
- def user_path(session_id, petition_id:, required_fields: nil)
28
+ def user_path(session_id, petition_id:, with_subscription_status: false, required_fields: nil)
29
29
  path = "/#{normalized_base_path}user/#{url_escape(session_id)}?petition_id=#{url_escape(petition_id)}"
30
+ if with_subscription_status
31
+ path << '&with_subscription_status=true'
32
+ end
30
33
  unless required_fields.nil?
31
34
  path << "&#{required_fields_param(required_fields)}"
32
35
  end
@@ -53,6 +53,43 @@ describe TokyoApi::Identity do
53
53
  expect(subject.identity.tokyo_identity_user_path('-123456', required_fields: ['email', 'fish & chips'])).to eq('/identity/user/-123456?required_fields=email,fish+%26+chips')
54
54
  end
55
55
  end
56
+
57
+ context 'with_subscription_status and associated arguments' do
58
+ it 'should not include query string parameter if argument is missing' do
59
+ expect(subject.identity.tokyo_identity_user_path('123abc456')).not_to match /.+with_subscription_status=.+/
60
+ end
61
+
62
+ it 'should not include query string parameter if argument is false' do
63
+ expect(subject.identity.tokyo_identity_user_path('123abc456', with_subscription_status: false)).not_to match /.+with_subscription_status=.+/
64
+ end
65
+
66
+ it 'should not include opt_in_public_ids and minimum_consent_level if with_subscription_status is false' do
67
+ tokyo_path = subject.identity.tokyo_identity_user_path('123abc456',
68
+ with_subscription_status: false,
69
+ opt_in_public_ids: ['policy-1.5'],
70
+ minimum_consent_level: 'explicit')
71
+
72
+ expect(tokyo_path).not_to match /.+opt_in_public_ids=.+/
73
+ expect(tokyo_path).not_to match /.+minimum_consent_level=.+/
74
+ end
75
+
76
+ it 'should include query string parameter if argument is true' do
77
+ expect(subject.identity.tokyo_identity_user_path('123abc456', with_subscription_status: true)).to match /.+with_subscription_status=.+/
78
+ end
79
+
80
+ it 'should include opt_in_public_ids and minimum_consent_level if with_subscription_status is true' do
81
+ tokyo_path = subject.identity.tokyo_identity_user_path('123abc456',
82
+ required_fields: [:first_name, :last_name, :email, :postal, :phone],
83
+ with_subscription_status: true,
84
+ opt_in_public_ids: ['policy-1.5'],
85
+ minimum_consent_level: 'explicit')
86
+
87
+ expect(tokyo_path).to match /.+with_subscription_status=true.*/
88
+ expect(tokyo_path).to match /.+opt_in_public_ids=.+/
89
+ expect(tokyo_path).to match /.+minimum_consent_level=.+/
90
+ expect { URI::parse(tokyo_path) }.not_to raise_error
91
+ end
92
+ end
56
93
  end
57
94
 
58
95
  describe '#subscription_status_path' do
@@ -86,6 +86,20 @@ describe TokyoApi::Krautbuster do
86
86
  expect(subject.krautbuster.user_path('123abc456', petition_id: 'save-the-trees', required_fields: ['email', 'fish & chips'])).to eq '/krautbuster/user/123abc456?petition_id=save-the-trees&required_fields=email,fish+%26+chips'
87
87
  end
88
88
  end
89
+
90
+ context 'with_subscription_status argument' do
91
+ it 'should not include query string parameter if argument is missing' do
92
+ expect(subject.krautbuster.user_path('123abc456', petition_id: 'save-the-trees')).not_to match /.+with_subscription_status=.+/
93
+ end
94
+
95
+ it 'should not include query string parameter if argument is false' do
96
+ expect(subject.krautbuster.user_path('123abc456', petition_id: 'save-the-trees', with_subscription_status: false)).not_to match /.+with_subscription_status=.+/
97
+ end
98
+
99
+ it 'should include query string parameter if argument is true' do
100
+ expect(subject.krautbuster.user_path('123abc456', petition_id: 'save-the-trees', with_subscription_status: true)).to match /.+with_subscription_status=true.*/
101
+ end
102
+ end
89
103
  end
90
104
 
91
105
  describe '#subscription_status_path' do
data/tokyo_api.gemspec CHANGED
@@ -2,11 +2,11 @@
2
2
  # DO NOT EDIT THIS FILE DIRECTLY
3
3
  # Instead, edit Juwelier::Tasks in Rakefile, and run 'rake gemspec'
4
4
  # -*- encoding: utf-8 -*-
5
- # stub: tokyo_api 1.1.0 ruby lib
5
+ # stub: tokyo_api 1.1.2 ruby lib
6
6
 
7
7
  Gem::Specification.new do |s|
8
8
  s.name = "tokyo_api".freeze
9
- s.version = "1.1.0"
9
+ s.version = "1.1.2"
10
10
 
11
11
  s.required_rubygems_version = Gem::Requirement.new(">= 0".freeze) if s.respond_to? :required_rubygems_version=
12
12
  s.require_paths = ["lib".freeze]
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: tokyo_api
3
3
  version: !ruby/object:Gem::Version
4
- version: 1.1.0
4
+ version: 1.1.2
5
5
  platform: ruby
6
6
  authors:
7
7
  - Nathan Woodhull