gds-api-adapters 30.2.1 → 30.3.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/README.md +3 -3
- data/lib/gds_api/email_alert_api.rb +29 -0
- data/lib/gds_api/test_helpers/email_alert_api.rb +21 -0
- data/lib/gds_api/version.rb +1 -1
- data/test/email_alert_api_test.rb +29 -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: 1ea4fb424e88b660a8ecb6ea9a088abf135983aa
|
4
|
+
data.tar.gz: ff6e5fd6357f9078dbc63762f498e3c47fc4d0d8
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 396bb7e3cddb5f262656439e1ef8c52795fa8b76f54e2339875e9d7d9ecd3e81843af9fdd8b1e050e9ca7293e22ee60b7af0078b7787235005f32fd972965ced
|
7
|
+
data.tar.gz: 173c4784e54d85ffdb1b6411572283a4082a5344cf0bb5b5ea87c6dabf500eef4b19963f6d26dc80109463bc9610d889eef7e5e757062de761f4c5f9810a2330
|
data/README.md
CHANGED
@@ -12,9 +12,9 @@ results = rummager.unified_search(q: "taxes")
|
|
12
12
|
|
13
13
|
Example adapters for frequently used applications:
|
14
14
|
|
15
|
-
- [Publishing API](lib/gds_api/publishing_api_v2.rb) ([docs](http://www.rubydoc.info/
|
16
|
-
- [Content Store](lib/gds_api/content_store.rb) ([docs](http://www.rubydoc.info/
|
17
|
-
- [Rummager](lib/gds_api/publishing_api_v2.rb) ([docs](http://www.rubydoc.info/
|
15
|
+
- [Publishing API](lib/gds_api/publishing_api_v2.rb) ([docs](http://www.rubydoc.info/github/alphagov/gds-api-adapters/master/GdsApi/PublishingApiV2), [test helper code](https://github.com/alphagov/gds-api-adapters/blob/master/lib/gds_api/test_helpers/publishing_api_v2.rb), [test helper docs](http://www.rubydoc.info/github/alphagov/gds-api-adapters/master/GdsApi/TestHelpers/PublishingApiV2))
|
16
|
+
- [Content Store](lib/gds_api/content_store.rb) ([docs](http://www.rubydoc.info/github/alphagov/gds-api-adapters/master/GdsApi/ContentStore), [test helper code](https://github.com/alphagov/gds-api-adapters/blob/master/lib/gds_api/test_helpers/content_store.rb), [test helper docs](http://www.rubydoc.info/github/alphagov/gds-api-adapters/master/GdsApi/TestHelpers/ContentStore))
|
17
|
+
- [Rummager](lib/gds_api/publishing_api_v2.rb) ([docs](http://www.rubydoc.info/github/alphagov/gds-api-adapters/master/GdsApi/Rummager), [test helper code](https://github.com/alphagov/gds-api-adapters/blob/master/lib/gds_api/test_helpers/rummager.rb), [test helper docs](http://www.rubydoc.info/github/alphagov/gds-api-adapters/master/GdsApi/TestHelpers/Rummager))
|
18
18
|
|
19
19
|
## Logging
|
20
20
|
|
@@ -1,8 +1,14 @@
|
|
1
1
|
require_relative 'base'
|
2
2
|
require_relative 'exceptions'
|
3
3
|
|
4
|
+
# Adapter for the Email Alert API
|
5
|
+
#
|
6
|
+
# @see https://github.com/alphagov/email-alert-api
|
4
7
|
class GdsApi::EmailAlertApi < GdsApi::Base
|
5
8
|
|
9
|
+
# Get or Post subscriber list
|
10
|
+
#
|
11
|
+
# @param attributes [Hash] document_type, links, tags used to search existing subscriber lists
|
6
12
|
def find_or_create_subscriber_list(attributes)
|
7
13
|
tags = attributes["tags"]
|
8
14
|
links = attributes["links"]
|
@@ -23,10 +29,33 @@ class GdsApi::EmailAlertApi < GdsApi::Base
|
|
23
29
|
create_subscriber_list(attributes)
|
24
30
|
end
|
25
31
|
|
32
|
+
# Post notification
|
33
|
+
#
|
34
|
+
# @param publication [Hash] Valid publication attributes
|
26
35
|
def send_alert(publication)
|
27
36
|
post_json!("#{endpoint}/notifications", publication)
|
28
37
|
end
|
29
38
|
|
39
|
+
# Get notifications
|
40
|
+
#
|
41
|
+
# @option start_at [String] Optional GovDelivery bulletin id to page back through notifications
|
42
|
+
#
|
43
|
+
# @return [Hash] notifications
|
44
|
+
def notifications(start_at=nil)
|
45
|
+
url = "#{endpoint}/notifications"
|
46
|
+
url += "?start_at=#{start_at}" if start_at
|
47
|
+
get_json!(url)
|
48
|
+
end
|
49
|
+
|
50
|
+
# Get notification
|
51
|
+
#
|
52
|
+
# @param id [String] GovDelivery bulletin id
|
53
|
+
#
|
54
|
+
# @return [Hash] notification
|
55
|
+
def notification(id)
|
56
|
+
get_json!("#{endpoint}/notifications/#{id}")
|
57
|
+
end
|
58
|
+
|
30
59
|
private
|
31
60
|
|
32
61
|
def search_subscriber_list(params)
|
@@ -74,6 +74,27 @@ module GdsApi
|
|
74
74
|
assert_requested(:post, notifications_url, times: 1, &matcher)
|
75
75
|
end
|
76
76
|
|
77
|
+
def email_alert_api_has_notifications(notifications, start_at=nil)
|
78
|
+
url = notifications_url
|
79
|
+
url += "?start_at=#{start_at}" if start_at
|
80
|
+
url_regexp = Regexp.new("^#{Regexp.escape(url)}$")
|
81
|
+
|
82
|
+
stub_request(:get, url_regexp)
|
83
|
+
.to_return(
|
84
|
+
status: 200,
|
85
|
+
body: notifications.to_json
|
86
|
+
)
|
87
|
+
end
|
88
|
+
|
89
|
+
def email_alert_api_has_notification(notification)
|
90
|
+
url = "#{notifications_url}/#{notification['web_service_bulletin']['to_param']}"
|
91
|
+
|
92
|
+
stub_request(:get, url).to_return(
|
93
|
+
status: 200,
|
94
|
+
body: notification.to_json
|
95
|
+
)
|
96
|
+
end
|
97
|
+
|
77
98
|
private
|
78
99
|
|
79
100
|
def subscriber_lists_url(attributes = nil)
|
data/lib/gds_api/version.rb
CHANGED
@@ -159,4 +159,33 @@ describe GdsApi::EmailAlertApi do
|
|
159
159
|
end
|
160
160
|
end
|
161
161
|
end
|
162
|
+
describe "notifications" do
|
163
|
+
it "retrieves notifications" do
|
164
|
+
stubbed_request = email_alert_api_has_notifications([
|
165
|
+
{"subject" => "Foo"}, {"subject" => "Bar"}
|
166
|
+
])
|
167
|
+
api_client.notifications
|
168
|
+
assert_requested(stubbed_request)
|
169
|
+
end
|
170
|
+
|
171
|
+
it "uses the start_at param if present" do
|
172
|
+
stubbed_request = email_alert_api_has_notifications([
|
173
|
+
{"subject" => "Foo"}, {"subject" => "Bar"}
|
174
|
+
], "101AA")
|
175
|
+
api_client.notifications("101AA")
|
176
|
+
assert_requested(stubbed_request)
|
177
|
+
end
|
178
|
+
end
|
179
|
+
|
180
|
+
describe "notification" do
|
181
|
+
before do
|
182
|
+
@stubbed_request = email_alert_api_has_notification({
|
183
|
+
"web_service_bulletin" => { "to_param" => "10001001" }
|
184
|
+
})
|
185
|
+
end
|
186
|
+
it "retrieves a notification by id" do
|
187
|
+
api_client.notification("10001001")
|
188
|
+
assert_requested(@stubbed_request)
|
189
|
+
end
|
190
|
+
end
|
162
191
|
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: 30.
|
4
|
+
version: 30.3.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-
|
11
|
+
date: 2016-05-06 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: plek
|