gds-api-adapters 69.0.0 → 71.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: b5de255ce4237b87f433deb2306447f9bda4534d3d85cad5b2ea3053b8d2dda1
4
- data.tar.gz: 2144a904a6f4b3eeb6d0ec0c14b11d680d844f37c432d8c2909f843ce67a6927
3
+ metadata.gz: f43e07de0971fb6d31f613c0e6ecf3894ddc198755ad003da36e6c43e37dedf5
4
+ data.tar.gz: 66369531af1d7c4412b79994759e360b78cb67b2e842a3d6f82e10267bd18876
5
5
  SHA512:
6
- metadata.gz: d045fefa180fd19839f9f10db2f6743bfe6e70f916434d486dd1745c8457b2874870f4fbd7f3f46eca5ee010afe9fc01b3b63e625694684d36feae3b69febb4b
7
- data.tar.gz: 812e40c01ab8876121451782fbf6103facfe9dd97f2e1b246a047ef3ec628f116dda681f7de2bdd36dfdc8fafd8ae8ba450bfed00da3b9100a02abd8ee51c78e
6
+ metadata.gz: ca1f75189c94449dac72f8e3826b67c36d57e55a40103a69aa2cc48dce9cbc75eff901b060d2d360d301ec482bca4937f5178a57b3b53a1e497bb96ca1a84490
7
+ data.tar.gz: 2cca74c89f2a0f827a09917fe6817aeac7199871f1f4c990845668b68c7daff9889dd2f885c809399c732d98b8c074f607072c24db8ad438a287b23f96a5dcb9
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 }, 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
@@ -7,12 +7,13 @@ class GdsApi::AssetManager < GdsApi::Base
7
7
  #
8
8
  # Makes a +POST+ request to the asset manager api to create an asset.
9
9
  #
10
- # The asset must be provided as a +Hash+ with a single +file+ attribute that
10
+ # The asset must be provided as a +Hash+ with a +file+ attribute that
11
11
  # behaves like a +File+ object. The +content-type+ that the asset manager will
12
- # subsequently serve will be based *only* on the file's extension (derived
13
- # from +#path+). If you supply a +content-type+ via, for example
12
+ # subsequently serve will be based on the file's extension (derived from
13
+ # +#path+). If you supply a +content-type+ via, for example
14
14
  # +ActionDispatch::Http::UploadedFile+ or another multipart wrapper, it will
15
- # be ignored.
15
+ # be ignored. To provide a +content-type+ directly you must be specify it
16
+ # as a +content_type+ attribute of the hash.
16
17
  #
17
18
  # @param asset [Hash] The attributes for the asset to send to the api. Must
18
19
  # contain +file+, which behaves like a +File+. All other attributes will be
@@ -143,12 +144,10 @@ class GdsApi::AssetManager < GdsApi::Base
143
144
  #
144
145
  # Makes a +PUT+ request to the asset manager api to update an asset.
145
146
  #
146
- # The asset must be provided as a +Hash+ with a single +file+ attribute that
147
- # behaves like a +File+ object. The +content-type+ that the asset manager will
148
- # subsequently serve will be based *only* on the file's extension (derived
149
- # from +#path+). If you supply a +content-type+ via, for example
150
- # +ActionDispatch::Http::UploadedFile+ or another multipart wrapper, it will
151
- # be ignored.
147
+ # The asset must be provided as a +Hash+ with a +file+ attribute that
148
+ # behaves like a +File+ object. The +content-type+ of the file will be based
149
+ # on the files extension unless you specify a +content_type+ attribute of
150
+ # the hash to set it.
152
151
  #
153
152
  # @param id [String] The asset identifier (a UUID).
154
153
  # @param asset [Hash] The attributes for the asset to send to the api. Must
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}"
@@ -15,14 +15,15 @@ class GdsApi::EmailAlertApi < GdsApi::Base
15
15
  raise ArgumentError, message
16
16
  end
17
17
 
18
- create_subscriber_list(attributes)
18
+ post_json("#{endpoint}/subscriber-lists", attributes)
19
19
  end
20
20
 
21
- # Post a subscriber list
21
+ # Get a subscriber list
22
22
  #
23
23
  # @param attributes [Hash] document_type, links, tags used to search existing subscriber lists
