gds-api-adapters 11.5.0 → 11.6.0
Sign up to get free protection for your applications and to get access to all the features.
- data/lib/gds_api/content_api.rb +15 -4
- data/lib/gds_api/test_helpers/content_api.rb +22 -0
- data/lib/gds_api/version.rb +1 -1
- data/test/content_api_test.rb +16 -0
- data/test/rummager_test.rb +10 -0
- metadata +4 -4
data/lib/gds_api/content_api.rb
CHANGED
@@ -26,16 +26,27 @@ class GdsApi::ContentApi < GdsApi::Base
|
|
26
26
|
child_tags("section", parent_tag)
|
27
27
|
end
|
28
28
|
|
29
|
-
def tags(tag_type)
|
30
|
-
|
29
|
+
def tags(tag_type, options={})
|
30
|
+
params = [
|
31
|
+
"type=#{CGI.escape(tag_type)}"
|
32
|
+
]
|
33
|
+
params << "sort=#{options[:sort]}" if options.has_key?(:sort)
|
34
|
+
|
35
|
+
get_list!("#{base_url}/tags.json?#{params.join('&')}")
|
31
36
|
end
|
32
37
|
|
33
38
|
def root_tags(tag_type)
|
34
39
|
get_list!("#{base_url}/tags.json?type=#{CGI.escape(tag_type)}&root_sections=true")
|
35
40
|
end
|
36
41
|
|
37
|
-
def child_tags(tag_type, parent_tag)
|
38
|
-
|
42
|
+
def child_tags(tag_type, parent_tag, options={})
|
43
|
+
params = [
|
44
|
+
"type=#{CGI.escape(tag_type)}",
|
45
|
+
"parent_id=#{CGI.escape(parent_tag)}",
|
46
|
+
]
|
47
|
+
params << "sort=#{options[:sort]}" if options.has_key?(:sort)
|
48
|
+
|
49
|
+
get_list!("#{base_url}/tags.json?#{params.join('&')}")
|
39
50
|
end
|
40
51
|
|
41
52
|
def tag(tag, tag_type=nil)
|
@@ -80,6 +80,15 @@ module GdsApi
|
|
80
80
|
stub_request(:get, url).to_return(status: 200, body: body.to_json, headers: {})
|
81
81
|
end
|
82
82
|
|
83
|
+
def content_api_has_sorted_tags(tag_type, sort_order, slugs_or_tags)
|
84
|
+
body = plural_response_base.merge(
|
85
|
+
"results" => slugs_or_tags.map { |tag| tag_result(tag, tag_type) }
|
86
|
+
)
|
87
|
+
|
88
|
+
url = "#{CONTENT_API_ENDPOINT}/tags.json?sort=#{sort_order}&type=#{tag_type}"
|
89
|
+
stub_request(:get, url).to_return(status: 200, body: body.to_json, headers: {})
|
90
|
+
end
|
91
|
+
|
83
92
|
def content_api_has_child_tags(tag_type, parent_slug_or_hash, child_tag_ids)
|
84
93
|
parent_tag = tag_hash(parent_slug_or_hash, tag_type)
|
85
94
|
child_tags = child_tag_ids.map { |id|
|
@@ -92,6 +101,19 @@ module GdsApi
|
|
92
101
|
stub_request(:get, url).to_return(status: 200, body: body.to_json, headers: {})
|
93
102
|
end
|
94
103
|
|
104
|
+
def content_api_has_sorted_child_tags(tag_type, parent_slug_or_hash, sort_order, child_tag_ids)
|
105
|
+
parent_tag = tag_hash(parent_slug_or_hash, tag_type)
|
106
|
+
child_tags = child_tag_ids.map { |id|
|
107
|
+
tag_hash(id, tag_type).merge(parent: parent_tag)
|
108
|
+
}
|
109
|
+
body = plural_response_base.merge(
|
110
|
+
"results" => child_tags.map { |s| tag_result(s, tag_type) }
|
111
|
+
)
|
112
|
+
|
113
|
+
url = "#{CONTENT_API_ENDPOINT}/tags.json?parent_id=#{CGI.escape(parent_tag[:slug])}&sort=#{sort_order}&type=#{tag_type}"
|
114
|
+
stub_request(:get, url).to_return(status: 200, body: body.to_json, headers: {})
|
115
|
+
end
|
116
|
+
|
95
117
|
def content_api_has_artefacts_with_a_tag(tag_type, slug, artefact_slugs=[])
|
96
118
|
body = plural_response_base.merge(
|
97
119
|
"results" => artefact_slugs.map do |artefact_slug|
|
data/lib/gds_api/version.rb
CHANGED
data/test/content_api_test.rb
CHANGED
@@ -291,6 +291,14 @@ describe GdsApi::ContentApi do
|
|
291
291
|
assert_equal "#{@base_api_url}/tags/authors/justin-thyme.json", first_section.id
|
292
292
|
end
|
293
293
|
|
294
|
+
it "returns a sorted list of tags of a given type" do
|
295
|
+
content_api_has_sorted_tags("author", "alphabetical", ["justin-thyme"])
|
296
|
+
response = @api.tags("author", sort: "alphabetical")
|
297
|
+
|
298
|
+
first_section = response.first
|
299
|
+
assert_equal "#{@base_api_url}/tags/authors/justin-thyme.json", first_section.id
|
300
|
+
end
|
301
|
+
|
294
302
|
it "returns a list of root tags of a given type" do
|
295
303
|
content_api_has_root_tags("author", ["oliver-sudden", "percy-vere"])
|
296
304
|
response = @api.root_tags("author")
|
@@ -317,6 +325,14 @@ describe GdsApi::ContentApi do
|
|
317
325
|
assert_equal "#{@base_api_url}/tags/genres/indie%2Findie-rock.json", first_section.id
|
318
326
|
end
|
319
327
|
|
328
|
+
it "returns a sorted list of child tags of a given type" do
|
329
|
+
content_api_has_sorted_child_tags("genre", "indie", "alphabetical", ["indie/indie-rock"])
|
330
|
+
response = @api.child_tags("genre", "indie", sort: "alphabetical")
|
331
|
+
|
332
|
+
first_section = response.first
|
333
|
+
assert_equal "#{@base_api_url}/tags/genres/indie%2Findie-rock.json", first_section.id
|
334
|
+
end
|
335
|
+
|
320
336
|
it "returns artefacts given a section" do
|
321
337
|
content_api_has_artefacts_in_a_section("crime-and-justice", ["complain-about-a-claims-company"])
|
322
338
|
response = @api.with_tag("crime-and-justice")
|
data/test/rummager_test.rb
CHANGED
@@ -167,6 +167,16 @@ describe GdsApi::Rummager do
|
|
167
167
|
end
|
168
168
|
end
|
169
169
|
|
170
|
+
it "#unified_search should raise an exception if the service at the unified search URI returns a 422" do
|
171
|
+
stub_request(:get, /example.com\/unified_search/).to_return(
|
172
|
+
status: [422, "Bad Request"],
|
173
|
+
body: %q("error":"Filtering by \"coffee\" is not allowed"),
|
174
|
+
)
|
175
|
+
assert_raises(GdsApi::HTTPErrorResponse) do
|
176
|
+
GdsApi::Rummager.new("http://example.com").unified_search(q: "query", filter_coffee: "tea")
|
177
|
+
end
|
178
|
+
end
|
179
|
+
|
170
180
|
it "#unified_search should raise an exception if the service at the search URI times out" do
|
171
181
|
stub_request(:get, /example.com\/unified_search/).to_timeout
|
172
182
|
assert_raises(GdsApi::TimedOutException) do
|
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: gds-api-adapters
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 11.
|
4
|
+
version: 11.6.0
|
5
5
|
prerelease:
|
6
6
|
platform: ruby
|
7
7
|
authors:
|
@@ -9,7 +9,7 @@ authors:
|
|
9
9
|
autorequire:
|
10
10
|
bindir: bin
|
11
11
|
cert_chain: []
|
12
|
-
date: 2014-07-
|
12
|
+
date: 2014-07-11 00:00:00.000000000 Z
|
13
13
|
dependencies:
|
14
14
|
- !ruby/object:Gem::Dependency
|
15
15
|
name: plek
|
@@ -385,7 +385,7 @@ required_ruby_version: !ruby/object:Gem::Requirement
|
|
385
385
|
version: '0'
|
386
386
|
segments:
|
387
387
|
- 0
|
388
|
-
hash:
|
388
|
+
hash: 713806713155441280
|
389
389
|
required_rubygems_version: !ruby/object:Gem::Requirement
|
390
390
|
none: false
|
391
391
|
requirements:
|
@@ -394,7 +394,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
394
394
|
version: '0'
|
395
395
|
segments:
|
396
396
|
- 0
|
397
|
-
hash:
|
397
|
+
hash: 713806713155441280
|
398
398
|
requirements: []
|
399
399
|
rubyforge_project:
|
400
400
|
rubygems_version: 1.8.23
|