gds-api-adapters 29.3.1 → 29.4.0

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
  SHA1:
3
- metadata.gz: 47a5ea938b00f84981bf99e6cd2f0e3d6fb94b3f
4
- data.tar.gz: a35284df3295fd23b5fc59771649acebf7f64cd7
3
+ metadata.gz: b562297ce51a222600b08f5f03e0bd8760a7b38a
4
+ data.tar.gz: 454376b9f09ffae61d33051e3cd0945c72eda27e
5
5
  SHA512:
6
- metadata.gz: ac5a10f123ecbf570a1ec183968d5e5d76faeb2bdc2423eace86dfea7ef56250fbe8f964b0295fd26d6c3fe281b183230a6b114e44e45ce98e27a15d22384426
7
- data.tar.gz: 2f25ce61b3eead78a1579882485efbc9bdfbda4cf3a227c835c42500fabdcf9024d3e15b6aabb8c63393d2af14f9b0a4efaa8d37fe6427ad1f2fe774bd600537
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
- search_subscriber_list_by_tags(attributes.fetch("tags"))
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 search_subscriber_list_by_tags(tags)
19
- get_json!("#{endpoint}/subscriber-lists?" + nested_query_string(tags: tags))
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
- title = attributes.fetch("title")
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
- query = Rack::Utils.build_nested_query(tags: attributes.fetch("tags"))
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(query = nil)
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
@@ -1,3 +1,3 @@
1
1
  module GdsApi
2
- VERSION = '29.3.1'
2
+ VERSION = '29.4.0'
3
3
  end
@@ -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.3.1
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-04 00:00:00.000000000 Z
11
+ date: 2016-03-08 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: plek