gds-api-adapters 29.3.1 → 29.4.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 +4 -4
- data/lib/gds_api/email_alert_api.rb +18 -3
- data/lib/gds_api/test_helpers/email_alert_api.rb +16 -13
- data/lib/gds_api/version.rb +1 -1
- data/test/email_alert_api_test.rb +61 -0
- metadata +2 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: b562297ce51a222600b08f5f03e0bd8760a7b38a
|
4
|
+
data.tar.gz: 454376b9f09ffae61d33051e3cd0945c72eda27e
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 8071ee9a6fb45ea027ee5450a76f6682d6d2a04734f59a21b480c1f2f2b15ff8482dd0de9f0ebba6a4ab23398fa210ddda07d70315e61d4e07a24801ba85835f
|
7
|
+
data.tar.gz: 4ba2242191eb8cbc922f8a157dc322dcf32931e8ea7f165ccd6594a991738425d2668a00e1bb1b5348743e8e136c3c961c517b9c03c9b990ae517abab7a4eec4
|
@@ -4,7 +4,21 @@ require_relative 'exceptions'
|
|
4
4
|
class GdsApi::EmailAlertApi < GdsApi::Base
|
5
5
|
|
6
6
|
def find_or_create_subscriber_list(attributes)
|
7
|
-
|
7
|
+
tags = attributes["tags"]
|
8
|
+
links = attributes["links"]
|
9
|
+
document_type = attributes["document_type"]
|
10
|
+
|
11
|
+
if tags && links
|
12
|
+
message = "please provide either tags or links (or neither), but not both"
|
13
|
+
raise ArgumentError, message
|
14
|
+
end
|
15
|
+
|
16
|
+
params = {}
|
17
|
+
params[:tags] = tags if tags
|
18
|
+
params[:links] = links if links
|
19
|
+
params[:document_type] = document_type if document_type
|
20
|
+
|
21
|
+
search_subscriber_list(params)
|
8
22
|
rescue GdsApi::HTTPNotFound
|
9
23
|
create_subscriber_list(attributes)
|
10
24
|
end
|
@@ -15,8 +29,9 @@ class GdsApi::EmailAlertApi < GdsApi::Base
|
|
15
29
|
|
16
30
|
private
|
17
31
|
|
18
|
-
def
|
19
|
-
|
32
|
+
def search_subscriber_list(params)
|
33
|
+
query_string = nested_query_string(params)
|
34
|
+
get_json!("#{endpoint}/subscriber-lists?" + query_string)
|
20
35
|
end
|
21
36
|
|
22
37
|
def create_subscriber_list(attributes)
|
@@ -7,12 +7,7 @@ module GdsApi
|
|
7
7
|
EMAIL_ALERT_API_ENDPOINT = Plek.find("email-alert-api")
|
8
8
|
|
9
9
|
def email_alert_api_has_subscriber_list(attributes)
|
10
|
-
|
11
|
-
tags = attributes.fetch("tags")
|
12
|
-
|
13
|
-
query = Rack::Utils.build_nested_query(tags: tags)
|
14
|
-
|
15
|
-
stub_request(:get, subscriber_lists_url(query))
|
10
|
+
stub_request(:get, subscriber_lists_url(attributes))
|
16
11
|
.to_return(
|
17
12
|
:status => 200,
|
18
13
|
:body => get_subscriber_list_response(attributes).to_json,
|
@@ -20,9 +15,7 @@ module GdsApi
|
|
20
15
|
end
|
21
16
|
|
22
17
|
def email_alert_api_does_not_have_subscriber_list(attributes)
|
23
|
-
|
24
|
-
|
25
|
-
stub_request(:get, subscriber_lists_url(query))
|
18
|
+
stub_request(:get, subscriber_lists_url(attributes))
|
26
19
|
.to_return(status: 404)
|
27
20
|
end
|
28
21
|
|
@@ -48,9 +41,6 @@ module GdsApi
|
|
48
41
|
"subscription_url" => "https://stage-public.govdelivery.com/accounts/UKGOVUK/subscriber/new?topic_id=UKGOVUK_1234",
|
49
42
|
"gov_delivery_id" => "UKGOVUK_1234",
|
50
43
|
"title" => "Some title",
|
51
|
-
"tags" => {
|
52
|
-
"format" => ["some-format"],
|
53
|
-
}
|
54
44
|
}.merge(attributes)
|
55
45
|
}
|
56
46
|
end
|
@@ -86,7 +76,20 @@ module GdsApi
|
|
86
76
|
|
87
77
|
private
|
88
78
|
|
89
|
-
def subscriber_lists_url(
|
79
|
+
def subscriber_lists_url(attributes = nil)
|
80
|
+
if attributes
|
81
|
+
tags = attributes["tags"]
|
82
|
+
links = attributes["links"]
|
83
|
+
document_type = attributes["document_type"]
|
84
|
+
|
85
|
+
params = {}
|
86
|
+
params[:tags] = tags if tags
|
87
|
+
params[:links] = links if links
|
88
|
+
params[:document_type] = document_type if document_type
|
89
|
+
|
90
|
+
query = Rack::Utils.build_nested_query(params)
|
91
|
+
end
|
92
|
+
|
90
93
|
url = EMAIL_ALERT_API_ENDPOINT + "/subscriber-lists"
|
91
94
|
query ? "#{url}?#{query}" : url
|
92
95
|
end
|
data/lib/gds_api/version.rb
CHANGED
@@ -96,6 +96,67 @@ describe GdsApi::EmailAlertApi do
|
|
96
96
|
)
|
97
97
|
end
|
98
98
|
end
|
99
|
+
|
100
|
+
describe "when the optional 'document_type' is provided" do
|
101
|
+
let(:params) {
|
102
|
+
{
|
103
|
+
"title" => title,
|
104
|
+
"tags" => tags,
|
105
|
+
"document_type" => "travel_advice",
|
106
|
+
}
|
107
|
+
}
|
108
|
+
|
109
|
+
before do
|
110
|
+
email_alert_api_has_subscriber_list(
|
111
|
+
"title" => "Some Title",
|
112
|
+
"tags" => tags,
|
113
|
+
"document_type" => "travel_advice",
|
114
|
+
"subscription_url" => expected_subscription_url,
|
115
|
+
)
|
116
|
+
end
|
117
|
+
|
118
|
+
it "returns the subscriber list attributes" do
|
119
|
+
subscriber_list_attrs = api_client.find_or_create_subscriber_list(params)
|
120
|
+
.to_hash
|
121
|
+
.fetch("subscriber_list")
|
122
|
+
|
123
|
+
assert_equal(
|
124
|
+
"travel_advice",
|
125
|
+
subscriber_list_attrs.fetch("document_type")
|
126
|
+
)
|
127
|
+
end
|
128
|
+
end
|
129
|
+
|
130
|
+
describe "when both tags and links are provided" do
|
131
|
+
let(:links) {
|
132
|
+
{
|
133
|
+
"format" => ["some-document-format"]
|
134
|
+
}
|
135
|
+
}
|
136
|
+
|
137
|
+
let(:params) {
|
138
|
+
{
|
139
|
+
"title" => title,
|
140
|
+
"tags" => tags,
|
141
|
+
"links" => links,
|
142
|
+
}
|
143
|
+
}
|
144
|
+
|
145
|
+
before do
|
146
|
+
email_alert_api_has_subscriber_list(
|
147
|
+
"title" => "Some Title",
|
148
|
+
"tags" => tags,
|
149
|
+
"links" => links,
|
150
|
+
"subscription_url" => expected_subscription_url,
|
151
|
+
)
|
152
|
+
end
|
153
|
+
|
154
|
+
it "excludes that attribute from the query string" do
|
155
|
+
assert_raises do
|
156
|
+
api_client.find_or_create_subscriber_list(params)
|
157
|
+
end
|
158
|
+
end
|
159
|
+
end
|
99
160
|
end
|
100
161
|
end
|
101
162
|
end
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: gds-api-adapters
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 29.
|
4
|
+
version: 29.4.0
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- James Stewart
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2016-03-
|
11
|
+
date: 2016-03-08 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: plek
|