gds-api-adapters 69.3.0 → 70.0.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
  SHA256:
3
- metadata.gz: 36d53c764d0ec5abb1685e55ff91057da30c9ce250dd46c4d5ae350b7684f66c
4
- data.tar.gz: 50687996dcb29b5ca7d8e0ec5cc3fca4ef40228ea2700d901528b9b2f98b30c4
3
+ metadata.gz: 632391e17f65b54797ea177945c0993fc71545d61a10975b244cf45355723ca1
4
+ data.tar.gz: dc7b387e7d2038c54541d4dd5382a75d316bbe383870326e89c6c31e8fdbb229
5
5
  SHA512:
6
- metadata.gz: 1c5cb0ce0c5bd0147374a6abff9a1e121ce811775b5120c73fc319df47aebd8c4acdbe264f3507be9e91b19e0a01e55e0711e9538237c940ad96f9de9ce9b08e
7
- data.tar.gz: 6584391dac6990ab4adeedc04491a1a9dec7f7ced21e8adc0da65e7c7fcea2bb242ac56e194e8b6572039a9917b9c7b78601899e822b101ba89f294fbb3a7d34
6
+ metadata.gz: e1a99f505078d1b27dba69a7b53b1945fdc83c2eb25fb0a6627090d6b77b67b43f324f8ff1ae76c447608e0265749083b78f74d28ec5c7703be4600aebf15174
7
+ data.tar.gz: a02640e69fb8a4d0292bdd97dee1061c5c498c5412812d74b40733bd7e10a06077631b93f74e8687b763362e1b4776221e60e201d287cbccf3b6d6d1868795c4
data/Rakefile CHANGED
@@ -30,5 +30,5 @@ end
30
30
 
31
31
  desc "Run the linter against changed files"
32
32
  task :lint do
33
- sh "bundle exec rubocop --format clang"
33
+ sh "bundle exec rubocop"
34
34
  end
data/lib/gds_api.rb CHANGED
@@ -1,6 +1,7 @@
1
1
  require "addressable"
2
2
  require "plek"
3
3
  require "time"
4
+ require "gds_api/account_api"
4
5
  require "gds_api/asset_manager"
5
6
  require "gds_api/calendars"
6
7
  require "gds_api/content_store"
@@ -21,6 +22,19 @@ require "gds_api/worldwide"
21
22
 
22
23
  # @api documented
23
24
  module GdsApi
25
+ # Creates a GdsApi::AccountApi adapter
26
+ #
27
+ # This will set a bearer token if a ACCOUNT_API_BEARER_TOKEN environment
28
+ # variable is set
29
+ #
30
+ # @return [GdsApi::AccountApi]
31
+ def self.account_api(options = {})
32
+ GdsApi::AccountApi.new(
33
+ Plek.find("account-api"),
34
+ { bearer_token: ENV["ACCOUNT_API_BEARER_TOKEN"] }.merge(options),
35
+ )
36
+ end
37
+
24
38
  # Creates a GdsApi::AssetManager adapter
25
39
  #
26
40
  # This will set a bearer token if a ASSET_MANAGER_BEARER_TOKEN environment
@@ -0,0 +1,90 @@
1
+ require_relative "base"
2
+ require_relative "exceptions"
3
+
4
+ # Adapter for the Account API
5
+ #
6
+ # @see https://github.com/alphagov/account-api
7
+ # @api documented
8
+ class GdsApi::AccountApi < GdsApi::Base
9
+ AUTH_HEADER_NAME = "GOVUK-Account-Session".freeze
10
+
11
+ # Get an OAuth sign-in URL to redirect the user to
12
+ #
13
+ # @param [String, nil] redirect_path path on GOV.UK to send the user to after authentication
14
+ # @param [String, nil] state_id identifier originally returned by #create_registration_state
15
+ #
16
+ # @return [Hash] An authentication URL and the OAuth state parameter (for CSRF protection)
17
+ def get_sign_in_url(redirect_path: nil, state_id: nil)
18
+ querystring = nested_query_string({ redirect_path: redirect_path, state_id: state_id }.compact)
19
+ get_json("#{endpoint}/api/oauth2/sign-in?#{querystring}")
20
+ end
21
+
22
+ # Validate an OAuth authentication response
23
+ #
24
+ # @param [String] code The OAuth code parameter, from the auth server.
25
+ # @param [String] state The OAuth state parameter, from the auth server.
26
+ #
27
+ # @return [Hash] The value for the govuk_account_session header, the path to redirect the user to, and the GA client ID (if there is one)
28
+ def validate_auth_response(code:, state:)
29
+ post_json("#{endpoint}/api/oauth2/callback", code: code, state: state)
30
+ end
31
+
32
+ # Register some initial state, to pass to get_sign_in_url, which is used to initialise the account if the user signs up
33
+ #
34
+ # @param [Hash, nil] attributes Initial attributes to store
35
+ #
36
+ # @return [Hash] The state ID to pass to get_sign_in_url
37
+ def create_registration_state(attributes:)
38
+ post_json("#{endpoint}/api/oauth2/state", attributes: attributes)
39
+ end
40
+
41
+ # Check if a user has an email subscription for the Transition Checker
42
+ #
43
+ # @param [String] govuk_account_session Value of the session header
44
+ #
45
+ # @return [Hash] Whether the user has a subscription, and a new session header
46
+ def check_for_email_subscription(govuk_account_session:)
47
+ get_json("#{endpoint}/api/transition-checker-email-subscription", auth_headers(govuk_account_session))
48
+ end
49
+
50
+ # Create or update a user's email subscription for the Transition Checker
51
+ #
52
+ # @param [String] govuk_account_session Value of the session header
53
+ # @param [String] slug The email topic slug
54
+ #
55
+ # @return [Hash] Whether the user has a subscription, and a new session header
56
+ def set_email_subscription(govuk_account_session:, slug:)
57
+ post_json("#{endpoint}/api/transition-checker-email-subscription", { slug: slug }, auth_headers(govuk_account_session))
58
+ end
59
+
60
+ # Look up the values of a user's attributes
61
+ #
62
+ # @param [String] attributes Names of the attributes to check
63
+ # @param [String] govuk_account_session Value of the session header
64
+ #
65
+ # @return [Hash] The attribute values (if present), and a new session header
66
+ def get_attributes(attributes:, govuk_account_session:)
67
+ querystring = nested_query_string({ attributes: attributes }.compact)
68
+ get_json("#{endpoint}/api/attributes?#{querystring}", auth_headers(govuk_account_session))
69
+ end
70
+
71
+ # Create or update attributes for a user
72
+ #
73
+ # @param [String] attributes Hash of new attribute values
74
+ # @param [String] govuk_account_session Value of the session header
75
+ #
76
+ # @return [Hash] A new session header
77
+ def set_attributes(attributes:, govuk_account_session:)
78
+ patch_json("#{endpoint}/api/attributes", { attributes: attributes.transform_values(&:to_json) }, auth_headers(govuk_account_session))
79
+ end
80
+
81
+ private
82
+
83
+ def nested_query_string(params)
84
+ Rack::Utils.build_nested_query(params)
85
+ end
86
+
87
+ def auth_headers(govuk_account_session)
88
+ { AUTH_HEADER_NAME => govuk_account_session }
89
+ end
90
+ end
data/lib/gds_api/base.rb CHANGED
@@ -71,7 +71,7 @@ private
71
71
  case value
