gds-api-adapters 60.1.0 → 61.0.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.
Files changed (53) hide show
  1. checksums.yaml +4 -4
  2. data/Rakefile +0 -6
  3. data/lib/gds-api-adapters.rb +3 -3
  4. data/lib/gds_api.rb +45 -45
  5. data/lib/gds_api/asset_manager.rb +2 -2
  6. data/lib/gds_api/base.rb +5 -5
  7. data/lib/gds_api/calendars.rb +1 -1
  8. data/lib/gds_api/content_store.rb +3 -3
  9. data/lib/gds_api/email_alert_api.rb +4 -4
  10. data/lib/gds_api/imminence.rb +2 -2
  11. data/lib/gds_api/json_client.rb +19 -19
  12. data/lib/gds_api/link_checker_api.rb +6 -6
  13. data/lib/gds_api/local_links_manager.rb +1 -1
  14. data/lib/gds_api/mapit.rb +6 -6
  15. data/lib/gds_api/middleware/govuk_header_sniffer.rb +1 -1
  16. data/lib/gds_api/organisations.rb +1 -1
  17. data/lib/gds_api/performance_platform/data_in.rb +1 -1
  18. data/lib/gds_api/performance_platform/data_out.rb +14 -14
  19. data/lib/gds_api/publishing_api.rb +2 -2
  20. data/lib/gds_api/publishing_api/special_route_publisher.rb +2 -2
  21. data/lib/gds_api/publishing_api_v2.rb +8 -8
  22. data/lib/gds_api/railtie.rb +6 -6
  23. data/lib/gds_api/response.rb +4 -4
  24. data/lib/gds_api/router.rb +3 -3
  25. data/lib/gds_api/rummager.rb +1 -1
  26. data/lib/gds_api/search.rb +10 -20
  27. data/lib/gds_api/support.rb +1 -1
  28. data/lib/gds_api/support_api.rb +1 -1
  29. data/lib/gds_api/test_helpers/asset_manager.rb +4 -4
  30. data/lib/gds_api/test_helpers/calendars.rb +13 -13
  31. data/lib/gds_api/test_helpers/common_responses.rb +3 -3
  32. data/lib/gds_api/test_helpers/content_item_helpers.rb +2 -2
  33. data/lib/gds_api/test_helpers/content_store.rb +7 -7
  34. data/lib/gds_api/test_helpers/email_alert_api.rb +19 -19
  35. data/lib/gds_api/test_helpers/imminence.rb +3 -3
  36. data/lib/gds_api/test_helpers/json_client_helper.rb +1 -1
  37. data/lib/gds_api/test_helpers/licence_application.rb +1 -1
  38. data/lib/gds_api/test_helpers/link_checker_api.rb +5 -5
  39. data/lib/gds_api/test_helpers/local_links_manager.rb +14 -14
  40. data/lib/gds_api/test_helpers/mapit.rb +17 -17
  41. data/lib/gds_api/test_helpers/organisations.rb +7 -7
  42. data/lib/gds_api/test_helpers/performance_platform/data_out.rb +13 -13
  43. data/lib/gds_api/test_helpers/publishing_api.rb +8 -8
  44. data/lib/gds_api/test_helpers/publishing_api_v2.rb +24 -24
  45. data/lib/gds_api/test_helpers/router.rb +12 -12
  46. data/lib/gds_api/test_helpers/rummager.rb +3 -3
  47. data/lib/gds_api/test_helpers/search.rb +18 -18
  48. data/lib/gds_api/test_helpers/support.rb +1 -1
  49. data/lib/gds_api/test_helpers/support_api.rb +8 -8
  50. data/lib/gds_api/test_helpers/worldwide.rb +6 -6
  51. data/lib/gds_api/version.rb +1 -1
  52. data/lib/gds_api/worldwide.rb +1 -1
  53. metadata +4 -4
@@ -1,4 +1,4 @@
1
- require_relative 'base'
1
+ require_relative "base"
2
2
 
