gds-api-adapters 5.0.1 → 5.1.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- data/lib/gds_api/test_helpers/content_api.rb +44 -49
- data/lib/gds_api/version.rb +1 -1
- metadata +4 -4
@@ -12,34 +12,21 @@ module GdsApi
|
|
12
12
|
# Takes an array of slugs, or hashes with section details (including a slug).
|
13
13
|
# Will stub out content_api calls for tags of type section to return these sections
|
14
14
|
def content_api_has_root_sections(slugs_or_sections)
|
15
|
-
sections = slugs_or_sections.map {|s| s.is_a?(Hash) ? s : {:slug => s} }
|
16
15
|
body = plural_response_base.merge(
|
17
|
-
"results" =>
|
18
|
-
{
|
19
|
-
"id" => "#{CONTENT_API_ENDPOINT}/tags/#{CGI.escape(section[:slug])}.json",
|
20
|
-
"web_url" => nil,
|
21
|
-
"title" => section[:title] || titleize_slug(section[:slug]),
|
22
|
-
"details" => {
|
23
|
-
"type" => "section",
|
24
|
-
"description" => section[:description] || "#{section[:slug]} description",
|
25
|
-
"short_description" => section[:short_description] || "#{section[:slug]} short description",
|
26
|
-
},
|
27
|
-
"parent" => nil,
|
28
|
-
"content_with_tag" => {
|
29
|
-
"id" => "#{CONTENT_API_ENDPOINT}/with_tag.json?tag=#{CGI.escape(section[:slug])}",
|
30
|
-
"web_url" => "http://www.test.gov.uk/browse/#{section[:slug]}"
|
31
|
-
}
|
32
|
-
}
|
33
|
-
end
|
16
|
+
"results" => slugs_or_sections.map { |section| tag_result(section) }
|
34
17
|
)
|
35
|
-
["
|
18
|
+
urls = ["type=section", "root_sections=true&type=section"].map { |q|
|
19
|
+
"#{CONTENT_API_ENDPOINT}/tags.json?#{q}"
|
20
|
+
}
|
21
|
+
urls.each do |url|
|
36
22
|
stub_request(:get, url).to_return(status: 200, body: body.to_json, headers: {})
|
37
23
|
end
|
38
24
|
end
|
39
25
|
|
40
|
-
def content_api_has_section(
|
41
|
-
|
42
|
-
|
26
|
+
def content_api_has_section(slug_or_hash, parent_slug=nil)
|
27
|
+
section = tag_hash(slug_or_hash).merge(parent: parent_slug)
|
28
|
+
body = tag_result(section)
|
29
|
+
url = "#{CONTENT_API_ENDPOINT}/tags/#{CGI.escape(section[:slug])}.json"
|
43
30
|
stub_request(:get, url).to_return(status: 200, body: body.to_json, headers: {})
|
44
31
|
end
|
45
32
|
|
@@ -56,27 +43,15 @@ module GdsApi
|
|
56
43
|
end
|
57
44
|
end
|
58
45
|
|
59
|
-
def content_api_has_subsections(
|
60
|
-
parent_section =
|
46
|
+
def content_api_has_subsections(parent_slug_or_hash, subsection_slugs)
|
47
|
+
parent_section = tag_hash(parent_slug_or_hash)
|
48
|
+
subsections = subsection_slugs.map { |s|
|
49
|
+
tag_hash(s).merge(parent: parent_section)
|
50
|
+
}
|
61
51
|
body = plural_response_base.merge(
|
62
|
-
"results" =>
|
63
|
-
{
|
64
|
-
"id" => "#{CONTENT_API_ENDPOINT}/tags/#{CGI.escape(slug)}.json",
|
65
|
-
"web_url" => nil,
|
66
|
-
"title" => titleize_slug(slug),
|
67
|
-
"details" => {
|
68
|
-
"type" => "section",
|
69
|
-
"description" => "#{slug} description"
|
70
|
-
},
|
71
|
-
"parent" => parent_section,
|
72
|
-
"content_with_tag" => {
|
73
|
-
"id" => "#{CONTENT_API_ENDPOINT}/with_tag.json?tag=#{CGI.escape(slug)}",
|
74
|
-
"web_url" => "http://www.test.gov.uk/browse/#{slug}"
|
75
|
-
}
|
76
|
-
}
|
77
|
-
end
|
52
|
+
"results" => subsections.map { |s| tag_result(s) }
|
78
53
|
)
|
79
|
-
url = "#{CONTENT_API_ENDPOINT}/tags.json?type=section&parent_id=#{CGI.escape(
|
54
|
+
url = "#{CONTENT_API_ENDPOINT}/tags.json?type=section&parent_id=#{CGI.escape(parent_section[:slug])}"
|
80
55
|
stub_request(:get, url).to_return(status: 200, body: body.to_json, headers: {})
|
81
56
|
end
|
82
57
|
|
@@ -214,18 +189,38 @@ module GdsApi
|
|
214
189
|
parent = if parent_slug
|
215
190
|
tag_for_slug(parent_slug, tag_type)
|
216
191
|
end
|
192
|
+
|
193
|
+
tag_result(slug: slug, type: tag_type, parent: parent)
|
194
|
+
end
|
195
|
+
|
196
|
+
# Construct a tag hash suitable for passing into tag_result
|
197
|
+
def tag_hash(slug_or_hash)
|
198
|
+
if slug_or_hash.is_a?(Hash)
|
199
|
+
slug_or_hash
|
200
|
+
else
|
201
|
+
{ slug: slug_or_hash, type: "section" }
|
202
|
+
end
|
203
|
+
end
|
204
|
+
|
205
|
+
def tag_result(slug_or_hash)
|
206
|
+
tag = tag_hash(slug_or_hash)
|
207
|
+
|
208
|
+
parent = tag_result(tag[:parent]) if tag[:parent]
|
209
|
+
|
217
210
|
{
|
218
|
-
"
|
219
|
-
"
|
211
|
+
"id" => "#{CONTENT_API_ENDPOINT}/tags/#{CGI.escape(tag[:slug])}.json",
|
212
|
+
"web_url" => nil,
|
213
|
+
"title" => tag[:title] || titleize_slug(tag[:slug].split("/").last),
|
220
214
|
"details" => {
|
221
|
-
"type" =>
|
215
|
+
"type" => tag[:type],
|
216
|
+
"description" => tag[:description] || "#{tag[:slug]} description",
|
217
|
+
"short_description" => tag[:short_description] || "#{tag[:slug]} short description"
|
222
218
|
},
|
223
|
-
"
|
219
|
+
"parent" => parent,
|
224
220
|
"content_with_tag" => {
|
225
|
-
"id" => "#{CONTENT_API_ENDPOINT}/with_tag.json?tag=#{CGI.escape(slug)}",
|
226
|
-
"web_url" => "
|
227
|
-
}
|
228
|
-
"parent" => parent
|
221
|
+
"id" => "#{CONTENT_API_ENDPOINT}/with_tag.json?tag=#{CGI.escape(tag[:slug])}",
|
222
|
+
"web_url" => "http://www.test.gov.uk/browse/#{tag[:slug]}"
|
223
|
+
}
|
229
224
|
}
|
230
225
|
end
|
231
226
|
|
data/lib/gds_api/version.rb
CHANGED
metadata
CHANGED
@@ -2,7 +2,7 @@
|
|
2
2
|
name: gds-api-adapters
|
3
3
|
version: !ruby/object:Gem::Version
|
4
4
|
prerelease:
|
5
|
-
version: 5.0
|
5
|
+
version: 5.1.0
|
6
6
|
platform: ruby
|
7
7
|
authors:
|
8
8
|
- James Stewart
|
@@ -10,7 +10,7 @@ autorequire:
|
|
10
10
|
bindir: bin
|
11
11
|
cert_chain: []
|
12
12
|
|
13
|
-
date: 2013-02-
|
13
|
+
date: 2013-02-26 00:00:00 Z
|
14
14
|
dependencies:
|
15
15
|
- !ruby/object:Gem::Dependency
|
16
16
|
name: plek
|
@@ -245,7 +245,7 @@ required_ruby_version: !ruby/object:Gem::Requirement
|
|
245
245
|
requirements:
|
246
246
|
- - ">="
|
247
247
|
- !ruby/object:Gem::Version
|
248
|
-
hash:
|
248
|
+
hash: 3445672762986828851
|
249
249
|
segments:
|
250
250
|
- 0
|
251
251
|
version: "0"
|
@@ -254,7 +254,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
254
254
|
requirements:
|
255
255
|
- - ">="
|
256
256
|
- !ruby/object:Gem::Version
|
257
|
-
hash:
|
257
|
+
hash: 3445672762986828851
|
258
258
|
segments:
|
259
259
|
- 0
|
260
260
|
version: "0"
|