72
72
  when Array
73
73
  value.map do |v|
74
- "#{CGI.escape(key.to_s + '[]')}=#{CGI.escape(v.to_s)}"
74
+ "#{CGI.escape("#{key}[]")}=#{CGI.escape(v.to_s)}"
75
75
  end
76
76
  else
77
77
  "#{CGI.escape(key.to_s)}=#{CGI.escape(value.to_s)}"
@@ -93,7 +93,7 @@ private
93
93
  def prefix_destination(redirect, path, query)
94
94
  uri = URI.parse(redirect["destination"])
95
95
  start_char = redirect["path"].length
96
- suffix = path[start_char..-1]
96
+ suffix = path[start_char..]
97
97
 
98
98
  if uri.path == "" && suffix[0] != "/"
99
99
  uri.path = "/#{suffix}"
@@ -14,8 +14,11 @@ module GdsApi
14
14
  end
15
15
 
16
16
  class EndpointNotFound < BaseError; end
17
+
17
18
  class TimedOutException < BaseError; end
19
+
18
20
  class InvalidUrl < BaseError; end
21
+
19
22
  class SocketErrorException < BaseError; end
20
23
 
21
24
  # Superclass for all 4XX and 5XX errors
@@ -31,25 +34,38 @@ module GdsApi
31
34
 
32
35
  # Superclass & fallback for all 4XX errors
33
36
  class HTTPClientError < HTTPErrorResponse; end
37
+
34
38
  class HTTPIntermittentClientError < HTTPClientError; end
35
39
 
36
40
  class HTTPNotFound < HTTPClientError; end
41
+
37
42
  class HTTPGone < HTTPClientError; end
43
+
38
44
  class HTTPPayloadTooLarge < HTTPClientError; end
45
+
39
46
  class HTTPUnauthorized < HTTPClientError; end
47
+
40
48
  class HTTPForbidden < HTTPClientError; end
49
+
41
50
  class HTTPConflict < HTTPClientError; end
51
+
42
52
  class HTTPUnprocessableEntity < HTTPClientError; end
53
+
43
54
  class HTTPBadRequest < HTTPClientError; end
55
+
44
56
  class HTTPTooManyRequests < HTTPIntermittentClientError; end
45
57
 
46
58
  # Superclass & fallback for all 5XX errors
47
59
  class HTTPServerError < HTTPErrorResponse; end
60
+
48
61
  class HTTPIntermittentServerError < HTTPServerError; end
49
62
 
50
63
  class HTTPInternalServerError < HTTPServerError; end
64
+
51
65
  class HTTPBadGateway < HTTPIntermittentServerError; end
66
+
52
67
  class HTTPUnavailable < HTTPIntermittentServerError; end
68
+
53
69
  class HTTPGatewayTimeout < HTTPIntermittentServerError; end
54
70
 
55
71
  module ExceptionHandling
@@ -101,10 +101,10 @@ module GdsApi
101
101
  rescue RestClient::Exception => e
102
102
  # Attempt to parse the body as JSON if possible
103
103
  error_details = begin
