gds-api-adapters 71.1.0 → 71.2.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: 9324b0ac6cf23eff191016dbb952b2cc4507d1071a6d7d8e463ce389f1e38024
4
- data.tar.gz: d5b157159178227c69d0d724f49f10e299937c7c855c9cc5b55019d9995e17f2
3
+ metadata.gz: fb0860ace845fe7016ae87832f88f46cbf9d27a660432f3314ad4b52cf4774f9
4
+ data.tar.gz: e3ad07862f196e9e65f16a1d3ff231133c45d293cc8ac4a998c126f5d08aa680
5
5
  SHA512:
6
- metadata.gz: b24b9dec516dfbd48713c6bee798e1d4579def436e284077f89f649f3ec3dbd0fc88a3b59270c07f3d51f4e972058d6521168d571e263e037de785b4e48af9b7
7
- data.tar.gz: 37dd29babe5be2b2f11d9fc26ea2d5b3d8e9414779b3d226f6282d533ad57ea9aed10cce07ee2725109ef30885e4707aec4d9c70e7ff818572f644a390bc3ce5
6
+ metadata.gz: 8356685a336b23b4c0cb7f8abafd697cafd065be17f5508097e00d7503b6ae7aaaff5efa14a5430ed0f74121661d5df4d1614185717136a1b9e49d78e57ea369
7
+ data.tar.gz: 232183a69a8985bd6963c475ef852e2d4d28e481d9c09232bd8dbcc9f9db102d16f22df09cd99c4abef7072e1524be76d34230be9cdf99867de08f7e0cf5a4a2
@@ -96,6 +96,46 @@ class GdsApi::AccountApi < GdsApi::Base
96
96
  get_json("#{endpoint}/api/attributes/names?#{querystring}", auth_headers(govuk_account_session))
97
97
  end
98
98
 
99
+ # Look up all pages saved by a user in their Account
100
+ #
101
+ # @param [String] govuk_account_session Value of the session header
102
+ #
103
+ # @return [Hash] containing :saved_pages, an array of single saved page hashes def get_saved_pages(govuk_account_session:)
104
+ def get_saved_pages(govuk_account_session:)
105
+ get_json("#{endpoint}/api/saved_pages", auth_headers(govuk_account_session))
106
+ end
107
+
108
+ # Return a single page by unique URL
109
+ #
110
+ # @param [String] the path of a page to check
111
+ # @param [String] govuk_account_session Value of the session header
112
+ #
113
+ # @return [Hash] containing :saved_page, a hash of a single saved page value
114
+ def get_saved_page(page_path:, govuk_account_session:)
115
+ get_json("#{endpoint}/api/saved_pages/#{CGI.escape(page_path)}", auth_headers(govuk_account_session))
116
+ end
117
+
118
+ # Upsert a single saved page entry in a users account
119
+ #
120
+ # @param [String] the path of a page to check
121
+ # @param [String] govuk_account_session Value of the session header
122
+ #
123
+ # @return [Hash] A single saved page value (if sucessful)
124
+ def save_page(page_path:, govuk_account_session:)
125
+ put_json("#{endpoint}/api/saved_pages/#{CGI.escape(page_path)}", {}, auth_headers(govuk_account_session))
126
+ end
127
+
128
+ # Delete a single saved page entry from a users account
129
+ #
130
+ # @param [String] the path of a page to check
131
+ # @param [String] govuk_account_session Value of the session header
132
+ #
133
+ # @return [GdsApi::Response] A status code of 204 indicates the saved page has been successfully deleted.
134
+ # A status code of 404 indicates there is no saved page with this path.
135
+ def delete_saved_page(page_path:, govuk_account_session:)
136
+ delete_json("#{endpoint}/api/saved_pages/#{CGI.escape(page_path)}", {}, auth_headers(govuk_account_session))
137
+ end
138
+
99
139
  private
100
140
 
101
141
  def nested_query_string(params)
@@ -207,6 +207,131 @@ module GdsApi
207
207
  stub_request(method, "#{ACCOUNT_API_ENDPOINT}#{path}").with(**with).to_return(**to_return)
208
208
  end
209
209
  end