24
- def create_subscriber_list(attributes)
25
- post_json("#{endpoint}/subscriber-lists", attributes)
24
+ def find_subscriber_list(attributes)
25
+ query_string = nested_query_string(attributes)
26
+ get_json("#{endpoint}/subscriber-lists?" + query_string)
26
27
  end
27
28
 
28
29
  # Post a content change
@@ -39,17 +40,6 @@ class GdsApi::EmailAlertApi < GdsApi::Base
39
40
  post_json("#{endpoint}/messages", message, headers)
40
41
  end
41
42
 
42
- # Unpublishing alert
43
- #
44
- # @param message [Hash] content_id
45
- #
46
- # Used by email-alert-service to send a message to email-alert-api
47
- # when an unpublishing message is put on the Rabbitmq queue by
48
- # publishing-api
49
- def send_unpublish_message(message)
50
- post_json("#{endpoint}/unpublish-messages", message)
51
- end
52
-
53
43
  # Get topic matches
54
44
  #
55
45
  # @param attributes [Hash] tags, links, document_type,
@@ -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
 
@@ -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 }.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 }.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)
@@ -132,16 +132,24 @@ module GdsApi
132
132
  )
133
133
  end
134
134
 
135
+ def stub_email_alert_api_has_subscriber_list(attributes)
136
+ stub_request(:get, build_subscriber_lists_url(attributes))
137
+ .to_return(
138
+ status: 200,
139
+ body: get_subscriber_list_response(attributes).to_json,
140
+ )
141
+ end
142
+
143
+ def stub_email_alert_api_does_not_have_subscriber_list(attributes)
144
+ stub_request(:get, build_subscriber_lists_url(attributes))
145
+ .to_return(status: 404)
146
+ end
147
+
135
148
  def stub_email_alert_api_refuses_to_create_subscriber_list
136
149
  stub_request(:post, build_subscriber_lists_url)
137
150
  .to_return(status: 422)
138
151
  end
139
152
 
140
- def stub_email_alert_api_accepts_unpublishing_message
141
- stub_request(:post, "#{EMAIL_ALERT_API_ENDPOINT}/unpublish-messages")
142
- .to_return(status: 202, body: {}.to_json)
143
- end
144
-
145
153
  def stub_email_alert_api_accepts_content_change
146
154
  stub_request(:post, "#{EMAIL_ALERT_API_ENDPOINT}/content-changes")
147
155
  .to_return(status: 202, body: {}.to_json)
@@ -5,7 +5,7 @@ module GdsApi
5
5
  module LocalLinksManager
6
6
  LOCAL_LINKS_MANAGER_ENDPOINT = Plek.current.find("local-links-manager")
7
7
 
8
- def stub_local_links_manager_has_a_link(authority_slug:, lgsl:, lgil:, url:, country_name: "England")
8
+ def stub_local_links_manager_has_a_link(authority_slug:, lgsl:, lgil:, url:, country_name: "England", status: "ok")
9
9
  response = {
10
10
  "local_authority" => {
11
11
  "name" => authority_slug.capitalize,
@@ -18,6 +18,7 @@ module GdsApi
18
18
  "lgsl_code" => lgsl,
19
19
  "lgil_code" => lgil,
20
20
  "url" => url,
21
+ "status" => status,
21
22
  },
22
23
  }
23
24
 
@@ -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
 
@@ -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.0.0".freeze
2
+ VERSION = "71.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.0.0
4
+ version: 71.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-18 00:00:00.000000000 Z
11
+ date: 2021-03-22 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
@@ -388,8 +389,6 @@ files:
388
389
  - lib/gds_api/maslow.rb
389
390
  - lib/gds_api/middleware/govuk_header_sniffer.rb
390
391
  - lib/gds_api/organisations.rb
391
- - lib/gds_api/performance_platform/data_in.rb
392
- - lib/gds_api/performance_platform/data_out.rb
393
392
  - lib/gds_api/publishing_api.rb
394
393
  - lib/gds_api/publishing_api/special_route_publisher.rb
395
394
  - lib/gds_api/railtie.rb
@@ -398,6 +397,7 @@ files:
398
397
  - lib/gds_api/search.rb
399
398
  - lib/gds_api/support.rb
400
399
  - lib/gds_api/support_api.rb
400
+ - lib/gds_api/test_helpers/account_api.rb
401
401
  - lib/gds_api/test_helpers/asset_manager.rb
402
402
  - lib/gds_api/test_helpers/calendars.rb