104
- e.http_body ? JSON.parse(e.http_body) : nil
105
- rescue JSON::ParserError
106
- nil
107
- end
104
+ e.http_body ? JSON.parse(e.http_body) : nil
105
+ rescue JSON::ParserError
106
+ nil
107
+ end
108
108
  raise build_specific_http_error(e, url, error_details)
109
109
  end
110
110
 
@@ -112,7 +112,7 @@ module GdsApi
112
112
  # The performance platform uses Backdrop and its query language for
113
113
  # storing and querying data.
114
114
  # Backdrop can be found here: https://github.com/alphagov/backdrop
115
- def statistics(options, is_multipart = false)
115
+ def statistics(options, is_multipart = false) # rubocop:disable Style/OptionalBooleanParameter
116
116
  params = {
117
117
  group_by: options[:group_by],
118
118
  collect: options[:collect],
@@ -122,7 +122,7 @@ module GdsApi
122
122
  }
123
123
 
124
124
  filter_param = is_multipart ? :filter_by_prefix : :filter_by
125
- params[filter_param] = "pagePath:" + options[:slug]
125
+ params[filter_param] = "pagePath:#{options[:slug]}"
126
126
 
127
127
  get_json("#{endpoint}/data/govuk-info/#{options[:transaction]}#{query_string(params)}")
128
128
  end
@@ -24,6 +24,7 @@ module GdsApi
24
24
  PATTERN = /([-a-z]+)(?:\s*=\s*([^,\s]+))?,?+/i.freeze
25
25
 
26
26
  def initialize(value = nil)
27
+ super()
27
28
  parse(value)
28
29
  end
29
30
 
@@ -67,7 +67,7 @@ module GdsApi
67
67
  #
68
68
  # @param args [Hash] A valid search query. See search-api documentation for options.
69
69
  #
70
- # @see https://github.com/alphagov/search-api/blob/master/doc/search-api.md
70
+ # @see https://github.com/alphagov/search-api/blob/master/docs/search-api.md
71
71
  def search(args, additional_headers = {})
72
72
  request_url = "#{base_url}/search.json?#{Rack::Utils.build_nested_query(args)}"
73
73
  get_json(request_url, additional_headers)
@@ -77,7 +77,7 @@ module GdsApi
77
77
  #
78
78
  # @param searches [Array] An array valid search queries. Maximum of 6. See search-api documentation for options.
79
79
  #
80
- # # @see https://github.com/alphagov/search-api/blob/master/doc/search-api.md
80
+ # # @see https://github.com/alphagov/search-api/blob/master/docs/search-api.md
81
81
  def batch_search(searches, additional_headers = {})
82
82
  url_friendly_searches = searches.each_with_index.map do |search, index|
83
83
  { index => search }
@@ -95,7 +95,7 @@ module GdsApi
95
95
  # @param args [Hash] A valid search query. See search-api documentation for options.
96
96
  # @param page_size [Integer] Number of results in each page.
97
97
  #
98
- # @see https://github.com/alphagov/search-api/blob/master/doc/search-api.md
98
+ # @see https://github.com/alphagov/search-api/blob/master/docs/search-api.md
99
99
  def search_enum(args, page_size: 100, additional_headers: {})
100
100
  Enumerator.new do |yielder|
101
101
  (0..Float::INFINITY).step(page_size).each do |index|
@@ -120,7 +120,7 @@ module GdsApi
120
120
  # GOV.UK - we only allow deletion from metasearch
121
121
  # @return [GdsApi::Response] A status code of 202 indicates the document has been successfully queued.
122
122
  #
123
- # @see https://github.com/alphagov/search-api/blob/master/doc/documents.md
123
+ # @see https://github.com/alphagov/search-api/blob/master/docs/documents.md
124
124
  def add_document(*args)
125
125
  @api.add_document(*args)
126
126
  end
@@ -132,7 +132,7 @@ module GdsApi
132
132
  # and contacts, which may be deleted with `delete_document`.
133
133
  #
134
134
  # @param base_path Base path of the page on GOV.UK.
135
- # @see https://github.com/alphagov/search-api/blob/master/doc/content-api.md
135
+ # @see https://github.com/alphagov/search-api/blob/master/docs/content-api.md
136
136
  def delete_content(base_path)
137
137
  request_url = "#{base_url}/content?link=#{base_path}"
138
138
  delete_json(request_url)
@@ -145,7 +145,7 @@ module GdsApi
145
145
  # and contacts.
146
146
  #
147
147
  # @param base_path [String] Base path of the page on GOV.UK.
148
- # @see https://github.com/alphagov/search-api/blob/master/doc/content-api.md
148
+ # @see https://github.com/alphagov/search-api/blob/master/docs/content-api.md
149
149
  def get_content(base_path)
150
150
  request_url = "#{base_url}/content?link=#{base_path}"
151
151
  get_json(request_url)