3
3
  class GdsApi::LocalLinksManager < GdsApi::Base
4
4
  def local_link(authority_slug, lgsl, lgil)
@@ -1,5 +1,5 @@
1
- require_relative 'base'
2
- require_relative 'exceptions'
1
+ require_relative "base"
2
+ require_relative "exceptions"
3
3
 
4
4
  class GdsApi::Mapit < GdsApi::Base
5
5
  def location_for_postcode(postcode)
@@ -23,19 +23,19 @@ class GdsApi::Mapit < GdsApi::Base
23
23
  end
24
24
 
25
25
  def lat
26
- @response['wgs84_lat']
26
+ @response["wgs84_lat"]
27
27
  end
28
28
 
29
29
  def lon
30
- @response['wgs84_lon']
30
+ @response["wgs84_lon"]
31
31
  end
32
32
 
33
33
  def areas
34
- @response['areas'].map { |_i, area| OpenStruct.new(area) }
34
+ @response["areas"].map { |_i, area| OpenStruct.new(area) }
35
35
  end
36
36
 
37
37
  def postcode
38
- @response['postcode']
38
+ @response["postcode"]
39
39
  end
40
40
  end
41
41
 
@@ -1,4 +1,4 @@
1
- require_relative '../govuk_headers'
1
+ require_relative "../govuk_headers"
2
2
 
3
3
  module GdsApi
4
4
  class GovukHeaderSniffer
@@ -1,4 +1,4 @@
1
- require_relative 'base'
1
+ require_relative "base"
2
2
 
3
3
  class GdsApi::Organisations < GdsApi::Base
4
4
  def organisations
@@ -1,4 +1,4 @@
1
- require_relative '../base'
1
+ require_relative "../base"
2
2
 
3
3
  module GdsApi
4
4
  class PerformancePlatformDatasetNotConfigured < BaseError; end
@@ -1,4 +1,4 @@
1
- require_relative '../base'
1
+ require_relative "../base"
2
2
 
3
3
  module GdsApi
4
4
  module PerformancePlatform
@@ -71,9 +71,9 @@ module GdsApi
71
71
  def search_terms(slug)
72
72
  options = {
73
73
  slug: slug,
74
- transaction: 'search-terms',
75
- group_by: 'searchKeyword',
76
- collect: 'searchUniques:sum'
74
+ transaction: "search-terms",
75
+ group_by: "searchKeyword",
76
+ collect: "searchUniques:sum",
77
77
  }
78
78
  statistics(options)
79
79
  end
@@ -81,9 +81,9 @@ module GdsApi
81
81
  def searches(slug, is_multipart)
82
82
  options = {
83
83
  slug: slug,
84
- transaction: 'search-terms',
85
- group_by: 'pagePath',
86
- collect: 'searchUniques:sum'
84
+ transaction: "search-terms",
85
+ group_by: "pagePath",
86
+ collect: "searchUniques:sum",
87
87
  }
88
88
  statistics(options, is_multipart)
89
89
  end
@@ -91,9 +91,9 @@ module GdsApi
91
91
  def page_views(slug, is_multipart)
92
92
  options = {
93
93
  slug: slug,
94
- transaction: 'page-statistics',
95
- group_by: 'pagePath',
96
- collect: 'uniquePageviews:sum'
94
+ transaction: "page-statistics",
95
+ group_by: "pagePath",
96
+ collect: "uniquePageviews:sum",
97
97
  }
98
98
  statistics(options, is_multipart)
99
99
  end
@@ -101,9 +101,9 @@ module GdsApi
101
101
  def problem_reports(slug, is_multipart)
102
102
  options = {
103
103
  slug: slug,
104
- transaction: 'page-contacts',
105
- group_by: 'pagePath',
106
- collect: 'total:sum'
104
+ transaction: "page-contacts",
105
+ group_by: "pagePath",
106
+ collect: "total:sum",
107
107
  }
108
108
  statistics(options, is_multipart)
109
109
  end
