gds-api-adapters 78.1.0 → 79.1.1
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/lib/gds_api/email_alert_api.rb +12 -0
- data/lib/gds_api/locations_api.rb +28 -0
- data/lib/gds_api/test_helpers/email_alert_api.rb +39 -2
- data/lib/gds_api/test_helpers/locations_api.rb +38 -0
- data/lib/gds_api/version.rb +1 -1
- data/lib/gds_api.rb +8 -0
- metadata +4 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 56aec1e3622b0974b51878653be4dfc833cc7e4bb8668c788e19ba38666dbffe
|
4
|
+
data.tar.gz: defee880c91c2c1ed568c5320a051ad938f6e1bb5a0d9a9e2f9ac705bc3c616a
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 2aa101d336e0151c5517bb15e7126489fd44cfbd9da7683f34a74865bf5f62ba051075feb990c22ed3cd34022ac5d5e120bb9924d3f116fc32ab1498bbda6db2
|
7
|
+
data.tar.gz: 5d50b8fb50c41d00b1e99a500dffb3969a43d33d6df7bf7d6693a383ca1226e35b91b5d5072880a9b57cd41727225233d520110876efabbcd8f119ebf83e67df
|
@@ -38,6 +38,7 @@ class GdsApi::EmailAlertApi < GdsApi::Base
|
|
38
38
|
#
|
39
39
|
# @param message [Hash] Valid message attributes
|
40
40
|
def create_message(message, headers = {})
|
41
|
+
warn "#create_message is deprecated and will be removed in a future version."
|
41
42
|
post_json("#{endpoint}/messages", message, headers)
|
42
43
|
end
|
43
44
|
|
@@ -267,6 +268,17 @@ class GdsApi::EmailAlertApi < GdsApi::Base
|
|
267
268
|
)
|
268
269
|
end
|
269
270
|
|
271
|
+
# Update subscriber list details, such as title
|
272
|
+
# @param [Hash] params A hash of detail paramaters that can be updated. For example title.
|
273
|
+
# For allowed parameters see:
|
274
|
+
# https://github.com/alphagov/email-alert-api/blob/main/docs/api.md#patch-subscriber-listsxxx
|
275
|
+
def update_subscriber_list_details(slug:, params: {})
|
276
|
+
patch_json(
|
277
|
+
"#{endpoint}/subscriber-lists/#{slug}",
|
278
|
+
params,
|
279
|
+
)
|
280
|
+
end
|
281
|
+
|
270
282
|
private
|
271
283
|
|
272
284
|
def nested_query_string(params)
|
@@ -0,0 +1,28 @@
|
|
1
|
+
require_relative "base"
|
2
|
+
require_relative "exceptions"
|
3
|
+
|
4
|
+
class GdsApi::LocationsApi < GdsApi::Base
|
5
|
+
# Get a list of local custodian codes for a postcode
|
6
|
+
#
|
7
|
+
# @param [String, nil] postcode The postcode for which the custodian codes are requested
|
8
|
+
#
|
9
|
+
# @return [Array] All local custodian codes for a specific postcode
|
10
|
+
def local_custodian_code_for_postcode(postcode)
|
11
|
+
response = get_json("#{endpoint}/locations?postcode=#{postcode}.json")
|
12
|
+
|
13
|
+
return [] if response["results"].nil?
|
14
|
+
|
15
|
+
response["results"].map { |r| r["local_custodian_code"] }.uniq
|
16
|
+
end
|
17
|
+
|
18
|
+
# Get the average coordinates for a postcode
|
19
|
+
#
|
20
|
+
# @param [String, nil] postcode The postcode for which the coordinates are requested
|
21
|
+
#
|
22
|
+
# @return [Hash] The average coordinates (two fields, "latitude" and "longitude") for a specific postcode
|
23
|
+
def coordinates_for_postcode(postcode)
|
24
|
+
response = get_json("#{endpoint}/locations?postcode=#{postcode}.json")
|
25
|
+
|
26
|
+
{ "latitude" => response["average_latitude"], "longitude" => response["average_longitude"] } unless response["results"].nil?
|
27
|
+
end
|
28
|
+
end
|
@@ -440,6 +440,11 @@ module GdsApi
|
|
440
440
|
).to_return(status: 404)
|
441
441
|
end
|
442
442
|
|
443
|
+
def stub_email_alert_api_bulk_unsubscribe_conflict(slug:)
|
444
|
+
stub_request(:post, "#{EMAIL_ALERT_API_ENDPOINT}/subscriber-lists/#{slug}/bulk-unsubscribe")
|
445
|
+
.to_return(status: 409)
|
446
|
+
end
|
447
|
+
|
443
448
|
def stub_email_alert_api_bulk_unsubscribe_conflict_with_message(slug:, govuk_request_id:, body:, sender_message_id:)
|
444
449
|
stub_request(:post, "#{EMAIL_ALERT_API_ENDPOINT}/subscriber-lists/#{slug}/bulk-unsubscribe")
|
445
450
|
.with(
|
@@ -451,13 +456,43 @@ module GdsApi
|
|
451
456
|
).to_return(status: 409)
|
452
457
|
end
|
453
458
|
|
454
|
-
def stub_email_alert_api_bulk_unsubscribe_bad_request(slug
|
459
|
+
def stub_email_alert_api_bulk_unsubscribe_bad_request(slug:)
|
460
|
+
stub_request(:post, "#{EMAIL_ALERT_API_ENDPOINT}/subscriber-lists/#{slug}/bulk-unsubscribe")
|
461
|
+
.to_return(status: 422)
|
462
|
+
end
|
463
|
+
|
464
|
+
def stub_email_alert_api_bulk_unsubscribe_bad_request_with_message(slug:, govuk_request_id:, body:, sender_message_id:)
|
455
465
|
stub_request(:post, "#{EMAIL_ALERT_API_ENDPOINT}/subscriber-lists/#{slug}/bulk-unsubscribe")
|
456
466
|
.with(
|
457
|
-
body: {
|
467
|
+
body: {
|
468
|
+
body: body,
|
469
|
+
sender_message_id: sender_message_id,
|
470
|
+
}.to_json,
|
471
|
+
headers: { "Govuk-Request-Id" => govuk_request_id },
|
458
472
|
).to_return(status: 422)
|
459
473
|
end
|
460
474
|
|
475
|
+
def stub_update_subscriber_list_details(slug:, params:)
|
476
|
+
stub_request(:patch, "#{EMAIL_ALERT_API_ENDPOINT}/subscriber-lists/#{slug}")
|
477
|
+
.with(body: params.to_json)
|
478
|
+
.to_return(
|
479
|
+
status: 200,
|
480
|
+
body: get_subscriber_list_response(params).to_json,
|
481
|
+
)
|
482
|
+
end
|
483
|
+
|
484
|
+
def stub_update_subscriber_list_details_not_found(slug:, params:)
|
485
|
+
stub_request(:patch, "#{EMAIL_ALERT_API_ENDPOINT}/subscriber-lists/#{slug}")
|
486
|
+
.with(body: params.to_json)
|
487
|
+
.to_return(status: 404)
|
488
|
+
end
|
489
|
+
|
490
|
+
def stub_update_subscriber_list_details_unprocessible_entity(slug:, params: {})
|
491
|
+
stub_request(:patch, "#{EMAIL_ALERT_API_ENDPOINT}/subscriber-lists/#{slug}")
|
492
|
+
.with(body: params.to_json)
|
493
|
+
.to_return(status: 422)
|
494
|
+
end
|
495
|
+
|
461
496
|
private
|
462
497
|
|
463
498
|
def get_subscriber_response(id, address, govuk_account_id)
|
@@ -537,6 +572,7 @@ module GdsApi
|
|
537
572
|
if attributes
|
538
573
|
tags = attributes["tags"]
|
539
574
|
links = attributes["links"]
|
575
|
+
content_id = attributes["content_id"]
|
540
576
|
document_type = attributes["document_type"]
|
541
577
|
email_document_supertype = attributes["email_document_supertype"]
|
542
578
|
government_document_supertype = attributes["government_document_supertype"]
|
@@ -546,6 +582,7 @@ module GdsApi
|
|
546
582
|
params = {}
|
547
583
|
params[:tags] = tags if tags
|
548
584
|
params[:links] = links if links
|
585
|
+
params[:content_id] = content_id if content_id
|
549
586
|
params[:document_type] = document_type if document_type
|
550
587
|
params[:email_document_supertype] = email_document_supertype if email_document_supertype
|
551
588
|
params[:government_document_supertype] = government_document_supertype if government_document_supertype
|
@@ -0,0 +1,38 @@
|
|
1
|
+
module GdsApi
|
2
|
+
module TestHelpers
|
3
|
+
module LocationsApi
|
4
|
+
LOCATIONS_API_ENDPOINT = Plek.current.find("locations-api")
|
5
|
+
|
6
|
+
def stub_locations_api_has_location(postcode, locations)
|
7
|
+
results = []
|
8
|
+
locations.each do |l|
|
9
|
+
results << {
|
10
|
+
"latitude" => l["latitude"],
|
11
|
+
"longitude" => l["longitude"],
|
12
|
+
"postcode" => postcode,
|
13
|
+
"local_custodian_code" => l["local_custodian_code"],
|
14
|
+
}
|
15
|
+
end
|
16
|
+
|
17
|
+
response = {
|
18
|
+
"average_latitude" => results.sum { |r| r["latitude"] } / results.size.to_f,
|
19
|
+
"average_longitude" => results.sum { |r| r["longitude"] } / results.size.to_f,
|
20
|
+
"results" => results,
|
21
|
+
}
|
22
|
+
|
23
|
+
stub_request(:get, "#{LOCATIONS_API_ENDPOINT}/locations?postcode=#{postcode}.json")
|
24
|
+
.to_return(body: response.to_json, status: 200)
|
25
|
+
end
|
26
|
+
|
27
|
+
def stub_locations_api_has_no_location(postcode)
|
28
|
+
stub_request(:get, "#{LOCATIONS_API_ENDPOINT}/locations?postcode=#{postcode}.json")
|
29
|
+
.to_return(body: { "results" => nil }.to_json, status: 200)
|
30
|
+
end
|
31
|
+
|
32
|
+
def stub_locations_api_does_not_have_a_bad_postcode(postcode)
|
33
|
+
stub_request(:get, "#{LOCATIONS_API_ENDPOINT}/locations?postcode=#{postcode}.json")
|
34
|
+
.to_return(body: { "code" => 400, "error" => "Postcode '#{postcode}' is not valid." }.to_json, status: 400)
|
35
|
+
end
|
36
|
+
end
|
37
|
+
end
|
38
|
+
end
|
data/lib/gds_api/version.rb
CHANGED
data/lib/gds_api.rb
CHANGED
@@ -10,6 +10,7 @@ require "gds_api/imminence"
|
|
10
10
|
require "gds_api/licence_application"
|
11
11
|
require "gds_api/link_checker_api"
|
12
12
|
require "gds_api/local_links_manager"
|
13
|
+
require "gds_api/locations_api"
|
13
14
|
require "gds_api/mapit"
|
14
15
|
require "gds_api/maslow"
|
15
16
|
require "gds_api/organisations"
|
@@ -201,4 +202,11 @@ module GdsApi
|
|
201
202
|
def self.worldwide(options = {})
|
202
203
|
GdsApi::Worldwide.new(Plek.new.website_root, options)
|
203
204
|
end
|
205
|
+
|
206
|
+
# Creates a GdsApi::LocationsApi adapter
|
207
|
+
#
|
208
|
+
# @return [GdsApi::LocationsApi]
|
209
|
+
def self.locations_api(options = {})
|
210
|
+
GdsApi::LocationsApi.new(Plek.find("locations-api"), options)
|
211
|
+
end
|
204
212
|
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:
|
4
|
+
version: 79.1.1
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- GOV.UK Dev
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2022-
|
11
|
+
date: 2022-03-29 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: addressable
|
@@ -385,6 +385,7 @@ files:
|
|
385
385
|
- lib/gds_api/link_checker_api.rb
|
386
386
|
- lib/gds_api/list_response.rb
|
387
387
|
- lib/gds_api/local_links_manager.rb
|
388
|
+
- lib/gds_api/locations_api.rb
|
388
389
|
- lib/gds_api/mapit.rb
|
389
390
|
- lib/gds_api/maslow.rb
|
390
391
|
- lib/gds_api/middleware/govuk_header_sniffer.rb
|
@@ -409,6 +410,7 @@ files:
|
|
409
410
|
- lib/gds_api/test_helpers/licence_application.rb
|
410
411
|
- lib/gds_api/test_helpers/link_checker_api.rb
|
411
412
|
- lib/gds_api/test_helpers/local_links_manager.rb
|
413
|
+
- lib/gds_api/test_helpers/locations_api.rb
|
412
414
|
- lib/gds_api/test_helpers/mapit.rb
|
413
415
|
- lib/gds_api/test_helpers/organisations.rb
|
414
416
|
- lib/gds_api/test_helpers/publishing_api.rb
|