gds-api-adapters 5.3.0 → 5.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.
@@ -0,0 +1,42 @@
1
+ require_relative 'base'
2
+ require_relative 'exceptions'
3
+ require 'json'
4
+
5
+ class GdsApi::GovUkDelivery < GdsApi::Base
6
+ include GdsApi::ExceptionHandling
7
+
8
+ def initialize(endpoint_url, options={})
9
+ super(endpoint_url, options.merge({timeout: 10}))
10
+ end
11
+
12
+ def subscribe(email, feed_urls)
13
+ data = {email: email, feed_urls: feed_urls}
14
+ url = "#{base_url}/subscriptions"
15
+ post_url(url, data)
16
+ end
17
+
18
+ def topic(feed_url, title, description=nil)
19
+ data = {feed_url: feed_url, title: title, description: description}
20
+ url = "#{base_url}/lists"
21
+ post_url(url, data)
22
+ end
23
+
24
+ def notify(feed_urls, subject, body)
25
+ data = {feed_urls: feed_urls, subject: subject, body: body}
26
+ url = "#{base_url}/notifications"
27
+ post_url(url, data)
28
+ end
29
+
30
+ private
31
+ def base_url
32
+ endpoint
33
+ end
34
+
35
+ def post_url(url, data)
36
+ if ! @options[:noop]
37
+ post_json(url, data)
38
+ elsif @options[:noop] && @options[:stdout]
39
+ puts "Would POST #{data.to_json} to #{url}"
40
+ end
41
+ end
42
+ end
@@ -0,0 +1,14 @@
1
+ require 'json'
2
+
3
+ module GdsApi
4
+ module TestHelpers
5
+ module GovUkDelivery
6
+
7
+ GOVUK_DELIVERY_ENDPOINT = Plek.current.find('govuk-delivery')
8
+
9
+ def stub_gov_uk_delivery_post_request(method, params_hash)
10
+ stub_request(:post, "#{GOVUK_DELIVERY_ENDPOINT}/#{method}").with(body: params_hash.to_json)
11
+ end
12
+ end
13
+ end
14
+ end
@@ -1,3 +1,3 @@
1
1
  module GdsApi
2
- VERSION = '5.3.0'
2
+ VERSION = '5.4.0'
3
3
  end
@@ -494,10 +494,6 @@ describe GdsApi::ContentApi do
494
494
  end
495
495
  end
496
496
 
497
- it "should do the request in batches if the request path would otherwise exceed 2000 chars" do
498
-
499
- end
500
-
501
497
  describe "test helpers" do
502
498
  it "should have representative test helpers" do
503
499
  setup_content_api_business_support_schemes_stubs
@@ -0,0 +1,43 @@
1
+ require 'test_helper'
2
+ require 'gds_api/gov_uk_delivery'
3
+ require 'gds_api/test_helpers/gov_uk_delivery'
4
+
5
+ describe GdsApi::GovUkDelivery do
6
+
7
+ include GdsApi::TestHelpers::GovUkDelivery
8
+
9
+ before do
10
+ @base_api_url = Plek.current.find("govuk-delivery")
11
+ @api = GdsApi::GovUkDelivery.new(@base_api_url)
12
+ end
13
+
14
+ it "can create a topic" do
15
+ expected_payload = { feed_url: 'http://example.com/feed', title: 'Title', description: nil }
16
+ stub = stub_gov_uk_delivery_post_request('lists', expected_payload).to_return(created_response_hash)
17
+
18
+ assert @api.topic("http://example.com/feed", "Title")
19
+ assert_requested stub
20
+ end
21
+
22
+ it "can subscribe a new email" do
23
+ expected_payload = { email: 'me@example.com', feed_urls: ['http://example.com/feed'] }
24
+ stub = stub_gov_uk_delivery_post_request('subscriptions', expected_payload).to_return(created_response_hash)
25
+
26
+ assert @api.subscribe('me@example.com', ['http://example.com/feed'])
27
+ assert_requested stub
28
+ end
29
+
30
+ it "can post a notification" do
31
+ expected_payload = { feed_urls: ['http://example.com/feed'], subject: 'Test', body: '<p>Something</p>'}
32
+ stub = stub_gov_uk_delivery_post_request('notifications', expected_payload).to_return(created_response_hash)
33
+
34
+ assert @api.notify(['http://example.com/feed'], 'Test', '<p>Something</p>')
35
+ assert_requested stub
36
+ end
37
+
38
+ private
39
+
40
+ def created_response_hash
41
+ { body: '', status: 201 }
42
+ end
43
+ end
metadata CHANGED
@@ -2,7 +2,7 @@
2
2
  name: gds-api-adapters
3
3
  version: !ruby/object:Gem::Version
4
4
  prerelease:
5
- version: 5.3.0
5
+ version: 5.4.0
6
6
  platform: ruby
7
7
  authors:
8
8
  - James Stewart
@@ -10,7 +10,7 @@ autorequire:
10
10
  bindir: bin
11
11
  cert_chain: []
12
12
 
13
- date: 2013-02-27 00:00:00 Z
13
+ date: 2013-04-11 00:00:00 Z
14
14
  dependencies:
15
15
  - !ruby/object:Gem::Dependency
16
16
  name: plek
@@ -187,51 +187,54 @@ extensions: []
187
187
  extra_rdoc_files: []
188
188
 
189
189
  files:
190
+ - lib/gds_api/gov_uk_delivery.rb
190
191
  - lib/gds_api/version.rb
191
- - lib/gds_api/base.rb
192
- - lib/gds_api/licence_application.rb
192
+ - lib/gds_api/publisher.rb
193
193
  - lib/gds_api/panopticon/registerer.rb