@@ -0,0 +1,100 @@
1
+ require "json"
2
+
3
+ module GdsApi
4
+ module TestHelpers
5
+ module AccountApi
6
+ ACCOUNT_API_ENDPOINT = Plek.find("account-api")
7
+
8
+ def stub_account_api_get_sign_in_url(redirect_path: nil, state_id: nil, auth_uri: "http://auth/provider", state: "state")
9
+ querystring = Rack::Utils.build_nested_query({ redirect_path: redirect_path, state_id: state_id }.compact)
10
+ stub_request(:get, "#{ACCOUNT_API_ENDPOINT}/api/oauth2/sign-in?#{querystring}")
11
+ .to_return(
12
+ status: 200,
13
+ body: { auth_uri: auth_uri, state: state }.to_json,
14
+ )
15
+ end
16
+
17
+ def stub_account_api_validates_auth_response(code: nil, state: nil, govuk_account_session: "govuk-account-session", redirect_path: "/", ga_client_id: "ga-client-id")
18
+ stub_request(:post, "#{ACCOUNT_API_ENDPOINT}/api/oauth2/callback")
19
+ .with(body: hash_including({ code: code, state: state }.compact))
20
+ .to_return(
21
+ status: 200,
22
+ body: { govuk_account_session: govuk_account_session, redirect_path: redirect_path, ga_client_id: ga_client_id }.to_json,
23
+ )
24
+ end
25
+
26
+ def stub_account_api_rejects_auth_response(code: nil, state: nil)
27
+ stub_request(:post, "#{ACCOUNT_API_ENDPOINT}/api/oauth2/callback")
28
+ .with(body: hash_including({ code: code, state: state }.compact))
29
+ .to_return(status: 401)
30
+ end
31
+
32
+ def stub_account_api_create_registration_state(attributes: nil, state_id: "state-id")
33
+ stub_request(:post, "#{ACCOUNT_API_ENDPOINT}/api/oauth2/state")
34
+ .with(body: hash_including({ attributes: attributes }.compact))
35
+ .to_return(
36
+ status: 200,
37
+ body: { state_id: state_id }.to_json,
38
+ )
39
+ end
40
+
41
+ def stub_account_api_has_email_subscription(govuk_account_session: nil, new_govuk_account_session: nil)
42
+ if govuk_account_session
43
+ stub_request(:get, "#{ACCOUNT_API_ENDPOINT}/api/transition-checker-email-subscription")
44
+ .with(headers: { GdsApi::AccountApi::AUTH_HEADER_NAME => govuk_account_session })
45
+ .to_return(status: 200, body: { govuk_account_session: new_govuk_account_session, has_subscription: true }.compact.to_json)
46
+ else
47
+ stub_request(:get, "#{ACCOUNT_API_ENDPOINT}/api/transition-checker-email-subscription")
48
+ .to_return(status: 200, body: { govuk_account_session: new_govuk_account_session, has_subscription: true }.compact.to_json)
49
+ end
50
+ end
51
+
52
+ def stub_account_api_does_not_have_email_subscription(govuk_account_session: nil, new_govuk_account_session: nil)
53
+ if govuk_account_session
54
+ stub_request(:get, "#{ACCOUNT_API_ENDPOINT}/api/transition-checker-email-subscription")
55
+ .with(headers: { GdsApi::AccountApi::AUTH_HEADER_NAME => govuk_account_session })
56
+ .to_return(status: 200, body: { govuk_account_session: new_govuk_account_session, has_subscription: false }.compact.to_json)
57
+ else
58
+ stub_request(:get, "#{ACCOUNT_API_ENDPOINT}/api/transition-checker-email-subscription")
59
+ .to_return(status: 200, body: { govuk_account_session: new_govuk_account_session, has_subscription: false }.compact.to_json)
60
+ end
61
+ end
62
+
63
+ def stub_account_api_set_email_subscription(govuk_account_session: nil, slug: "slug", new_govuk_account_session: nil)
64
+ if govuk_account_session
65
+ stub_request(:post, "#{ACCOUNT_API_ENDPOINT}/api/transition-checker-email-subscription")
66
+ .with(body: hash_including({ slug: slug }.compact), headers: { GdsApi::AccountApi::AUTH_HEADER_NAME => govuk_account_session })
67
+ .to_return(status: 200, body: { govuk_account_session: new_govuk_account_session }.compact.to_json)
68
+ else
69
+ stub_request(:post, "#{ACCOUNT_API_ENDPOINT}/api/transition-checker-email-subscription")
70
+ .with(body: hash_including({ slug: slug }.compact))
71
+ .to_return(status: 200, body: { govuk_account_session: new_govuk_account_session }.compact.to_json)
72
+ end
73
+ end
74
+
75
+ def stub_account_api_has_attributes(govuk_account_session: nil, attributes: [], values: {}, new_govuk_account_session: nil)
76
+ querystring = Rack::Utils.build_nested_query({ attributes: attributes }.compact)
77
+ if govuk_account_session
78
+ stub_request(:get, "#{ACCOUNT_API_ENDPOINT}/api/attributes?#{querystring}")
79
+ .with(headers: { GdsApi::AccountApi::AUTH_HEADER_NAME => govuk_account_session })
80
+ .to_return(status: 200, body: { govuk_account_session: new_govuk_account_session, values: values }.compact.to_json)
81
+ else
82
+ stub_request(:get, "#{ACCOUNT_API_ENDPOINT}/api/attributes?#{querystring}")
83
+ .to_return(status: 200, body: { govuk_account_session: new_govuk_account_session, values: values }.compact.to_json)
84
+ end
85
+ end
86
+
87
+ def stub_account_api_set_attributes(govuk_account_session: nil, attributes: nil, new_govuk_account_session: nil)
88
+ if govuk_account_session
89
+ stub_request(:patch, "#{ACCOUNT_API_ENDPOINT}/api/attributes")
90
+ .with(body: hash_including({ attributes: attributes&.transform_values(&:to_json) }.compact), headers: { GdsApi::AccountApi::AUTH_HEADER_NAME => govuk_account_session })
91
+ .to_return(status: 200, body: { govuk_account_session: new_govuk_account_session }.compact.to_json)
92
+ else
93
+ stub_request(:patch, "#{ACCOUNT_API_ENDPOINT}/api/attributes")
94
+ .with(body: hash_including({ attributes: attributes&.transform_values(&:to_json) }.compact))
95
+ .to_return(status: 200, body: { govuk_account_session: new_govuk_account_session }.compact.to_json)
96
+ end
97
+ end
98
+ end
99
+ end
100
+ end
@@ -4,7 +4,7 @@ module GdsApi
4
4
  def 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)
