gds-api-adapters 2.9.0 → 2.10.0

Sign up to get free protection for your applications and to get access to all the features.
@@ -8,6 +8,14 @@ class GdsApi::ContentApi < GdsApi::Base
8
8
  get_json!("#{base_url}/tags.json?type=section")
9
9
  end
10
10
 
11
+ def root_sections
12
+ get_json!("#{base_url}/tags.json?type=section&root_sections=true")
13
+ end
14
+
15
+ def sub_sections(parent_tag)
16
+ get_json!("#{base_url}/tags.json?type=section&parent_id=#{CGI.escape(parent_tag)}")
17
+ end
18
+
11
19
  def tag(tag)
12
20
  get_json("#{base_url}/tags/#{CGI.escape(tag)}.json")
13
21
  end
@@ -20,6 +28,10 @@ class GdsApi::ContentApi < GdsApi::Base
20
28
  get_json("#{base_url}/with_tag.json?tag=#{CGI.escape(tag)}&sort=curated")
21
29
  end
22
30
 
31
+ def sorted_by(tag, sort_by)
32
+ get_json!("#{base_url}/with_tag.json?tag=#{CGI.escape(tag)}&sort=#{sort_by}")
33
+ end
34
+
23
35
  def artefact(slug, edition=nil)
24
36
  url = "#{base_url}/#{slug}.json"
25
37
  if edition
@@ -25,7 +25,48 @@ module GdsApi
25
25
  }
26
26
  end
27
27
  )
28
- url = "#{CONTENT_API_ENDPOINT}/tags.json?type=section"
28
+ ["#{CONTENT_API_ENDPOINT}/tags.json?type=section", "#{CONTENT_API_ENDPOINT}/tags.json?root_sections=true&type=section"].each do |url|
29
+ stub_request(:get, url).to_return(status: 200, body: body.to_json, headers: {})
30
+ end
31
+ end
32
+
33
+ def content_api_has_section(slug, parent_slug=nil)
34
+ body = tag_for_slug(slug, "section", parent_slug)
35
+ url = "#{CONTENT_API_ENDPOINT}/tags/#{CGI.escape(slug)}.json"
36
+ stub_request(:get, url).to_return(status: 200, body: body.to_json, headers: {})
37
+ end
38
+
39
+ def content_api_has_artefacts_in_a_section(slug, artefact_slugs=[])
40
+ body = plural_response_base.merge(
41
+ "results" => artefact_slugs.map do |artefact_slug|
42
+ artefact_for_slug(artefact_slug)
43
+ end
44
+ )
45
+ url = "https://contentapi.test.alphagov.co.uk/with_tag.json?sort=alphabetical&tag=#{CGI.escape(slug)}"
46
+ stub_request(:get, url).to_return(status: 200, body: body.to_json, headers: {})
47
+ end
48
+
49
+ def content_api_has_subsections(parent_slug, subsection_slugs)
50
+ parent_section = tag_for_slug(parent_slug, "section")
51
+ body = plural_response_base.merge(
52
+ "results" => subsection_slugs.map do |slug|
53
+ {
54
+ "id" => "http://contentapi.test.gov.uk/tags/#{CGI.escape(slug)}.json",
55
+ "web_url" => nil,
56
+ "title" => titleize_slug(slug),
57
+ "details" => {
58
+ "type" => "section",
59
+ "description" => "#{slug} description"
60
+ },
61
+ "parent" => parent_section,
62
+ "content_with_tag" => {
63
+ "id" => "http://contentapi.test.gov.uk/with_tag.json?tag=#{CGI.escape(slug)}",
64
+ "web_url" => "http://www.test.gov.uk/browse/#{slug}"
65
+ }
66
+ }
67
+ end
68
+ )
69
+ url = "#{CONTENT_API_ENDPOINT}/tags.json?type=section&parent_id=#{CGI.escape(parent_slug)}"
29
70
  stub_request(:get, url).to_return(status: 200, body: body.to_json, headers: {})
30
71
  end
31
72
 
@@ -140,7 +181,10 @@ module GdsApi
140
181
  artefact
141
182
  end
142
183
 
143
- def tag_for_slug(slug, tag_type)
184
+ def tag_for_slug(slug, tag_type, parent_slug=nil)
185
+ parent = if parent_slug
186
+ tag_for_slug(parent_slug, tag_type)
187
+ end
144
188
  {
145
189
  "title" => titleize_slug(slug.split('/').last),
146
190
  "id" => "https://contentapi.test.alphagov.co.uk/tags/#{CGI.escape(slug)}.json",
@@ -150,7 +194,8 @@ module GdsApi
150
194
  "content_with_tag" => {
151
195
  "id" => "https://contentapi.test.alphagov.co.uk/with_tag.json?tag=#{CGI.escape(slug)}",
152
196
  "web_url" => "https://www.test.gov.uk/browse/#{slug}",
153
- }
197
+ },
198
+ "parent" => parent
154
199
  }
155
200
  end
156
201
 
@@ -1,3 +1,3 @@
1
1
  module GdsApi
2
- VERSION = '2.9.0'
2
+ VERSION = '2.10.0'
3
3
  end
metadata CHANGED
@@ -2,7 +2,7 @@
2
2
  name: gds-api-adapters
3
3
  version: !ruby/object:Gem::Version
4
4
  prerelease:
5
- version: 2.9.0
5
+ version: 2.10.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: 2012-09-27 00:00:00 Z
13
+ date: 2012-10-01 00:00:00 Z
14
14
  dependencies:
15
15
  - !ruby/object:Gem::Dependency
16
16
  name: plek
@@ -205,7 +205,7 @@ required_ruby_version: !ruby/object:Gem::Requirement
205
205
  requirements:
206
206
  - - ">="
207
207
  - !ruby/object:Gem::Version
208
- hash: 3131893873068674307
208
+ hash: -2662590031199001168
209
209
  segments:
210
210
  - 0
211
211
  version: "0"
@@ -214,7 +214,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
214
214
  requirements:
215
215
  - - ">="
216
216
  - !ruby/object:Gem::Version
217
- hash: 3131893873068674307
217
+ hash: -2662590031199001168
218
218
  segments:
219
219
  - 0
220
220
  version: "0"