@@ -118,7 +118,7 @@ module GdsApi
118
118
  collect: options[:collect],
119
119
  duration: 42,
120
120
  period: "day",
121
- end_at: Date.today.to_time.getutc.iso8601
121
+ end_at: Date.today.to_time.getutc.iso8601,
122
122
  }
123
123
 
124
124
  filter_param = is_multipart ? :filter_by_prefix : :filter_by
@@ -1,5 +1,5 @@
1
- require_relative 'base'
2
- require_relative 'exceptions'
1
+ require_relative "base"
2
+ require_relative "exceptions"
3
3
 
4
4
  class GdsApi::PublishingApi < GdsApi::Base
5
5
  # Create a publishing intent for a base_path.
@@ -25,12 +25,12 @@ module GdsApi
25
25
  {
26
26
  path: options.fetch(:base_path),
27
27
  type: options.fetch(:type),
28
- }
28
+ },
29
29
  ],
30
30
  publishing_app: options.fetch(:publishing_app),
31
31
  rendering_app: options.fetch(:rendering_app),
32
32
  public_updated_at: time.now.iso8601,
33
- update_type: options.fetch(:update_type, "major")
33
+ update_type: options.fetch(:update_type, "major"),
34
34
  )
35
35
 
36
36
  publishing_api.patch_links(options.fetch(:content_id), links: options[:links]) if options[:links]
@@ -1,4 +1,4 @@
1
- require_relative 'base'
1
+ require_relative "base"
2
2
 
3
3
  # Adapter for the Publishing API.
4
4
  #
@@ -96,7 +96,7 @@ class GdsApi::PublishingApiV2 < GdsApi::Base
96
96
  # @see https://github.com/alphagov/publishing-api/blob/master/doc/api.md#post-v2contentcontent_idpublish
97
97
  def publish(content_id, update_type = nil, options = {})
98
98
  params = {
99
- update_type: update_type
99
+ update_type: update_type,
100
100
  }
101
101
 
102
102
  optional_keys = %i[locale previous_version]
@@ -159,7 +159,7 @@ class GdsApi::PublishingApiV2 < GdsApi::Base
159
159
  # @see https://github.com/alphagov/publishing-api/blob/master/doc/api.md#post-v2contentcontent_idunpublish
160
160
  def unpublish(content_id, type:, explanation: nil, alternative_path: nil, discard_drafts: false, allow_draft: false, previous_version: nil, locale: nil, unpublished_at: nil, redirects: nil)
161
161
  params = {
162
- type: type
162
+ type: type,
163
163
  }
164
164
 
165
165
  params[:explanation] = explanation if explanation
@@ -295,7 +295,7 @@ class GdsApi::PublishingApiV2 < GdsApi::Base
295
295
  # @see https://github.com/alphagov/publishing-api/blob/master/doc/api.md#patch-v2linkscontent_id
296
296
  def patch_links(content_id, params)
297
297
  payload = {
298
- links: params.fetch(:links)
298
+ links: params.fetch(:links),
299
299
  }
300
300
 
301
301
  payload = merge_optional_keys(payload, params, %i[previous_version bulk_publishing])
@@ -341,11 +341,11 @@ class GdsApi::PublishingApiV2 < GdsApi::Base
341
341
  (1..Float::INFINITY).each do |index|
342
342
  merged_params = params.merge(page: index)
343
343
  page = get_content_items(merged_params).to_h
344
- results = page.fetch('results', [])
344
+ results = page.fetch("results", [])
345
345
  results.each do |result|
346
346
  yielder << result
347
347
  end
348
- break if page.fetch('pages') <= index
348
+ break if page.fetch("pages") <= index
349
349
  end
350
350
  end
351
351
  end
@@ -397,8 +397,8 @@ class GdsApi::PublishingApiV2 < GdsApi::Base
397
397
  yielder.yield begin
398
398
  response = get_json(next_link)
399
399
  end