@@ -7,7 +7,7 @@ module GdsApi
7
7
  module ContentStore
8
8
  include ContentItemHelpers
9
9
 
10
- def content_store_endpoint(draft = false)
10
+ def content_store_endpoint(draft: false)
11
11
  draft ? Plek.current.find("draft-content-store") : Plek.current.find("content-store")
12
12
  end
13
13
 
@@ -21,10 +21,10 @@ module GdsApi
21
21
  def stub_content_store_has_item(base_path, body = content_item_for_base_path(base_path), options = {})
22
22
  max_age = options.fetch(:max_age, 900)
23
23
  visibility = options[:private] ? "private" : "public"
24
- url = content_store_endpoint(options[:draft]) + "/content" + base_path
25
24
  body = body.to_json unless body.is_a?(String)
26
25
 
27
- stub_request(:get, url).to_return(
26
+ endpoint = content_store_endpoint(draft: options[:draft])
27
+ stub_request(:get, "#{endpoint}/content#{base_path}").to_return(
28
28
  status: 200,
29
29
  body: body,
30
30
  headers: {
@@ -35,11 +35,9 @@ module GdsApi
35
35
  end
36
36
 
37
37
  def stub_content_store_does_not_have_item(base_path, options = {})
38
- url = content_store_endpoint(options[:draft]) + "/content" + base_path
39
- stub_request(:get, url).to_return(status: 404, headers: {})
40
-
41
- url = content_store_endpoint(options[:draft]) + "/incoming-links" + base_path
42
- stub_request(:get, url).to_return(status: 404, headers: {})
38
+ endpoint = content_store_endpoint(draft: options[:draft])
39
+ stub_request(:get, "#{endpoint}/content#{base_path}").to_return(status: 404, headers: {})
40
+ stub_request(:get, "#{endpoint}/incoming-links#{base_path}").to_return(status: 404, headers: {})
43
41
  end
44
42
 
45
43
  # Content store has gone item
@@ -67,10 +65,9 @@ module GdsApi
67
65
  # "details" => {}
68
66
  # }
69
67
  def stub_content_store_has_gone_item(base_path, body = gone_content_item_for_base_path(base_path), options = {})
70
- url = content_store_endpoint(options[:draft]) + "/content" + base_path
71
68
  body = body.to_json unless body.is_a?(String)
72
-
73
- stub_request(:get, url).to_return(
69
+ endpoint = content_store_endpoint(draft: options[:draft])
70
+ stub_request(:get, "#{endpoint}/content#{base_path}").to_return(
74
71
  status: 410,
75
72
  body: body,
76
73
  headers: {},
@@ -86,7 +83,7 @@ module GdsApi
86
83
  end
87
84
 
88
85
  def stub_content_store_has_incoming_links(base_path, links)
89
- url = content_store_endpoint + "/incoming-links" + base_path
86
+ url = "#{content_store_endpoint}/incoming-links#{base_path}"
90
87
  body = links.to_json
91
88
 
92
89
  stub_request(:get, url).to_return(body: body)
@@ -10,9 +10,9 @@ module GdsApi
10
10
  "postcode" => postcode,
11
11
  }
12
12
 
13
- stub_request(:get, "#{MAPIT_ENDPOINT}/postcode/" + postcode.tr(" ", "+") + ".json")
13
+ stub_request(:get, "#{MAPIT_ENDPOINT}/postcode/#{postcode.tr(' ', '+')}.json")
14
14
  .to_return(body: response.to_json, status: 200)
15
- stub_request(:get, "#{MAPIT_ENDPOINT}/postcode/partial/" + postcode.split(" ").first + ".json")
15
+ stub_request(:get, "#{MAPIT_ENDPOINT}/postcode/partial/#{postcode.split(' ').first}.json")
16
16
  .to_return(body: response.to_json, status: 200)
17
17
  end
18
18
 
@@ -37,9 +37,9 @@ module GdsApi
37
37
  }]
38
38
  end]
39
39
 
40
- stub_request(:get, "#{MAPIT_ENDPOINT}/postcode/" + postcode.tr(" ", "+") + ".json")
40
+ stub_request(:get, "#{MAPIT_ENDPOINT}/postcode/#{postcode.tr(' ', '+')}.json")
41
41
  .to_return(body: response.merge("areas" => area_response).to_json, status: 200)
42
- stub_request(:get, "#{MAPIT_ENDPOINT}/postcode/partial/" + postcode.split(" ").first + ".json")
42
+ stub_request(:get, "#{MAPIT_ENDPOINT}/postcode/partial/#{postcode.split(' ').first}.json")
43
43
  .to_return(body: response.to_json, status: 200)
44
44
  end
45
45
 
@@ -51,29 +51,29 @@ module GdsApi
51
51
  "country_name" => country_name,
52
52
  }
