gds-api-adapters 34.1.0 → 35.0.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/content_api.rb +0 -22
- data/lib/gds_api/test_helpers/content_api.rb +0 -105
- data/lib/gds_api/test_helpers/content_item_helpers.rb +13 -0
- data/lib/gds_api/test_helpers/content_store.rb +35 -0
- data/lib/gds_api/version.rb +1 -1
- data/test/content_api_test.rb +0 -71
- data/test/content_store_test.rb +22 -0
- metadata +2 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 3de808a31aebeb02fcb1731a56452fac86864c84
|
4
|
+
data.tar.gz: 89d5c19db3a0a4c9558a2817bc01b77315fcf58f
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 0aa623216d9876b2c935af07011504a32169b1199eb071bfd68090f43de2aaa1cbde4feeaf3288bae53e9e30485076ecf7b952ae5c73d882cef6be3f589ab546
|
7
|
+
data.tar.gz: 0048a9e7a5cd71b3d832c3d1cdae804b59557b06e835ae1efe4b12133a2e503d2975fc4fd5cebf28ef1124cd827e1f81f3e7380ea6758047d8a85ca3b6d5bf21
|
data/lib/gds_api/content_api.rb
CHANGED
@@ -60,28 +60,6 @@ class GdsApi::ContentApi < GdsApi::Base
|
|
60
60
|
get_json(url)
|
61
61
|
end
|
62
62
|
|
63
|
-
def with_tag(tag, tag_type=nil, options={})
|
64
|
-
tag_key = key_for_tag_type(tag_type)
|
65
|
-
|
66
|
-
url = "#{base_url}/with_tag.json?#{tag_key}=#{CGI.escape(tag)}"
|
67
|
-
url << "&group_by=#{CGI.escape(options[:group_by])}" if options.has_key?(:group_by)
|
68
|
-
url << "&draft=true" if options[:draft]
|
69
|
-
|
70
|
-
get_list!(url)
|
71
|
-
end
|
72
|
-
|
73
|
-
def curated_list(tag, tag_type=nil)
|
74
|
-
tag_key = key_for_tag_type(tag_type)
|
75
|
-
|
76
|
-
get_list("#{base_url}/with_tag.json?#{tag_key}=#{CGI.escape(tag)}&sort=curated")
|
77
|
-
end
|
78
|
-
|
79
|
-
def sorted_by(tag, sort_by, tag_type=nil)
|
80
|
-
tag_key = key_for_tag_type(tag_type)
|
81
|
-
|
82
|
-
get_list!("#{base_url}/with_tag.json?#{tag_key}=#{CGI.escape(tag)}&sort=#{sort_by}")
|
83
|
-
end
|
84
|
-
|
85
63
|
def for_need(need_id)
|
86
64
|
get_list("#{base_url}/for_need/#{CGI.escape(need_id.to_s)}.json")
|
87
65
|
end
|
@@ -29,10 +29,6 @@ module GdsApi
|
|
29
29
|
content_api_has_child_tags("section", parent_slug_or_hash, subsection_slugs)
|
30
30
|
end
|
31
31
|
|
32
|
-
def content_api_has_artefacts_in_a_section(slug, artefact_slugs=nil)
|
33
|
-
content_api_has_artefacts_with_a_tag("section", slug, artefact_slugs)
|
34
|
-
end
|
35
|
-
|
36
32
|
def artefact_for_slug_in_a_section(slug, section_slug)
|
37
33
|
artefact_for_slug_with_a_tag("section", slug, section_slug)
|
38
34
|
end
|
@@ -41,7 +37,6 @@ module GdsApi
|
|
41
37
|
artefact_for_slug_with_a_child_tag("section", slug, subsection_slug)
|
42
38
|
end
|
43
39
|
|
44
|
-
|
45
40
|
# Takes an array of slugs, or hashes with section details (including a slug).
|
46
41
|
# Will stub out content_api calls for tags of type section to return these sections
|
47
42
|
def content_api_has_root_tags(tag_type, slugs_or_tags)
|
@@ -154,106 +149,6 @@ module GdsApi
|
|
154
149
|
stub_request(:get, url).to_return(status: 200, body: body.to_json, headers: {})
|
155
150
|
end
|
156
151
|
|
157
|
-
def content_api_has_artefacts_with_a_tag(tag_type, slug, artefact_slugs=[], options={tag: {}, artefact: {}})
|
158
|
-
if options.has_key?(:draft)
|
159
|
-
puts "Passing a key of :draft outside of the 'tag' options hash is being deprecated. Please use tag: { draft: bool }"
|
160
|
-
end
|
161
|
-
|
162
|
-
draft = options[:draft] || (options[:tag] && options[:tag][:draft])
|
163
|
-
|
164
|
-
body = plural_response_base.merge(
|
165
|
-
"results" => artefact_slugs.map do |artefact_slug|
|
166
|
-
artefact_for_slug(artefact_slug, options.fetch(:artefact, {}))
|
167
|
-
end
|
168
|
-
)
|
169
|
-
|
170
|
-
endpoint = "#{CONTENT_API_ENDPOINT}/with_tag.json"
|
171
|
-
resp = { status: 200, body: body.to_json, headers: {} }
|
172
|
-
|
173
|
-
unless draft
|
174
|
-
stub_request(:get, endpoint)
|
175
|
-
.with(:query => { tag_type => slug })
|
176
|
-
.to_return(resp)
|
177
|
-
|
178
|
-
if tag_type == "section"
|
179
|
-
stub_request(:get, endpoint)
|
180
|
-
.with(:query => { "tag" => slug })
|
181
|
-
.to_return(resp)
|
182
|
-
end
|
183
|
-
end
|
184
|
-
|
185
|
-
stub_request(:get, endpoint)
|
186
|
-
.with(:query => { tag_type => slug, "draft" => "true" })
|
187
|
-
.to_return(resp)
|
188
|
-
|
189
|
-
if tag_type == "section"
|
190
|
-
stub_request(:get, endpoint)
|
191
|
-
.with(:query => { "tag" => slug, "draft" => "true" })
|
192
|
-
.to_return(resp)
|
193
|
-
end
|
194
|
-
|
195
|
-
sort_orders = ["alphabetical", "curated"]
|
196
|
-
sort_orders.each do |order|
|
197
|
-
unless draft
|
198
|
-
stub_request(:get, endpoint)
|
199
|
-
.with(:query => { tag_type => slug, "sort" => order })
|
200
|
-
.to_return(resp)
|
201
|
-
|
202
|
-
if tag_type == "section"
|
203
|
-
stub_request(:get, endpoint)
|
204
|
-
.with(:query => { "tag" => slug, "sort" => order })
|
205
|
-
.to_return(resp)
|
206
|
-
end
|
207
|
-
end
|
208
|
-
|
209
|
-
stub_request(:get, endpoint)
|
210
|
-
.with(:query => { tag_type => slug, "sort" => order, "draft" => "true" })
|
211
|
-
.to_return(resp)
|
212
|
-
|
213
|
-
if tag_type == "section"
|
214
|
-
stub_request(:get, endpoint)
|
215
|
-
.with(:query => { "tag" => slug, "sort" => order, "draft" => "true" })
|
216
|
-
.to_return(resp)
|
217
|
-
end
|
218
|
-
end
|
219
|
-
end
|
220
|
-
|
221
|
-
def content_api_has_artefacts_with_a_draft_tag(tag_type, slug, artefact_slugs=[])
|
222
|
-
content_api_has_artefacts_with_a_tag(tag_type, slug, artefact_slugs, tag: {draft: true})
|
223
|
-
end
|
224
|
-
|
225
|
-
def content_api_has_sorted_artefacts_with_a_tag(tag_type, slug, sort_order, artefact_slugs=[])
|
226
|
-
body = plural_response_base.merge(
|
227
|
-
"results" => artefact_slugs.map do |artefact_slug|
|
228
|
-
artefact_for_slug(artefact_slug)
|
229
|
-
end
|
230
|
-
)
|
231
|
-
|
232
|
-
endpoint = "#{CONTENT_API_ENDPOINT}/with_tag.json"
|
233
|
-
stub_request(:get, endpoint)
|
234
|
-
.with(:query => { tag_type => slug, "sort" => sort_order })
|
235
|
-
.to_return(status: 200, body: body.to_json, headers: {})
|
236
|
-
end
|
237
|
-
|
238
|
-
def content_api_has_grouped_artefacts_with_a_tag(tag_type, tag_id, group_by, grouped_artefact_slugs={})
|
239
|
-
body = plural_response_base.merge(
|
240
|
-
"grouped_results" => grouped_artefact_slugs.map {|name,artefact_slugs|
|
241
|
-
{
|
242
|
-
"name" => name,
|
243
|
-
"formats" => [name.downcase],
|
244
|
-
"items" => artefact_slugs.map {|artefact_slug|
|
245
|
-
artefact_for_slug(artefact_slug)
|
246
|
-
}
|
247
|
-
}
|
248
|
-
}
|
249
|
-
)
|
250
|
-
|
251
|
-
endpoint = "#{CONTENT_API_ENDPOINT}/with_tag.json"
|
252
|
-
stub_request(:get, endpoint)
|
253
|
-
.with(:query => { tag_type => tag_id, "group_by" => group_by })
|
254
|
-
.to_return(status: 200, body: body.to_json, headers: {})
|
255
|
-
end
|
256
|
-
|
257
152
|
def content_api_has_an_artefact(slug, body = artefact_for_slug(slug))
|
258
153
|
ArtefactStub.new(slug).with_response_body(body).stub
|
259
154
|
end
|
@@ -18,6 +18,19 @@ module GdsApi
|
|
18
18
|
}
|
19
19
|
end
|
20
20
|
|
21
|
+
def gone_content_item_for_base_path(base_path)
|
22
|
+
{
|
23
|
+
"title" => nil,
|
24
|
+
"description" => nil,
|
25
|
+
"format" => "gone",
|
26
|
+
"schema_name" => "gone",
|
27
|
+
"public_updated_at" => nil,
|
28
|
+
"base_path" => base_path,
|
29
|
+
"withdrawn_notice" => {},
|
30
|
+
"details" => {}
|
31
|
+
}
|
32
|
+
end
|
33
|
+
|
21
34
|
def titleize_base_path(base_path, options = {})
|
22
35
|
if options[:title_case]
|
23
36
|
base_path.gsub("-", " ").gsub(/\b./) {|m| m.upcase }
|
@@ -43,6 +43,41 @@ module GdsApi
|
|
43
43
|
stub_request(:get, url).to_return(status: 404, headers: {})
|
44
44
|
end
|
45
45
|
|
46
|
+
# Content store has gone item
|
47
|
+
#
|
48
|
+
# Stubs a content item in the content store to respond with 410 HTTP Status Code and response body with 'format' set to 'gone'.
|
49
|
+
#
|
50
|
+
# @param base_path [String]
|
51
|
+
# @param body [Hash]
|
52
|
+
# @param options [Hash]
|
53
|
+
# @option options [String] draft Will point to the draft content store if set to true
|
54
|
+
#
|
55
|
+
# @example
|
56
|
+
#
|
57
|
+
# content_store.content_store_has_gone_item('/sample-slug')
|
58
|
+
#
|
59
|
+
# # Will return HTTP Status Code 410 and the following response body:
|
60
|
+
# {
|
61
|
+
# "title" => nil,
|
62
|
+
# "description" => nil,
|
63
|
+
# "format" => "gone",
|
64
|
+
# "schema_name" => "gone",
|
65
|
+
# "public_updated_at" => nil,
|
66
|
+
# "base_path" => "/sample-slug",
|
67
|
+
# "withdrawn_notice" => {},
|
68
|
+
# "details" => {}
|
69
|
+
# }
|
70
|
+
def content_store_has_gone_item(base_path, body = gone_content_item_for_base_path(base_path), options = {})
|
71
|
+
url = content_store_endpoint(options[:draft]) + "/content" + base_path
|
72
|
+
body = body.to_json unless body.is_a?(String)
|
73
|
+
|
74
|
+
stub_request(:get, url).to_return(
|
75
|
+
status: 410,
|
76
|
+
body: body,
|
77
|
+
headers: {}
|
78
|
+
)
|
79
|
+
end
|
80
|
+
|
46
81
|
def content_store_isnt_available
|
47
82
|
stub_request(:any, /#{content_store_endpoint}\/.*/).to_return(:status => 503)
|
48
83
|
end
|
data/lib/gds_api/version.rb
CHANGED
data/test/content_api_test.rb
CHANGED
@@ -343,25 +343,6 @@ describe GdsApi::ContentApi do
|
|
343
343
|
assert_equal "#{@base_api_url}/tags/genres/indie%2Findie-rock.json", first_section.id
|
344
344
|
end
|
345
345
|
|
346
|
-
it "returns artefacts given a section" do
|
347
|
-
content_api_has_artefacts_in_a_section("crime-and-justice", ["complain-about-a-claims-company"])
|
348
|
-
response = @api.with_tag("crime-and-justice")
|
349
|
-
|
350
|
-
# Old dictionary-style access
|
351
|
-
subsection = response["results"][0]
|
352
|
-
assert_equal "Complain about a claims company", subsection["title"]
|
353
|
-
|
354
|
-
# Attribute access
|
355
|
-
assert_equal "Complain about a claims company", response.first.title
|
356
|
-
end
|
357
|
-
|
358
|
-
it "returns artefacts given a tag and tag type" do
|
359
|
-
content_api_has_artefacts_with_a_tag("genre", "reggae", ["three-little-birds"])
|
360
|
-
response = @api.with_tag("reggae", "genre")
|
361
|
-
|
362
|
-
assert_equal "Three little birds", response.first.title
|
363
|
-
end
|
364
|
-
|
365
346
|
it "returns tag information for a section" do
|
366
347
|
content_api_has_section("crime-and-justice")
|
367
348
|
response = @api.tag("crime-and-justice", "section")
|
@@ -376,58 +357,6 @@ describe GdsApi::ContentApi do
|
|
376
357
|
assert_equal "Reggae", response['title']
|
377
358
|
end
|
378
359
|
|
379
|
-
it "returns artefacts in curated list order for a section" do
|
380
|
-
content_api_has_artefacts_in_a_section("crime-and-justice", ["complain-about-a-claims-company"])
|
381
|
-
response = @api.curated_list("crime-and-justice")
|
382
|
-
|
383
|
-
assert_equal "Complain about a claims company", response.first.title
|
384
|
-
end
|
385
|
-
|
386
|
-
it "returns artefacts in curated list order for a tag and tag type" do
|
387
|
-
content_api_has_artefacts_with_a_tag("genre", "reggae", ["buffalo-soldier"])
|
388
|
-
response = @api.curated_list("reggae", "genre")
|
389
|
-
|
390
|
-
assert_equal "Buffalo soldier", response.first.title
|
391
|
-
end
|
392
|
-
|
393
|
-
it "returns artefacts for a tag in a given sort order" do
|
394
|
-
content_api_has_artefacts_in_a_section("crime-and-justice", ["complain-about-a-claims-company"])
|
395
|
-
response = @api.sorted_by("crime-and-justice", "alphabetical")
|
396
|
-
|
397
|
-
assert_equal "Complain about a claims company", response.first.title
|
398
|
-
end
|
399
|
-
|
400
|
-
it "returns artefacts in a given sort order for a tag and tag type" do
|
401
|
-
content_api_has_sorted_artefacts_with_a_tag("genre", "reggae", "foo", ["is-this-love"])
|
402
|
-
response = @api.sorted_by("reggae", "foo", "genre")
|
403
|
-
|
404
|
-
assert_equal "Is this love", response.first.title
|
405
|
-
end
|
406
|
-
|
407
|
-
it "returns artefacts in groups for a tag and tag type" do
|
408
|
-
content_api_has_grouped_artefacts_with_a_tag(
|
409
|
-
"genre",
|
410
|
-
"reggae",
|
411
|
-
"format",
|
412
|
-
{
|
413
|
-
"Tracks" => ["is-this-love", "three-little-birds"],
|
414
|
-
"Albums" => ["kaya", "exodus"],
|
415
|
-
}
|
416
|
-
)
|
417
|
-
response = @api.with_tag("reggae", "genre", group_by: "format")
|
418
|
-
|
419
|
-
# expect two groups to be returned
|
420
|
-
assert_equal 2, response.results.size
|
421
|
-
|
422
|
-
assert_equal 2, response.results[0].items.size
|
423
|
-
assert_equal "Is this love", response.results[0].items[0].title
|
424
|
-
assert_equal "Three little birds", response.results[0].items[1].title
|
425
|
-
|
426
|
-
assert_equal 2, response.results[1].items.size
|
427
|
-
assert_equal "Kaya", response.results[1].items[0].title
|
428
|
-
assert_equal "Exodus", response.results[1].items[1].title
|
429
|
-
end
|
430
|
-
|
431
360
|
it "permits cache busting" do
|
432
361
|
content_api_has_tags("specialist_sector", ["oil-and-gas/licensing"])
|
433
362
|
|
data/test/content_store_test.rb
CHANGED
@@ -41,6 +41,28 @@ describe GdsApi::ContentStore do
|
|
41
41
|
config.always_raise_for_not_found = false
|
42
42
|
end
|
43
43
|
end
|
44
|
+
|
45
|
+
it "returns nil if the item is gone" do
|
46
|
+
content_store_has_gone_item("/it-is-gone")
|
47
|
+
|
48
|
+
assert_nil @api.content_item("/it-is-gone")
|
49
|
+
end
|
50
|
+
|
51
|
+
it "raises if the item is gone and `always_raise_for_not_found` enabled" do
|
52
|
+
GdsApi.configure do |config|
|
53
|
+
config.always_raise_for_not_found = true
|
54
|
+
end
|
55
|
+
|
56
|
+
content_store_has_gone_item("/it-is-gone")
|
57
|
+
|
58
|
+
assert_raises GdsApi::HTTPGone do
|
59
|
+
@api.content_item("/it-is-gone")
|
60
|
+
end
|
61
|
+
|
62
|
+
GdsApi.configure do |config|
|
63
|
+
config.always_raise_for_not_found = false
|
64
|
+
end
|
65
|
+
end
|
44
66
|
end
|
45
67
|
|
46
68
|
describe "#content_item!" do
|
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:
|
4
|
+
version: 35.0.0
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- James Stewart
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2016-
|
11
|
+
date: 2016-09-06 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: plek
|