403
403
  - lib/gds_api/test_helpers/common_responses.rb
@@ -411,8 +411,6 @@ files:
411
411
  - lib/gds_api/test_helpers/local_links_manager.rb
412
412
  - lib/gds_api/test_helpers/mapit.rb
413
413
  - lib/gds_api/test_helpers/organisations.rb
414
- - lib/gds_api/test_helpers/performance_platform/data_in.rb
415
- - lib/gds_api/test_helpers/performance_platform/data_out.rb
416
414
  - lib/gds_api/test_helpers/publishing_api.rb
417
415
  - lib/gds_api/test_helpers/router.rb
418
416
  - lib/gds_api/test_helpers/search.rb
@@ -440,7 +438,7 @@ required_ruby_version: !ruby/object:Gem::Requirement
440
438
  requirements:
441
439
  - - ">="
442
440
  - !ruby/object:Gem::Version
443
- version: 2.4.0
441
+ version: 2.6.0
444
442
  required_rubygems_version: !ruby/object:Gem::Requirement
445
443
  requirements:
446
444
  - - ">="
@@ -1,27 +0,0 @@
1
- require_relative "../base"
2
-
3
- module GdsApi
4
- class PerformancePlatformDatasetNotConfigured < BaseError; end
5
-
6
- module PerformancePlatform
7
- class DataIn < GdsApi::Base
8
- def submit_service_feedback_day_aggregate(slug, request_details)
9
- post_json("#{endpoint}/data/#{slug}/customer-satisfaction", request_details)
10
- rescue GdsApi::HTTPNotFound
11
- raise PerformancePlatformDatasetNotConfigured, "Dataset for slug [#{slug}] not set up"
12
- end
13
-
14
- def corporate_content_problem_report_count(entries)
15
- post_json("#{endpoint}/data/gov-uk-content/feedback-count", entries)
16
- end
17
-
18
- def corporate_content_urls_with_the_most_problem_reports(entries)
19
- post_json("#{endpoint}/data/gov-uk-content/top-urls", entries)
20
- end
21
-
22
- def submit_problem_report_daily_totals(entries)
23
- post_json("#{endpoint}/data/govuk-info/page-contacts", entries)
24
- end
25
- end
26
- end
27
- end
@@ -1,131 +0,0 @@
1
- require_relative "../base"
2
-
3
- module GdsApi
4
- module PerformancePlatform
5
- class DataOut < GdsApi::Base
6
- # Fetch all service feedback from the performance platform for a given transaction
7
- # page slug.
8
- #
9
- # Makes a +GET+ request.
10
- #
11
- # The results are ordered date ascending.
12
- #
13
- # @param transaction_page_slug [String] The slug for which service feedback is
14
- # needed.
15
- #
16
- # # @example
17
- #
18
- # performance_platform_data_out.service_feedback('register-to-vote')
19
- #
20
- # #=> {
21
- # "data": [
22
- # {
23
- # "_day_start_at": "2014-06-10T00:00:00+00:00",
24
- # "_hour_start_at": "2014-06-10T00:00:00+00:00",
25
- # "_id": "20140610_register-to-vote",
26
- # "_month_start_at": "2014-06-01T00:00:00+00:00",
27
- # "_quarter_start_at": "2014-04-01T00:00:00+00:00",
28
- # "_timestamp": "2014-06-10T00:00:00+00:00",
29
- # "_updated_at": "2014-06-11T00:30:50.901000+00:00",
30
- # "_week_start_at": "2014-06-09T00:00:00+00:00",
31
- # "comments": 217,
32
- # "period": "day",
33
- # "rating_1": 4,
34
- # "rating_2": 6,
35
- # "rating_3": 7,
36
- # "rating_4": 74,
37
- # "rating_5": 574,
38
- # "slug": "register-to-vote",
39
- # "total": 665
40
- # },
41
- # ...
42
- # }
43
- def service_feedback(transaction_page_slug)
44
- get_json("#{endpoint}/data/#{transaction_page_slug}/customer-satisfaction")
45
- end
46
-
47
- # Fetching statistics data from the performance platform for a given page slug
48
- #
49
- # Makes a +GET+ request.
50
- #
51
- # @param slug [String] Points to the page for which we are requesting
52
- # statistics.
53
- # @param is_multipart [Boolean] Flag that marks whether the slug is multipart
54
- # or not:
55
- #
56
- # - simple: `/european-health-insurance-card`
57
- # - multipart: `/european-health-insurance-card/123`
58
- #
59
- # # @examples
60
- #
61
- # 1. Without multipart filtering:
62
- #
63
- # performance_platform_data_out.search_terms('/european-health-insurance-card')
64
- #
65
- # 2. With multipart filtering:
66
- #
67
- # performance_platform_data_out.searches('/european-health-insurance-card', true)
68
- # performance_platform_data_out.page_views('/european-health-insurance-card', true)
69
- # performance_platform_data_out.problem_reports('/european-health-insurance-card', true)
70
-
71
- def search_terms(slug)
72
- options = {
73
- slug: slug,
74
- transaction: "search-terms",
75
- group_by: "searchKeyword",
76
- collect: "searchUniques:sum",
77
- }
78
- statistics(options)
79
- end
80
-
81
- def searches(slug, is_multipart)
82
- options = {
83
- slug: slug,
84
- transaction: "search-terms",
85
- group_by: "pagePath",
86
- collect: "searchUniques:sum",
87
- }
88
- statistics(options, is_multipart)
89
- end
90
-
91
- def page_views(slug, is_multipart)
92
- options = {
93
- slug: slug,
94
- transaction: "page-statistics",
95
- group_by: "pagePath",
96
- collect: "uniquePageviews:sum",
97
- }
98
- statistics(options, is_multipart)
99
- end
100
-
101
- def problem_reports(slug, is_multipart)
102
- options = {
103
- slug: slug,
104
- transaction: "page-contacts",
105
- group_by: "pagePath",
106
- collect: "total:sum",
107
- }
108
- statistics(options, is_multipart)
109
- end
110
-
111
- # This can be used as a free form call to the performance platform.
112
- # The performance platform uses Backdrop and its query language for
113
- # storing and querying data.
114
- # Backdrop can be found here: https://github.com/alphagov/backdrop
115
- def statistics(options, is_multipart = false)
116
- params = {
117
- group_by: options[:group_by],
118
- collect: options[:collect],
119
- duration: 42,
120
- period: "day",
121
- end_at: Date.today.to_time.getutc.iso8601,
122
- }
123
-
124
- filter_param = is_multipart ? :filter_by_prefix : :filter_by
125
- params[filter_param] = "pagePath:" + options[:slug]
126
-
127
- get_json("#{endpoint}/data/govuk-info/#{options[:transaction]}#{query_string(params)}")
128
- end
129
- end
130
- end
131
- end
@@ -1,45 +0,0 @@
1
- module GdsApi
2
- module TestHelpers
3
- module PerformancePlatform
4
- module DataIn
5
- PP_DATA_IN_ENDPOINT = "http://www.performance.dev.gov.uk".freeze
6
-
7
- def stub_service_feedback_day_aggregate_submission(slug, request_body = nil)
8
- post_stub = stub_http_request(:post, "#{PP_DATA_IN_ENDPOINT}/data/#{slug}/customer-satisfaction")
9
- post_stub.with(body: request_body) unless request_body.nil?
10
- post_stub.to_return(status: 200)
11
- end
12
-
13
- def stub_corporate_content_problem_report_count_submission(submissions = nil)
14
- post_stub = stub_http_request(:post, "#{PP_DATA_IN_ENDPOINT}/data/gov-uk-content/feedback-count")
15
- post_stub.with(body: submissions.to_json) unless submissions.nil?
16
- post_stub.to_return(status: 200)
17
- end
18
-
19
- def stub_corporate_content_urls_with_the_most_problem_reports_submission(submissions = nil)
20
- post_stub = stub_http_request(:post, "#{PP_DATA_IN_ENDPOINT}/data/gov-uk-content/top-urls")
21
- post_stub.with(body: submissions.to_json) unless submissions.nil?
22
- post_stub.to_return(status: 200)
23
- end
24
-
25
- def stub_problem_report_daily_totals_submission(submissions = nil)
26
- post_stub = stub_http_request(:post, "#{PP_DATA_IN_ENDPOINT}/data/govuk-info/page-contacts")
27
- post_stub.with(body: submissions.to_json) unless submissions.nil?
28
- post_stub.to_return(status: 200)
29
- end
30
-
31
- def stub_service_feedback_bucket_unavailable_for(slug)
32
- stub_request(:post, "#{PP_DATA_IN_ENDPOINT}/data/#{slug}/customer-satisfaction").to_return(status: 404)
33
- end
34
-
35
- def stub_pp_isnt_available
36
- stub_request(:post, /#{PP_DATA_IN_ENDPOINT}\/.*/).to_return(status: 503)
37
- end
38
-
39
- def stub_pp_dataset_unavailable
40
- stub_request(:any, /#{PP_DATA_IN_ENDPOINT}/).to_return(status: 404)
41
- end
42
- end
43
- end
44
- end
45
- end
@@ -1,98 +0,0 @@
1
- module GdsApi
2
- module TestHelpers
3
- module PerformancePlatform
4
- module DataOut
5
- PP_DATA_OUT_ENDPOINT = "https://www.performance.service.gov.uk".freeze
6
-
7
- def stub_service_feedback(slug, response_body = {})
8
- stub_http_request(:get, "#{PP_DATA_OUT_ENDPOINT}/data/#{slug}/customer-satisfaction")
9
- .to_return(status: 200, body: response_body.to_json)
10
- end
11
-
12
- def stub_data_set_not_available(slug)
13
- stub_http_request(:get, "#{PP_DATA_OUT_ENDPOINT}/data/#{slug}/customer-satisfaction")
14
- .to_return(status: 404)
15
- end
16
-
17
- def stub_service_not_available
18
- stub_request(:any, /#{PP_DATA_OUT_ENDPOINT}\/.*/).to_return(status: 503)
19
- end
20
-
21
- def stub_search_terms(slug, response_body = {})
22
- options = {
23
- slug: slug,
24
- transaction: "search-terms",
25
- group_by: "searchKeyword",
26
- collect: "searchUniques:sum",
27
- }
28
- stub_statistics(options, false, response_body)
29
- end
30
-
31
- def stub_searches(slug, is_multipart, response_body = {})
32
- options = {
33
- slug: slug,
34
- transaction: "search-terms",
35
- group_by: "pagePath",
36
- collect: "searchUniques:sum",
37
- }
38
- stub_statistics(options, is_multipart, response_body)
39
- end
40
-
41
- def stub_page_views(slug, is_multipart, response_body = {})
42
- options = {
43
- slug: slug,
44
- transaction: "page-statistics",
45
- group_by: "pagePath",
46
- collect: "uniquePageviews:sum",
47
- }
48
- stub_statistics(options, is_multipart, response_body)
49
- end
50
-
51
- def stub_problem_reports(slug, is_multipart, response_body = {})
52
- options = {
53
- slug: slug,
54
- transaction: "page-contacts",
55
- group_by: "pagePath",
56
- collect: "total:sum",
57
- }
58
- stub_statistics(options, is_multipart, response_body)
59
- end
60
-
61
- def stub_statistics(options, is_multipart, response_body = {})
62
- params = {
63
- group_by: options[:group_by],
64
- collect: options[:collect],
65
- duration: 42,
66
- period: "day",
67
- end_at: Date.today.to_time.getutc.iso8601,
68
- }
69
-
70
- filter_param = is_multipart ? :filter_by_prefix : :filter_by
71
- params[filter_param] = "pagePath:" + options[:slug]
72
-
73
- stub_http_request(:get, "#{PP_DATA_OUT_ENDPOINT}/data/govuk-info/#{options[:transaction]}")
74
- .with(query: params)
75
- .to_return(status: 200, body: response_body.to_json)
76
- end
77
-
78
- def stub_search_404(slug)
79
- stub_request(:get, "#{PP_DATA_OUT_ENDPOINT}/data/govuk-info/search-terms")
80
- .with(query: hash_including(filter_by: slug))
81
- .to_return(status: 404, headers: { content_type: "application/json" })
82
- end
83
-
84
- def stub_page_views_404(slug)
85
- stub_request(:get, "#{PP_DATA_OUT_ENDPOINT}/data/govuk-info/page-statistics")
86
- .with(query: hash_including(filter_by: slug))
87
- .to_return(status: 404, headers: { content_type: "application/json" })
88
- end
89
-
90
- def stub_problem_reports_404(slug)
91
- stub_request(:get, "#{PP_DATA_OUT_ENDPOINT}/data/govuk-info/page-contacts")
92
- .with(query: hash_including(filter_by: slug))
93
- .to_return(status: 404, headers: { content_type: "application/json" })
94
- end
95
- end
96
- end
97
- end
98
- end