53
53
 
54
- stub_request(:get, "#{MAPIT_ENDPOINT}/postcode/" + postcode.tr(" ", "+") + ".json")
54
+ stub_request(:get, "#{MAPIT_ENDPOINT}/postcode/#{postcode.tr(' ', '+')}.json")
55
55
  .to_return(body: response.to_json, status: 200)
56
- stub_request(:get, "#{MAPIT_ENDPOINT}/postcode/partial/" + postcode.split(" ").first + ".json")
56
+ stub_request(:get, "#{MAPIT_ENDPOINT}/postcode/partial/#{postcode.split(' ').first}.json")
57
57
  .to_return(body: response.to_json, status: 200)
58
58
  end
59
59
 
60
60
  def stub_mapit_does_not_have_a_postcode(postcode)
61
- stub_request(:get, "#{MAPIT_ENDPOINT}/postcode/" + postcode.tr(" ", "+") + ".json")
61
+ stub_request(:get, "#{MAPIT_ENDPOINT}/postcode/#{postcode.tr(' ', '+')}.json")
62
62
  .to_return(body: { "code" => 404, "error" => "No Postcode matches the given query." }.to_json, status: 404)
63
63
  end
64
64
 
65
65
  def stub_mapit_does_not_have_a_bad_postcode(postcode)
66
- stub_request(:get, "#{MAPIT_ENDPOINT}/postcode/" + postcode.tr(" ", "+") + ".json")
66
+ stub_request(:get, "#{MAPIT_ENDPOINT}/postcode/#{postcode.tr(' ', '+')}.json")
67
67
  .to_return(body: { "code" => 400, "error" => "Postcode '#{postcode}' is not valid." }.to_json, status: 400)
68
68
  end
69
69
 
70
70
  def stub_mapit_has_areas(area_type, areas)
71
- stub_request(:get, "#{MAPIT_ENDPOINT}/areas/" + area_type + ".json")
71
+ stub_request(:get, "#{MAPIT_ENDPOINT}/areas/#{area_type}.json")
72
72
  .to_return(body: areas.to_json, status: 200)
73
73
  end
74
74
 
75
75
  def stub_mapit_does_not_have_areas(area_type)
76
- stub_request(:get, "#{MAPIT_ENDPOINT}/areas/" + area_type + ".json")
76
+ stub_request(:get, "#{MAPIT_ENDPOINT}/areas/#{area_type}.json")
77
77
  .to_return(body: [].to_json, status: 200)
78
78
  end
79
79
 
@@ -68,7 +68,7 @@ module GdsApi
68
68
  }
69
69
 
70
70
  filter_param = is_multipart ? :filter_by_prefix : :filter_by
71
- params[filter_param] = "pagePath:" + options[:slug]
71
+ params[filter_param] = "pagePath:#{options[:slug]}"
72
72
 
73
73
  stub_http_request(:get, "#{PP_DATA_OUT_ENDPOINT}/data/govuk-info/#{options[:transaction]}")
74
74
  .with(query: params)
@@ -8,7 +8,7 @@ module GdsApi
8
8
  module PublishingApi
9
9
  include ContentItemHelpers
10
10
 
11
- PUBLISHING_API_V2_ENDPOINT = Plek.current.find("publishing-api") + "/v2"
11
+ PUBLISHING_API_V2_ENDPOINT = "#{Plek.current.find('publishing-api')}/v2".freeze
12
12
  PUBLISHING_API_ENDPOINT = Plek.current.find("publishing-api")
13
13
 
14
14
  # Stub a PUT /v2/content/:content_id request with the given content id and request body.
@@ -213,7 +213,7 @@ module GdsApi
213
213
  # @param attributes_or_matcher [Object]
214
214
  # @param times [Integer]
215
215
  def assert_publishing_api_put_content(content_id, attributes_or_matcher = nil, times = 1)
216
- url = PUBLISHING_API_V2_ENDPOINT + "/content/" + content_id
216
+ url = "#{PUBLISHING_API_V2_ENDPOINT}/content/#{content_id}"
217
217
  assert_publishing_api(:put, url, attributes_or_matcher, times)
218
218
  end
219
219
 
@@ -243,7 +243,7 @@ module GdsApi
243
243
  # @param attributes_or_matcher [Object]
244
244
  # @param times [Integer]
245
245
  def assert_publishing_api_patch_links(content_id, attributes_or_matcher = nil, times = 1)
246
- url = PUBLISHING_API_V2_ENDPOINT + "/links/" + content_id
246
+ url = "#{PUBLISHING_API_V2_ENDPOINT}/links/#{content_id}"
247
247
  assert_publishing_api(:patch, url, attributes_or_matcher, times)
248
248
  end
249
249
 
@@ -308,7 +308,7 @@ module GdsApi
308
308
  # @param items [Array]
309
309
  # @param params [Hash]
310
310
  def stub_publishing_api_has_content(items, params = {})
311
- url = PUBLISHING_API_V2_ENDPOINT + "/content"
311
+ url = "#{PUBLISHING_API_V2_ENDPOINT}/content"
312
312
 
313
313
  if params.respond_to? :fetch
