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 +4 -4
- data/lib/gds_api/account_api.rb +40 -0
- data/lib/gds_api/test_helpers/account_api.rb +125 -0
- data/lib/gds_api/version.rb +1 -1
- metadata +2 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: fb0860ace845fe7016ae87832f88f46cbf9d27a660432f3314ad4b52cf4774f9
|
4
|
+
data.tar.gz: e3ad07862f196e9e65f16a1d3ff231133c45d293cc8ac4a998c126f5d08aa680
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 8356685a336b23b4c0cb7f8abafd697cafd065be17f5508097e00d7503b6ae7aaaff5efa14a5430ed0f74121661d5df4d1614185717136a1b9e49d78e57ea369
|
7
|
+
data.tar.gz: 232183a69a8985bd6963c475ef852e2d4d28e481d9c09232bd8dbcc9f9db102d16f22df09cd99c4abef7072e1524be76d34230be9cdf99867de08f7e0cf5a4a2
|
data/lib/gds_api/account_api.rb
CHANGED
@@ -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
|
data/lib/gds_api/version.rb
CHANGED
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.
|
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-
|
11
|
+
date: 2021-05-25 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: addressable
|