194
- - lib/gds_api/needotron.rb
195
- - lib/gds_api/imminence.rb
196
- - lib/gds_api/rummager.rb
194
+ - lib/gds_api/asset_manager.rb
197
195
  - lib/gds_api/content_api.rb
198
- - lib/gds_api/mapit.rb
199
- - lib/gds_api/exceptions.rb
200
- - lib/gds_api/json_client.rb
201
- - lib/gds_api/core-ext/openstruct.rb
202
- - lib/gds_api/response.rb
203
- - lib/gds_api/content_api/list_response.rb
204
- - lib/gds_api/content_api/response.rb
205
- - lib/gds_api/publisher.rb
206
- - lib/gds_api/test_helpers/licence_application.rb
207
- - lib/gds_api/test_helpers/imminence.rb
196
+ - lib/gds_api/imminence.rb
197
+ - lib/gds_api/test_helpers/gov_uk_delivery.rb
198
+ - lib/gds_api/test_helpers/publisher.rb
199
+ - lib/gds_api/test_helpers/asset_manager.rb
208
200
  - lib/gds_api/test_helpers/content_api.rb
201
+ - lib/gds_api/test_helpers/imminence.rb
202
+ - lib/gds_api/test_helpers/licence_application.rb
209
203
  - lib/gds_api/test_helpers/mapit.rb
210
204
  - lib/gds_api/test_helpers/content_api/artefact_stub.rb
211
- - lib/gds_api/test_helpers/publisher.rb
212
- - lib/gds_api/test_helpers/asset_manager.rb
213
205
  - lib/gds_api/test_helpers/panopticon.rb
214
206
  - lib/gds_api/test_helpers/json_client_helper.rb
215
- - lib/gds_api/part_methods.rb
216
- - lib/gds_api/asset_manager.rb
207
+ - lib/gds_api/licence_application.rb
208
+ - lib/gds_api/base.rb
209
+ - lib/gds_api/mapit.rb
210
+ - lib/gds_api/json_client.rb
211
+ - lib/gds_api/response.rb
212
+ - lib/gds_api/content_api/list_response.rb
213
+ - lib/gds_api/content_api/response.rb
214
+ - lib/gds_api/rummager.rb
217
215
  - lib/gds_api/panopticon.rb
216
+ - lib/gds_api/core-ext/openstruct.rb
217
+ - lib/gds_api/part_methods.rb
218
+ - lib/gds_api/needotron.rb
219
+ - lib/gds_api/exceptions.rb
218
220
  - lib/gds_api/helpers.rb
219
221
  - README.md
220
222
  - Rakefile
221
- - test/rummager_test.rb
223
+ - test/panopticon_api_test.rb
222
224
  - test/publisher_api_test.rb
223
- - test/content_api_response_test.rb
224
- - test/licence_application_api_test.rb
225
225
  - test/mapit_test.rb
226
- - test/panopticon_api_test.rb
226
+ - test/gov_uk_delivery_test.rb
227
+ - test/rummager_test.rb
227
228
  - test/imminence_api_test.rb
228
- - test/json_client_test.rb
229
- - test/test_helper.rb
230
- - test/fixtures/hello.txt
229
+ - test/panopticon_registerer_test.rb
230
+ - test/content_api_test.rb
231
231
  - test/asset_manager_test.rb
232
+ - test/content_api_response_test.rb
233
+ - test/json_client_test.rb
232
234
  - test/gds_api_base_test.rb
233
- - test/content_api_test.rb
234
- - test/panopticon_registerer_test.rb
235
+ - test/licence_application_api_test.rb
236
+ - test/fixtures/hello.txt
237
+ - test/test_helper.rb
235
238
  homepage: http://github.com/alphagov/gds-api-adapters
236
239
  licenses: []
237
240
 
@@ -245,7 +248,7 @@ required_ruby_version: !ruby/object:Gem::Requirement
245
248
  requirements:
246
249
  - - ">="
247
250
  - !ruby/object:Gem::Version
248
- hash: -3192296895891701275
251
+ hash: -1093811920964553750
249
252
  segments:
250
253
  - 0
251
254
  version: "0"
@@ -254,7 +257,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
254
257
  requirements:
255
258
  - - ">="
256
259
  - !ruby/object:Gem::Version
257
- hash: -3192296895891701275
260
+ hash: -1093811920964553750
258
261
  segments:
259
262
  - 0
260
263
  version: "0"
@@ -266,17 +269,18 @@ signing_key:
266
269
  specification_version: 3
267
270
  summary: Adapters to work with GDS APIs
268
271
  test_files:
269
- - test/rummager_test.rb
272
+ - test/panopticon_api_test.rb
270
273
  - test/publisher_api_test.rb
271
- - test/content_api_response_test.rb
272
- - test/licence_application_api_test.rb
273
274
  - test/mapit_test.rb
274
- - test/panopticon_api_test.rb
275
+ - test/gov_uk_delivery_test.rb
276
+ - test/rummager_test.rb
275
277
  - test/imminence_api_test.rb
276
- - test/json_client_test.rb
277
- - test/test_helper.rb
278
- - test/fixtures/hello.txt
278
+ - test/panopticon_registerer_test.rb
279
+ - test/content_api_test.rb
279
280
  - test/asset_manager_test.rb
281
+ - test/content_api_response_test.rb
282
+ - test/json_client_test.rb
280
283
  - test/gds_api_base_test.rb
281
- - test/content_api_test.rb
282
- - test/panopticon_registerer_test.rb
284
+ - test/licence_application_api_test.rb
285
+ - test/fixtures/hello.txt
286
+ - test/test_helper.rb