210
+
211
+ ######################
212
+ # GET /api/saved_pages
213
+ ######################
214
+ def stub_account_api_returning_saved_pages(saved_pages: [], **options)
215
+ stub_account_api_request(
216
+ :get,
217
+ "/api/saved_pages",
218
+ response_body: { saved_pages: saved_pages },
219
+ **options,
220
+ )
221
+ end
222
+
223
+ def stub_account_api_unauthorized_get_saved_pages(**options)
224
+ stub_account_api_request(
225
+ :get,
226
+ "/api/saved_pages",
227
+ response_status: 401,
228
+ **options,
229
+ )
230
+ end
231
+
232
+ #################################
233
+ # GET /api/saved_pages/:page_path
234
+ #################################
235
+ def stub_account_api_get_saved_page(page_path:, **options)
236
+ stub_account_api_request(
237
+ :get,
238
+ "/api/saved_pages/#{CGI.escape(page_path)}",
239
+ response_body: { saved_page: { page_path: page_path } },
240
+ **options,
241
+ )
242
+ end
243
+
244
+ def stub_account_api_does_not_have_saved_page(page_path:, **options)
245
+ stub_account_api_request(
246
+ :get,
247
+ "/api/saved_pages/#{CGI.escape(page_path)}",
248
+ response_status: 404,
249
+ **options,
250
+ )
251
+ end
252
+
253
+ def stub_account_api_unauthorized_get_saved_page(page_path:, **options)
254
+ stub_account_api_request(
255
+ :get,
256
+ "/api/saved_pages/#{CGI.escape(page_path)}",
257
+ response_status: 401,
258
+ **options,
259
+ )
260
+ end
261
+
262
+ #################################
263
+ # PUT /api/saved_pages/:page_path
264
+ #################################
265
+ def stub_account_api_save_page(page_path:, **options)
266
+ stub_account_api_request(
267
+ :put,
268
+ "/api/saved_pages/#{CGI.escape(page_path)}",
269
+ response_body: { saved_page: { page_path: page_path } },
270
+ **options,
271
+ )
272
+ end
273
+
274
+ def stub_account_api_save_page_already_exists(page_path:, **options)
275
+ stub_account_api_save_page(page_path: page_path, **options)
276
+ end
277
+
278
+ def stub_account_api_save_page_cannot_save_page(page_path:, **options)
279
+ stub_account_api_request(
280
+ :put,
281
+ "/api/saved_pages/#{CGI.escape(page_path)}",
282
+ response_status: 422,
283
+ response_body: { **cannot_save_page_problem_detail({ page_path: page_path }) },
284
+ **options,
285
+ )
286
+ end
287
+
288
+ def stub_account_api_unauthorized_save_page(page_path:, **options)
289
+ stub_account_api_request(
290
+ :put,
291
+ "/api/saved_pages/#{CGI.escape(page_path)}",
292
+ response_status: 401,
293
+ **options,
294
+ )
295
+ end
296
+
297
+ def cannot_save_page_problem_detail(option = {})
298
+ {
299
+ title: "Cannot save page",
300
+ detail: "Cannot save page with path #{option['page_path']}, check it is not blank, and is a well formatted url path.",
301
+ type: "https://github.com/alphagov/account-api/blob/main/docs/api.md#cannot-save-page",
302
+ **option,
303
+ }
304
+ end
305
+
306
+ ####################################
307
+ # DELETE /api/saved-pages/:page_path
308
+ ####################################
309
+ def stub_account_api_delete_saved_page(page_path:, **options)
310
+ stub_account_api_request(
311
+ :delete,
312
+ "/api/saved_pages/#{CGI.escape(page_path)}",
313
+ response_status: 204,
314
+ **options,
315
+ )
316
+ end
317
+
318
+ def stub_account_api_delete_saved_page_does_not_exist(page_path:, **options)
319
+ stub_account_api_request(
320
+ :delete,
321
+ "/api/saved_pages/#{CGI.escape(page_path)}",
322
+ response_status: 404,
323
+ **options,
324
+ )
325
+ end
326
+
327
+ def stub_account_api_delete_saved_page_unauthorised(page_path:, **options)
328
+ stub_account_api_request(
329
+ :delete,
330
+ "/api/saved_pages/#{CGI.escape(page_path)}",
331
+ response_status: 401,
332
+ **options,
333
+ )
334
+ end
210
335
  end
211
336
  end
212
337
  end
@@ -1,3 +1,3 @@
1
1
  module GdsApi
2
- VERSION = "71.1.0".freeze
2
+ VERSION = "71.2.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: 71.1.0
4
+ version: 71.2.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-05-06 00:00:00.000000000 Z
11
+ date: 2021-05-25 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: addressable