gds-api-adapters 9.0.0 → 9.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/content_api.rb +5 -2
- data/lib/gds_api/list_response.rb +7 -0
- data/lib/gds_api/test_helpers/content_api.rb +19 -0
- data/lib/gds_api/version.rb +1 -1
- data/test/content_api_test.rb +24 -0
- metadata +4 -4
data/lib/gds_api/content_api.rb
CHANGED
@@ -49,10 +49,13 @@ class GdsApi::ContentApi < GdsApi::Base
|
|
49
49
|
get_json("#{url}/#{CGI.escape(tag)}.json")
|
50
50
|
end
|
51
51
|
|
52
|
-
def with_tag(tag, tag_type=nil)
|
52
|
+
def with_tag(tag, tag_type=nil, options={})
|
53
53
|
tag_key = key_for_tag_type(tag_type)
|
54
54
|
|
55
|
-
|
55
|
+
url = "#{base_url}/with_tag.json?#{tag_key}=#{CGI.escape(tag)}"
|
56
|
+
url << "&group_by=#{CGI.escape(options[:group_by])}" if options.has_key?(:group_by)
|
57
|
+
|
58
|
+
get_list!(url)
|
56
59
|
end
|
57
60
|
|
58
61
|
def curated_list(tag, tag_type=nil)
|
@@ -22,6 +22,13 @@ module GdsApi
|
|
22
22
|
# over the response directly
|
23
23
|
def_delegators :results, :each, :to_ary
|
24
24
|
|
25
|
+
def results
|
26
|
+
# support group_by results from the content api by checking if there is a
|
27
|
+
# grouped_results key present first. if it's not, then fallback to the
|
28
|
+
# results key
|
29
|
+
to_ostruct.grouped_results || to_ostruct.results
|
30
|
+
end
|
31
|
+
|
25
32
|
def has_next_page?
|
26
33
|
! page_link("next").nil?
|
27
34
|
end
|
@@ -137,6 +137,25 @@ module GdsApi
|
|
137
137
|
.to_return(status: 200, body: body.to_json, headers: {})
|
138
138
|
end
|
139
139
|
|
140
|
+
def content_api_has_grouped_artefacts_with_a_tag(tag_type, tag_id, group_by, grouped_artefact_slugs={})
|
141
|
+
body = plural_response_base.merge(
|
142
|
+
"grouped_results" => grouped_artefact_slugs.map {|name,artefact_slugs|
|
143
|
+
{
|
144
|
+
"name" => name,
|
145
|
+
"formats" => [name.downcase],
|
146
|
+
"items" => artefact_slugs.map {|artefact_slug|
|
147
|
+
artefact_for_slug(artefact_slug)
|
148
|
+
}
|
149
|
+
}
|
150
|
+
}
|
151
|
+
)
|
152
|
+
|
153
|
+
endpoint = "#{CONTENT_API_ENDPOINT}/with_tag.json"
|
154
|
+
stub_request(:get, endpoint)
|
155
|
+
.with(:query => { tag_type => tag_id, "group_by" => group_by })
|
156
|
+
.to_return(status: 200, body: body.to_json, headers: {})
|
157
|
+
end
|
158
|
+
|
140
159
|
def content_api_has_an_artefact(slug, body = artefact_for_slug(slug))
|
141
160
|
ArtefactStub.new(slug).with_response_body(body).stub
|
142
161
|
end
|
data/lib/gds_api/version.rb
CHANGED
data/test/content_api_test.rb
CHANGED
@@ -370,6 +370,30 @@ describe GdsApi::ContentApi do
|
|
370
370
|
|
371
371
|
assert_equal "Is this love", response.first.title
|
372
372
|
end
|
373
|
+
|
374
|
+
it "returns artefacts in groups for a tag and tag type" do
|
375
|
+
content_api_has_grouped_artefacts_with_a_tag(
|
376
|
+
"genre",
|
377
|
+
"reggae",
|
378
|
+
"format",
|
379
|
+
{
|
380
|
+
"Tracks" => ["is-this-love", "three-little-birds"],
|
381
|
+
"Albums" => ["kaya", "exodus"],
|
382
|
+
}
|
383
|
+
)
|
384
|
+
response = @api.with_tag("reggae", "genre", group_by: "format")
|
385
|
+
|
386
|
+
# expect two groups to be returned
|
387
|
+
assert_equal 2, response.results.size
|
388
|
+
|
389
|
+
assert_equal 2, response.results[0].items.size
|
390
|
+
assert_equal "Is this love", response.results[0].items[0].title
|
391
|
+
assert_equal "Three little birds", response.results[0].items[1].title
|
392
|
+
|
393
|
+
assert_equal 2, response.results[1].items.size
|
394
|
+
assert_equal "Kaya", response.results[1].items[0].title
|
395
|
+
assert_equal "Exodus", response.results[1].items[1].title
|
396
|
+
end
|
373
397
|
end
|
374
398
|
|
375
399
|
describe "licence" 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: 9.
|
4
|
+
version: 9.1.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-02-
|
12
|
+
date: 2014-02-24 00:00:00.000000000 Z
|
13
13
|
dependencies:
|
14
14
|
- !ruby/object:Gem::Dependency
|
15
15
|
name: plek
|
@@ -367,7 +367,7 @@ required_ruby_version: !ruby/object:Gem::Requirement
|
|
367
367
|
version: '0'
|
368
368
|
segments:
|
369
369
|
- 0
|
370
|
-
hash:
|
370
|
+
hash: 2182195135345570645
|
371
371
|
required_rubygems_version: !ruby/object:Gem::Requirement
|
372
372
|
none: false
|
373
373
|
requirements:
|
@@ -376,7 +376,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
376
376
|
version: '0'
|
377
377
|
segments:
|
378
378
|
- 0
|
379
|
-
hash:
|
379
|
+
hash: 2182195135345570645
|
380
380
|
requirements: []
|
381
381
|
rubyforge_project:
|
382
382
|
rubygems_version: 1.8.23
|