gds-api-adapters 0.2.0 → 0.2.1
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 +17 -0
- data/lib/gds_api/version.rb +1 -1
- data/test/publisher_api_test.rb +46 -3
- metadata +4 -4
data/lib/gds_api/publisher.rb
CHANGED
@@ -25,6 +25,23 @@ class GdsApi::Publisher < GdsApi::Base
|
|
25
25
|
end
|
26
26
|
end
|
27
27
|
|
28
|
+
def council_for_snac_code(snac)
|
29
|
+
if json = get_json("#{@endpoint}/local_transactions/find_by_snac?snac=#{snac}")
|
30
|
+
json.to_hash
|
31
|
+
else
|
32
|
+
nil
|
33
|
+
end
|
34
|
+
end
|
35
|
+
|
36
|
+
def council_for_name(name)
|
37
|
+
name = URI.escape(name)
|
38
|
+
if json = get_json("#{@endpoint}/local_transactions/find_by_council_name?name=#{name}")
|
39
|
+
json.to_hash
|
40
|
+
else
|
41
|
+
nil
|
42
|
+
end
|
43
|
+
end
|
44
|
+
|
28
45
|
def licences_for_ids(ids)
|
29
46
|
response = get_json("#{@endpoint}/licences.json?ids=#{ids.map(&:to_s).sort.join(',')}")
|
30
47
|
if response
|
data/lib/gds_api/version.rb
CHANGED
data/test/publisher_api_test.rb
CHANGED
@@ -110,11 +110,11 @@ describe GdsApi::Publisher do
|
|
110
110
|
it "should get licence details from publisher" do
|
111
111
|
setup_publisher_licences_stubs
|
112
112
|
|
113
|
-
publisher_has_licence :licence_identifier => "1234", :title => 'Test Licence 1', :slug => 'test-licence-1',
|
113
|
+
publisher_has_licence :licence_identifier => "1234", :title => 'Test Licence 1', :slug => 'test-licence-1',
|
114
114
|
:licence_short_description => 'A short description'
|
115
|
-
publisher_has_licence :licence_identifier => "1235", :title => 'Test Licence 2', :slug => 'test-licence-2',
|
115
|
+
publisher_has_licence :licence_identifier => "1235", :title => 'Test Licence 2', :slug => 'test-licence-2',
|
116
116
|
:licence_short_description => 'A short description'
|
117
|
-
publisher_has_licence :licence_identifier => "AB1234", :title => 'Test Licence 3', :slug => 'test-licence-3',
|
117
|
+
publisher_has_licence :licence_identifier => "AB1234", :title => 'Test Licence 3', :slug => 'test-licence-3',
|
118
118
|
:licence_short_description => 'A short description'
|
119
119
|
|
120
120
|
results = api.licences_for_ids([1234, 'AB1234', 'something'])
|
@@ -138,5 +138,48 @@ describe GdsApi::Publisher do
|
|
138
138
|
|
139
139
|
assert_equal nil, api.licences_for_ids([123,124])
|
140
140
|
end
|
141
|
+
|
142
|
+
it "should return nil if a council snac code is not found" do
|
143
|
+
stub_request(:get, "#{PUBLISHER_ENDPOINT}/local_transactions/find_by_snac?snac=bloop").
|
144
|
+
with(:headers => GdsApi::JsonClient::REQUEST_HEADERS).
|
145
|
+
to_return(:status => 404, :body => " ", :headers => {})
|
146
|
+
|
147
|
+
assert_equal nil, api.council_for_snac_code("bloop")
|
148
|
+
end
|
149
|
+
|
150
|
+
it "should return a council hash for a snac code" do
|
151
|
+
stub_request(:get, "#{PUBLISHER_ENDPOINT}/local_transactions/find_by_snac?snac=AA00").
|
152
|
+
with(:headers => GdsApi::JsonClient::REQUEST_HEADERS).
|
153
|
+
to_return(:status => 200, :body => '{"name": "Some Council", "snac": "AA00"}', :headers => {})
|
154
|
+
|
155
|
+
expected = {"name" => "Some Council", "snac" => "AA00"}
|
156
|
+
assert_equal expected, api.council_for_snac_code("AA00")
|
157
|
+
end
|
158
|
+
|
159
|
+
it "should return nil if a council name is not found" do
|
160
|
+
stub_request(:get, "#{PUBLISHER_ENDPOINT}/local_transactions/find_by_council_name?name=bloop").
|
161
|
+
with(:headers => GdsApi::JsonClient::REQUEST_HEADERS).
|
162
|
+
to_return(:status => 404, :body => " ", :headers => {})
|
163
|
+
|
164
|
+
assert_equal nil, api.council_for_name("bloop")
|
165
|
+
end
|
166
|
+
|
167
|
+
it "should return a council hash for a mixed case council name" do
|
168
|
+
stub_request(:get, "#{PUBLISHER_ENDPOINT}/local_transactions/find_by_council_name?name=Some%20Council").
|
169
|
+
with(:headers => GdsApi::JsonClient::REQUEST_HEADERS).
|
170
|
+
to_return(:status => 200, :body => '{"name": "Some Council", "snac": "AA00"}', :headers => {})
|
171
|
+
|
172
|
+
expected = {"name" => "Some Council", "snac" => "AA00"}
|
173
|
+
assert_equal expected, api.council_for_name("Some Council")
|
174
|
+
end
|
175
|
+
|
176
|
+
it "should return a council hash for a lowercase council name" do
|
177
|
+
stub_request(:get, "#{PUBLISHER_ENDPOINT}/local_transactions/find_by_council_name?name=some%20council").
|
178
|
+
with(:headers => GdsApi::JsonClient::REQUEST_HEADERS).
|
179
|
+
to_return(:status => 200, :body => '{"name": "Some Council", "snac": "AA00"}', :headers => {})
|
180
|
+
|
181
|
+
expected = {"name" => "Some Council", "snac" => "AA00"}
|
182
|
+
assert_equal expected, api.council_for_name("some council")
|
183
|
+
end
|
141
184
|
end
|
142
185
|
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.2.
|
5
|
+
version: 0.2.1
|
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-07-
|
13
|
+
date: 2012-07-18 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: 548718294900661603
|
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: 548718294900661603
|
198
198
|
segments:
|
199
199
|
- 0
|
200
200
|
version: "0"
|