314
314
  per_page = params.fetch(:per_page, 50)
@@ -369,7 +369,7 @@ module GdsApi
369
369
  # @param item [Hash]
370
370
  def stub_publishing_api_has_item(item, params = {})
371
371
  item = deep_transform_keys(item, &:to_sym)
372
- url = PUBLISHING_API_V2_ENDPOINT + "/content/" + item[:content_id]
372
+ url = "#{PUBLISHING_API_V2_ENDPOINT}/content/#{item[:content_id]}"
373
373
  stub_request(:get, url)
374
374
  .with(query: hash_including(params))
375
375
  .to_return(status: 200, body: item.to_json, headers: {})
@@ -380,7 +380,7 @@ module GdsApi
380
380
  # @param items [Array]
381
381
  def stub_publishing_api_has_item_in_sequence(content_id, items)
382
382
  items = items.each { |item| deep_transform_keys(item, &:to_sym) }
383
- url = PUBLISHING_API_V2_ENDPOINT + "/content/" + content_id
383
+ url = "#{PUBLISHING_API_V2_ENDPOINT}/content/#{content_id}"
384
384
  calls = -1
385
385
 
386
386
  stub_request(:get, url).to_return do |_request|
@@ -395,7 +395,7 @@ module GdsApi
395
395
  #
396
396
  # @param content_id [UUID]
397
397
  def stub_publishing_api_does_not_have_item(content_id, params = {})
398
- url = PUBLISHING_API_V2_ENDPOINT + "/content/" + content_id
398
+ url = "#{PUBLISHING_API_V2_ENDPOINT}/content/#{content_id}"
399
399
  stub_request(:get, url)
400
400
  .with(query: hash_including(params))
401
401
  .to_return(status: 404, body: resource_not_found(content_id, "content item").to_json, headers: {})
@@ -433,7 +433,7 @@ module GdsApi
433
433
  # }
434
434
  def stub_publishing_api_has_links(links)
435
435
  links = deep_transform_keys(links, &:to_sym)
436
- url = PUBLISHING_API_V2_ENDPOINT + "/links/" + links[:content_id]
436
+ url = "#{PUBLISHING_API_V2_ENDPOINT}/links/#{links[:content_id]}"
437
437
  stub_request(:get, url).to_return(status: 200, body: links.to_json, headers: {})
438
438
  end
439
439
 
@@ -497,7 +497,7 @@ module GdsApi
497
497
  request_params["with_drafts"] = false unless with_drafts
498
498
  request_params["generate"] = true if generate
499
499
 
500
- url = PUBLISHING_API_V2_ENDPOINT + "/expanded-links/" + links[:content_id]
500
+ url = "#{PUBLISHING_API_V2_ENDPOINT}/expanded-links/#{links[:content_id]}"
501
501
  stub_request(:get, url)
502
502
  .with(query: request_params)
503
503
  .to_return(status: 200, body: links.to_json, headers: {})
@@ -528,7 +528,7 @@ module GdsApi
528
528
  # }
529
529
  # }
530
530
  def stub_publishing_api_has_links_for_content_ids(links)
531
- url = PUBLISHING_API_V2_ENDPOINT + "/links/by-content-id"
531
+ url = "#{PUBLISHING_API_V2_ENDPOINT}/links/by-content-id"
532
532
  stub_request(:post, url).with(body: { content_ids: links.keys }).to_return(status: 200, body: links.to_json, headers: {})
533
533
  end
534
534
 
@@ -536,7 +536,7 @@ module GdsApi
536
536
  #
537
537
  # @param content_id [UUID]
538
538
  def stub_publishing_api_does_not_have_links(content_id)
539
- url = PUBLISHING_API_V2_ENDPOINT + "/links/" + content_id
539
+ url = "#{PUBLISHING_API_V2_ENDPOINT}/links/#{content_id}"
540
540
  stub_request(:get, url).to_return(status: 404, body: resource_not_found(content_id, "link set").to_json, headers: {})
541
541
  end
542
542
 
@@ -552,7 +552,7 @@ module GdsApi
552
552
  # })
553
553
  #
554
554
  def stub_publishing_api_has_lookups(lookup_hash)
555
- url = PUBLISHING_API_ENDPOINT + "/lookup-by-base-path"
555
+ url = "#{PUBLISHING_API_ENDPOINT}/lookup-by-base-path"
556
556
  stub_request(:post, url).to_return(body: lookup_hash.to_json)
557
557
  end
558
558
 
@@ -605,7 +605,7 @@ module GdsApi
605
605
  # @param items [Array]
606
606
  # @param params [Hash]
607
607
  def stub_publishing_api_get_editions(editions, params = {})
608
- url = PUBLISHING_API_V2_ENDPOINT + "/editions"
608
+ url = "#{PUBLISHING_API_V2_ENDPOINT}/editions"
609
609
 
610
610
  results = editions.map do |edition|
611
611
  next edition unless params[:fields]
@@ -670,7 +670,7 @@ module GdsApi
670
670
  end
671
671
 
672
672
  def stub_publishing_api_destroy_intent(base_path)
673
- url = PUBLISHING_API_ENDPOINT + "/publish-intent" + base_path
673
+ url = "#{PUBLISHING_API_ENDPOINT}/publish-intent#{base_path}"
674
674
  stub_request(:delete, url).to_return(status: 200, body: "{}", headers: { "Content-Type" => "application/json; charset=utf-8" })