400
- next_link_info = response['links'].select { |link| link['rel'] == 'next' }.first
401
- next_link = next_link_info && next_link_info['href']
400
+ next_link_info = response["links"].select { |link| link["rel"] == "next" }.first
401
+ next_link = next_link_info && next_link_info["href"]
402
402
  end
403
403
  end
404
404
  end
@@ -1,30 +1,30 @@
1
- require_relative 'middleware/govuk_header_sniffer'
1
+ require_relative "middleware/govuk_header_sniffer"
2
2
 
3
3
  module GdsApi
4
4
  class Railtie < Rails::Railtie
5
5
  initializer "gds_api.initialize_govuk_request_id_sniffer" do |app|
6
6
  Rails.logger.debug "Using middleware GdsApi::GovukHeaderSniffer to sniff for Govuk-Request-Id header"
7
- app.middleware.use GdsApi::GovukHeaderSniffer, 'HTTP_GOVUK_REQUEST_ID'
7
+ app.middleware.use GdsApi::GovukHeaderSniffer, "HTTP_GOVUK_REQUEST_ID"
8
8
  end
9
9
 
10
10
  initializer "gds_api.initialize_govuk_original_url_sniffer" do |app|
11
11
  Rails.logger.debug "Using middleware GdsApi::GovukHeaderSniffer to sniff for Govuk-Original-Url header"
12
- app.middleware.use GdsApi::GovukHeaderSniffer, 'HTTP_GOVUK_ORIGINAL_URL'
12
+ app.middleware.use GdsApi::GovukHeaderSniffer, "HTTP_GOVUK_ORIGINAL_URL"
13
13
  end
14
14
 
15
15
  initializer "gds_api.initialize_govuk_authenticated_user_sniffer" do |app|
16
16
  Rails.logger.debug "Using middleware GdsApi::GovukHeaderSniffer to sniff for X-Govuk-Authenticated-User header"
17
- app.middleware.use GdsApi::GovukHeaderSniffer, 'HTTP_X_GOVUK_AUTHENTICATED_USER'
17
+ app.middleware.use GdsApi::GovukHeaderSniffer, "HTTP_X_GOVUK_AUTHENTICATED_USER"
18
18
  end
19
19
 
20
20
  initializer "gds_api.initialize_govuk_authenticated_user_organisation_sniffer" do |app|
21
21
  Rails.logger.debug "Using middleware GdsApi::GovukHeaderSniffer to sniff for X-Govuk-Authenticated-User-Organisation header"
22
- app.middleware.use GdsApi::GovukHeaderSniffer, 'HTTP_X_GOVUK_AUTHENTICATED_USER_ORGANISATION'
22
+ app.middleware.use GdsApi::GovukHeaderSniffer, "HTTP_X_GOVUK_AUTHENTICATED_USER_ORGANISATION"
23
23
  end
24
24
 
25
25
  initializer "gds_api.initialize_govuk_content_id_sniffer" do |app|
26
26
  Rails.logger.debug "Using middleware GdsApi::GovukHeaderSniffer to sniff for Govuk-Auth-Bypass-Id header"
27
- app.middleware.use GdsApi::GovukHeaderSniffer, 'HTTP_GOVUK_AUTH_BYPASS_ID'
27
+ app.middleware.use GdsApi::GovukHeaderSniffer, "HTTP_GOVUK_AUTH_BYPASS_ID"
28
28
  end
29
29
  end
30
30
  end
@@ -1,6 +1,6 @@
1
- require 'json'
2
- require 'forwardable'
3
- require 'rack/cache'
1
+ require "json"
2
+ require "forwardable"
3
+ require "rack/cache"
4
4
 
5
5
  module GdsApi
6
6
  # This wraps an HTTP response with a JSON body.
@@ -87,7 +87,7 @@ module GdsApi
87
87
  when Hash
