gds-api-adapters 0.0.48 → 0.0.49
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/publisher.rb +5 -0
- data/lib/gds_api/test_helpers/publisher.rb +17 -0
- data/lib/gds_api/version.rb +1 -1
- data/test/publisher_api_test.rb +25 -0
- metadata +4 -4
data/lib/gds_api/publisher.rb
CHANGED
@@ -25,6 +25,11 @@ class GdsApi::Publisher < GdsApi::Base
|
|
25
25
|
end
|
26
26
|
end
|
27
27
|
|
28
|
+
def licences_for_ids(ids)
|
29
|
+
response = get_json("#{@endpoint}/licences.json?ids=#{ids.map(&:to_s).sort.join(',')}")
|
30
|
+
response.to_ostruct
|
31
|
+
end
|
32
|
+
|
28
33
|
private
|
29
34
|
def convert_updated_date(container)
|
30
35
|
if container.updated_at && container.updated_at.class == String
|
@@ -42,6 +42,23 @@ module GdsApi
|
|
42
42
|
uri = "#{PUBLISHER_ENDPOINT}/local_transactions/#{slug}.json"
|
43
43
|
stub_request(:post, uri).to_return(:body => "", :status => 404)
|
44
44
|
end
|
45
|
+
|
46
|
+
def setup_publisher_licences_stubs
|
47
|
+
@stubbed_publisher_licences = []
|
48
|
+
stub_request(:get, %r{\A#{PUBLISHER_ENDPOINT}/licences}).to_return do |request|
|
49
|
+
if request.uri.query_values and request.uri.query_values["ids"]
|
50
|
+
ids = request.uri.query_values["ids"].split(',')
|
51
|
+
{:body => @stubbed_publisher_licences.select {|l| ids.include? l[:licence_identifier] }.to_json}
|
52
|
+
else
|
53
|
+
{:body => [].to_json}
|
54
|
+
end
|
55
|
+
end
|
56
|
+
end
|
57
|
+
|
58
|
+
def publisher_has_licence(details)
|
59
|
+
raise "Need a licence identifier" if details[:licence_identifier].nil?
|
60
|
+
@stubbed_publisher_licences << details
|
61
|
+
end
|
45
62
|
end
|
46
63
|
end
|
47
64
|
end
|
data/lib/gds_api/version.rb
CHANGED
data/test/publisher_api_test.rb
CHANGED
@@ -105,4 +105,29 @@ class GdsApi::PublisherTest < MiniTest::Unit::TestCase
|
|
105
105
|
to_return(:status => 200, :body => '{"snac": "12345"}', :headers => {})
|
106
106
|
assert_equal '12345', api.council_for_slug('fake-transaction', [12345])
|
107
107
|
end
|
108
|
+
|
109
|
+
def test_should_get_licence_details_from_publisher
|
110
|
+
setup_publisher_licences_stubs
|
111
|
+
|
112
|
+
publisher_has_licence :licence_identifier => "1234", :title => 'Test Licence 1', :slug => 'test-licence-1',
|
113
|
+
:licence_short_description => 'A short description'
|
114
|
+
publisher_has_licence :licence_identifier => "1235", :title => 'Test Licence 2', :slug => 'test-licence-2',
|
115
|
+
:licence_short_description => 'A short description'
|
116
|
+
publisher_has_licence :licence_identifier => "AB1234", :title => 'Test Licence 3', :slug => 'test-licence-3',
|
117
|
+
:licence_short_description => 'A short description'
|
118
|
+
|
119
|
+
results = api.licences_for_ids([1234, 'AB1234', 'something'])
|
120
|
+
assert_equal 2, results.size
|
121
|
+
assert_equal ['1234', 'AB1234'], results.map(&:licence_identifier)
|
122
|
+
assert_equal ['Test Licence 1', 'Test Licence 3'], results.map(&:title).sort
|
123
|
+
assert_equal ['test-licence-1', 'test-licence-3'], results.map(&:slug).sort
|
124
|
+
assert_equal 'A short description', results[0].licence_short_description
|
125
|
+
assert_equal 'A short description', results[1].licence_short_description
|
126
|
+
end
|
127
|
+
|
128
|
+
def test_should_return_empty_array_with_no_licences
|
129
|
+
setup_publisher_licences_stubs
|
130
|
+
|
131
|
+
assert_equal [], api.licences_for_ids([123,124])
|
132
|
+
end
|
108
133
|
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: 0.0.
|
5
|
+
version: 0.0.49
|
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-06-
|
13
|
+
date: 2012-06-07 00:00:00 Z
|
14
14
|
dependencies:
|
15
15
|
- !ruby/object:Gem::Dependency
|
16
16
|
name: plek
|
@@ -185,7 +185,7 @@ required_ruby_version: !ruby/object:Gem::Requirement
|
|
185
185
|
requirements:
|
186
186
|
- - ">="
|
187
187
|
- !ruby/object:Gem::Version
|
188
|
-
hash:
|
188
|
+
hash: 3231493740475825517
|
189
189
|
segments:
|
190
190
|
- 0
|
191
191
|
version: "0"
|
@@ -194,7 +194,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
194
194
|
requirements:
|
195
195
|
- - ">="
|
196
196
|
- !ruby/object:Gem::Version
|
197
|
-
hash:
|
197
|
+
hash: 3231493740475825517
|
198
198
|
segments:
|
199
199
|
- 0
|
200
200
|
version: "0"
|