675
675
  end
676
676
 
@@ -679,7 +679,7 @@ module GdsApi
679
679
  end
680
680
 
681
681
  def assert_publishing_api_put_intent(base_path, attributes_or_matcher = {}, times = 1)
682
- url = PUBLISHING_API_ENDPOINT + "/publish-intent" + base_path
682
+ url = "#{PUBLISHING_API_ENDPOINT}/publish-intent#{base_path}"
683
683
  assert_publishing_api_put(url, attributes_or_matcher, times)
684
684
  end
685
685
 
@@ -792,8 +792,7 @@ module GdsApi
792
792
  def stub_publishing_api_returns_path_reservation_validation_error_for(base_path, error_fields = {})
793
793
  error_fields = { "base_path" => ["Computer says no"] } if error_fields.empty?
794
794
 
795
- message = error_fields.keys.first.to_s.capitalize.gsub(/_/, " ") + " " +
796
- error_fields.values.flatten.first
795
+ message = "#{error_fields.keys.first.to_s.capitalize.gsub(/_/, ' ')} #{error_fields.values.flatten.first}"
797
796
 
798
797
  error = { code: 422, message: message, fields: error_fields }
799
798
 
@@ -817,7 +816,7 @@ module GdsApi
817
816
  response_hash = { status: 200, body: "{}", headers: { "Content-Type" => "application/json; charset=utf-8" } }
818
817
  response_hash.merge!(override_response_hash)
819
818
  response_hash[:body] = response_hash[:body].to_json if response_hash[:body].is_a?(Hash)
820
- url = PUBLISHING_API_V2_ENDPOINT + resource_path + "/" + content_id
819
+ url = "#{PUBLISHING_API_V2_ENDPOINT}#{resource_path}/#{content_id}"
821
820
  stub_request(method, url).with(body: body).to_return(response_hash)
822
821
  end
823
822
 
@@ -858,7 +857,7 @@ module GdsApi
858
857
  end
859
858
 
860
859
  def stub_publishing_api_unreserve_path_with_code(base_path, publishing_app, code)
861
- url = PUBLISHING_API_ENDPOINT + "/paths" + base_path
860
+ url = "#{PUBLISHING_API_ENDPOINT}/paths#{base_path}"
862
861
  body = { publishing_app: publishing_app }
863
862
  stub_request(:delete, url).with(body: body).to_return(status: code, body: "{}", headers: { "Content-Type" => "application/json; charset=utf-8" })
864
863
  end
@@ -20,7 +20,7 @@ module GdsApi
20
20
  url = if index
21
21
  SEARCH_ENDPOINT + "/#{index}/documents"
22
22
  else
23
- SEARCH_ENDPOINT + "/documents"
23
+ "#{SEARCH_ENDPOINT}/documents"
24
24
  end
25
25
 
26
26
  assert_requested(:post, url, **options) do |req|
@@ -1,3 +1,3 @@
1
1
  module GdsApi
2
- VERSION = "69.3.0".freeze
2
+ VERSION = "70.0.0".freeze
3
3
  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: 69.3.0
4
+ version: 70.0.0
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: 2021-01-25 00:00:00.000000000 Z
11
+ date: 2021-03-15 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: addressable
@@ -266,16 +266,16 @@ dependencies:
266
266
  name: rubocop-govuk
267
267
  requirement: !ruby/object:Gem::Requirement
268
268
  requirements:
269
- - - ">="
269
+ - - '='
270
270
  - !ruby/object:Gem::Version
271
- version: '0'
271
+ version: 4.0.0.pre.1
272
272
  type: :development
273
273
  prerelease: false
274
274
  version_requirements: !ruby/object:Gem::Requirement
275
275
  requirements:
276
- - - ">="
276
+ - - '='
277
277
  - !ruby/object:Gem::Version
278
- version: '0'
278
+ version: 4.0.0.pre.1
279
279
  - !ruby/object:Gem::Dependency
280
280
  name: simplecov
281
281
  requirement: !ruby/object:Gem::Requirement
@@ -371,6 +371,7 @@ files:
371
371
  - Rakefile
372
372
  - lib/gds-api-adapters.rb
373
373
  - lib/gds_api.rb
374
+ - lib/gds_api/account_api.rb
374
375
  - lib/gds_api/asset_manager.rb
375
376
  - lib/gds_api/base.rb
376
377
  - lib/gds_api/calendars.rb
@@ -398,6 +399,7 @@ files:
398
399
  - lib/gds_api/search.rb
399
400
  - lib/gds_api/support.rb
400
401
  - lib/gds_api/support_api.rb
402
+ - lib/gds_api/test_helpers/account_api.rb
401
403
  - lib/gds_api/test_helpers/asset_manager.rb
402
404
  - lib/gds_api/test_helpers/calendars.rb
403
405
  - lib/gds_api/test_helpers/common_responses.rb
@@ -440,7 +442,7 @@ required_ruby_version: !ruby/object:Gem::Requirement
440
442
  requirements:
441
443
  - - ">="
442
444
  - !ruby/object:Gem::Version
443
- version: 2.4.0
445
+ version: 2.6.0
444
446
  required_rubygems_version: !ruby/object:Gem::Requirement
445
447
  requirements:
446
448
  - - ">="