88
88
  Hash[value.map { |k, v|
89
89
  # NOTE: Don't bother transforming if the value is nil
90
- if k == 'web_url' && v
90
+ if k == "web_url" && v
91
91
  # Use relative URLs to route when the web_url value is on the
92
92
  # same domain as the site root. Note that we can't just use the
93
93
  # `route_to` method, as this would give us technically correct
@@ -1,4 +1,4 @@
1
- require_relative 'base'
1
+ require_relative "base"
2
2
 
3
3
  class GdsApi::Router < GdsApi::Base
4
4
  ### Backends
@@ -36,8 +36,8 @@ class GdsApi::Router < GdsApi::Base
36
36
  handler: "redirect",
37
37
  redirect_to: destination,
38
38
  redirect_type: redirect_type,
39
- segments_mode: options[:segments_mode]
40
- }
39
+ segments_mode: options[:segments_mode],
40
+ },
41
41
  )
42
42
 
43
43
  commit_routes if options[:commit]
@@ -1,4 +1,4 @@
1
- require 'gds_api/search'
1
+ require "gds_api/search"
2
2
 
3
3
  module GdsApi
4
4
  class Rummager < Search
@@ -1,5 +1,5 @@
1
- require 'gds_api/base'
2
- require 'rack/utils'
1
+ require "gds_api/base"
2
+ require "rack/utils"
3
3
 
4
4
  module GdsApi
5
5
  # @api documented
@@ -12,7 +12,7 @@ module GdsApi
12
12
  document.merge(
13
13
  _type: type,
14
14
  _id: id,
15
- )
15
+ ),
16
16
  )
17
17
  end
18
18
 
@@ -30,27 +30,27 @@ module GdsApi
30
30
  class InvalidIndex < StandardError; end
31
31
 
32
32
  def add_document(id, document, index_name)
33
- raise(InvalidIndex, index_name) unless index_name == 'metasearch'
33
+ raise(InvalidIndex, index_name) unless index_name == "metasearch"
34
34
 
35
35
  post_json(
36
36
  "#{base_url}/v2/metasearch/documents",
37
37
  document.merge(
38
38
  _id: id,
39
- )
39
+ ),
40
40
  )
41
41
  end
42
42
 
43
43
  def delete_document(id, index_name)
44
- raise(InvalidIndex, index_name) unless index_name == 'metasearch'
44
+ raise(InvalidIndex, index_name) unless index_name == "metasearch"
45
45
 
46
46
  delete_json("#{base_url}/v2/metasearch/documents/#{id}")
47
47
  end
48
48
  end
49
49
 
50
- DEFAULT_API_VERSION = 'V1'.freeze
50
+ DEFAULT_API_VERSION = "V1".freeze
51
51
  API_VERSIONS = {
52
- 'V1' => GdsApi::Search::V1,
53
- 'V2' => GdsApi::Search::V2,
52
+ "V1" => GdsApi::Search::V1,
53
+ "V2" => GdsApi::Search::V2,
54
54
  }.freeze
55
55
  class UnknownAPIVersion < StandardError; end
56
56
 
@@ -100,7 +100,7 @@ module GdsApi
100
100
  Enumerator.new do |yielder|
101
101
  (0..Float::INFINITY).step(page_size).each do |index|
102
102
  search_params = args.merge(start: index.to_i, count: page_size)
103
- results = search(search_params, additional_headers).to_h.fetch('results', [])
103
+ results = search(search_params, additional_headers).to_h.fetch("results", [])
104
104
  results.each do |result|
105
105
  yielder << result
106
106
  end
@@ -111,16 +111,6 @@ module GdsApi
111
111
  end
112
112
  end
113
113
 
114
- # Advanced search.
115
- #
116
- # @deprecated Only in use by Whitehall. Use the `#search` method.
117
- def advanced_search(args)
118
- raise ArgumentError.new("Args cannot be blank") if args.nil? || args.empty?
119
-
120
- request_path = "#{base_url}/advanced_search?#{Rack::Utils.build_nested_query(args)}"
121
- get_json(request_path)
122
- end
123
-
124
114
  # Add a document to the search index.
125
115
  #
126
116
  # @param type [String] The search-api document type.
@@ -1,4 +1,4 @@
1
- require_relative 'base'
1
+ require_relative "base"
2
2
 
3
3
  class GdsApi::Support < GdsApi::Base
4
4
  def create_foi_request(request_details)
@@ -1,4 +1,4 @@
1
- require_relative 'base'
1
+ require_relative "base"
2
2
 
3
3
  # @api documented
4
4
  class GdsApi::SupportApi < GdsApi::Base
@@ -1,7 +1,7 @@
1
1
  module GdsApi
2
2
  module TestHelpers
3
3
  module AssetManager
4
- ASSET_MANAGER_ENDPOINT = Plek.current.find('asset-manager')
4
+ ASSET_MANAGER_ENDPOINT = Plek.current.find("asset-manager")
5
5
 
6
6
  def stub_any_asset_manager_call
7
7
  stub_request(:any, %r{\A#{ASSET_MANAGER_ENDPOINT}}).to_return(status: 200)
@@ -37,7 +37,7 @@ module GdsApi
37
37
 
38
38
  def stub_asset_manager_does_not_have_an_asset(id)
39
39
  response = {
40
- "_response_info" => { "status" => "not found" }
40
+ "_response_info" => { "status" => "not found" },
41
41
  }
42
42
 
43
43
  stub_request(:any, "#{ASSET_MANAGER_ENDPOINT}/assets/#{id}")
@@ -46,7 +46,7 @@ module GdsApi
46
46
 
47
47
  def stub_asset_manager_does_not_have_a_whitehall_asset(legacy_url_path)
48
48
  response = {
49
- "_response_info" => { "status" => "not found" }
49
+ "_response_info" => { "status" => "not found" },
50
50
  }
51
51
 
52
52
  stub_request(:get, "#{ASSET_MANAGER_ENDPOINT}/whitehall_assets/#{legacy_url_path}")
@@ -73,7 +73,7 @@ module GdsApi
73
73
  else
74
74
  options = {
75
75
  id: SecureRandom.uuid,
76
- filename: SecureRandom.hex(8)
76
+ filename: SecureRandom.hex(8),
77
77
  }.merge(response_url)
78
78
 
79
79
  file_url = "#{ASSET_MANAGER_ENDPOINT}/media/#{options[:id]}/#{options[:filename]}"
@@ -4,7 +4,7 @@ module GdsApi
4
4
  def stub_calendars_endpoint(in_division: nil)
5
5
  endpoint = "#{Plek.new.website_root}/bank-holidays"
6
6
  endpoint += "/#{in_division}" unless in_division.nil?
7
- endpoint + '.json'
7
+ endpoint + ".json"
8
8
  end
9
9
 
10
10
  def stub_calendars_has_no_bank_holidays(in_division: nil)
@@ -17,30 +17,30 @@ module GdsApi
17
17
  title: "Caturday #{idx}!",
18
18
  date: date.to_date.iso8601,
19
19
  notes: "Y'know, for cats!",
20
- bunting: true
20
+ bunting: true,
21
21
  }
22
22
  end
23
23
 
24
24
  response =
25
25
  if in_division.nil?
26
26
  {
27
- 'england-and-wales' => {
28
- division: 'england-and-wales',
29
- events: events
27
+ "england-and-wales" => {
28
+ division: "england-and-wales",
29
+ events: events,
30
30
  },
31
- 'scotland' => {
32
- division: 'scotland',
33
- events: events
31
+ "scotland" => {
32
+ division: "scotland",
33
+ events: events,
34
+ },
35
+ "northern-ireland" => {
36
+ division: "northern-ireland",
37
+ events: events,
34
38
  },
35
- 'northern-ireland' => {
36
- division: 'northern-ireland',
37
- events: events
38
- }
39
39
  }
40
40
  else
41
41
  {
42
42
  division: in_division,
43
- events: events
43
+ events: events,
44
44
  }
45
45
  end
46
46