gds-api-adapters 1.6.0 → 1.7.0

Sign up to get free protection for your applications and to get access to all the features.
data/lib/gds_api/base.rb CHANGED
@@ -17,9 +17,9 @@ class GdsApi::Base
17
17
  end
18
18
  end
19
19
 
20
- def_delegators :client, :get_json, :get_json!,
20
+ def_delegators :client, :get_json, :get_json!,
21
21
  :post_json, :post_json!,
22
- :put_json, :put_json!,
22
+ :put_json, :put_json!,
23
23
  :delete_json!,
24
24
  :get_raw
25
25
 
@@ -8,6 +8,10 @@ class GdsApi::ContentApi < GdsApi::Base
8
8
  get_json!("#{base_url}/tags.json?type=section")
9
9
  end
10
10
 
11
+ def with_tag(tag)
12
+ get_json!("#{base_url}/with_tag.json?tag=#{tag}")
13
+ end
14
+
11
15
  private
12
16
  def base_url
13
17
  endpoint
@@ -9,7 +9,7 @@ module GdsApi
9
9
  @oauth_client = OAuth2::Client.new(nil, nil)
10
10
  @access_token = OAuth2::AccessToken.new(@oauth_client, options[:access_token], options[:token_options])
11
11
  end
12
-
12
+
13
13
  def get_json(url)
14
14
  @access_token.get(url, headers: REQUEST_HEADERS)
15
15
  end
@@ -35,7 +35,7 @@ module GdsApi
35
35
  hash
36
36
  end
37
37
 
38
- # record should respond to #slug and #title, or override #record_to_artefact
38
+ # record should respond to #slug and #title, or override #record_to_artefact
39
39
  def register(record)
40
40
  register_artefact(record_to_artefact(record))
41
41
  end
@@ -18,37 +18,30 @@ class GdsApi::Publisher < GdsApi::Base
18
18
  end
19
19
 
20
20
  def council_for_slug(slug, snac_codes)
21
- if json = post_json("#{@endpoint}/local_transactions/#{slug}/verify_snac.json", {'snac_codes' => snac_codes})
22
- json['snac']
23
- else
24
- nil
25
- end
21
+ json = post_json(
22
+ "#{@endpoint}/local_transactions/#{slug}/verify_snac.json",
23
+ {'snac_codes' => snac_codes}
24
+ )
25
+ json['snac'] if json
26
26
  end
27
27
 
28
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
29
+ json = get_json("#{@endpoint}/local_transactions/find_by_snac?snac=#{snac}")
30
+ json.to_hash if json
34
31
  end
35
32
 
36
33
  def council_for_name(name)
37
34
  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
35
+ json = get_json(
36
+ "#{@endpoint}/local_transactions/find_by_council_name?name=#{name}"
37
+ )
38
+ json.to_hash if json
43
39
  end
44
40
 
45
41
  def licences_for_ids(ids)
46
- response = get_json("#{@endpoint}/licences.json?ids=#{ids.map(&:to_s).sort.join(',')}")
47
- if response
48
- response.to_ostruct
49
- else
50
- nil
51
- end
42
+ ids = ids.map(&:to_s).sort.join(',')
43
+ response = get_json("#{@endpoint}/licences.json?ids=#{ids}")
44
+ response.to_ostruct if response
52
45
  end
53
46
 
54
47
  private
@@ -28,7 +28,7 @@ module GdsApi
28
28
  stub_request(:get, url).to_return(status: 200, body: body.to_json, headers: {})
29
29
  end
30
30
 
31
- private
31
+ private
32
32
  def response_base
33
33
  {
34
34
  "_response_info" => {
@@ -33,7 +33,7 @@ module GdsApi
33
33
  json = JSON.dump(output_details)
34
34
  slug = input_details.delete('slug')
35
35
  uri = "#{PUBLISHER_ENDPOINT}/local_transactions/#{slug}/verify_snac.json"
36
- stub_request(:post, uri).with(:body => JSON.dump(input_details),
36
+ stub_request(:post, uri).with(:body => JSON.dump(input_details),
37
37
  :headers => GdsApi::JsonClient::REQUEST_HEADERS).
38
38
  to_return(:body => json, :status => 200)
39
39
  end
@@ -1,3 +1,3 @@
1
1
  module GdsApi
2
- VERSION = '1.6.0'
2
+ VERSION = '1.7.0'
3
3
  end
@@ -15,4 +15,16 @@ class ContentApiTest < MiniTest::Unit::TestCase
15
15
  first_section = response["results"][0]
16
16
  assert_equal "http://contentapi.test.gov.uk/tags/crime.json", first_section["id"]
17
17
  end
18
+
19
+ def test_with_tag
20
+ tag = "crime-and-justice"
21
+ api_url = "https://contentapi.test.alphagov.co.uk/with_tag.json?tag=#{tag}"
22
+ json = {
23
+ results: [{title: "Complain about a claims company"}]
24
+ }.to_json
25
+ stub_request(:get, api_url).to_return(:status => 200, :body => json)
26
+ response = api.with_tag("crime-and-justice")
27
+ subsection = response["results"][0]
28
+ assert_equal "Complain about a claims company", subsection["title"]
29
+ end
18
30
  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: 1.6.0
5
+ version: 1.7.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-05 00:00:00 Z
13
+ date: 2012-09-06 00:00:00 Z
14
14
  dependencies:
15
15
  - !ruby/object:Gem::Dependency
16
16
  name: plek
@@ -154,42 +154,42 @@ extensions: []
154
154
  extra_rdoc_files: []
155
155
 
156
156
  files:
157
+ - lib/gds_api/version.rb
158
+ - lib/gds_api/publisher.rb
159
+ - lib/gds_api/panopticon/registerer.rb
160
+ - lib/gds_api/typhoeus_client.rb
157
161
  - lib/gds_api/content_api.rb
158
- - lib/gds_api/licence_application.rb
162
+ - lib/gds_api/imminence.rb
163
+ - lib/gds_api/contactotron.rb
164
+ - lib/gds_api/test_helpers/publisher.rb
159
165
  - lib/gds_api/test_helpers/content_api.rb
166
+ - lib/gds_api/test_helpers/imminence.rb
160
167
  - lib/gds_api/test_helpers/contactotron.rb
161
- - lib/gds_api/test_helpers/json_client_helper.rb
162
- - lib/gds_api/test_helpers/publisher.rb
163
168
  - lib/gds_api/test_helpers/panopticon.rb
164
- - lib/gds_api/test_helpers/imminence.rb
165
- - lib/gds_api/part_methods.rb
166
- - lib/gds_api/needotron.rb
167
- - lib/gds_api/typhoeus_client.rb
169
+ - lib/gds_api/test_helpers/json_client_helper.rb
170
+ - lib/gds_api/licence_application.rb
171
+ - lib/gds_api/base.rb
168
172
  - lib/gds_api/json_client.rb
169
- - lib/gds_api/contactotron.rb
170
- - lib/gds_api/oauth2_client.rb
171
173
  - lib/gds_api/response.rb
172
- - lib/gds_api/panopticon/registerer.rb
173
- - lib/gds_api/publisher.rb
174
- - lib/gds_api/exceptions.rb
175
- - lib/gds_api/version.rb
176
- - lib/gds_api/helpers.rb
177
- - lib/gds_api/base.rb
178
174
  - lib/gds_api/panopticon.rb
179
175
  - lib/gds_api/core-ext/openstruct.rb
180
- - lib/gds_api/imminence.rb
176
+ - lib/gds_api/oauth2_client.rb
177
+ - lib/gds_api/part_methods.rb
178
+ - lib/gds_api/needotron.rb
179
+ - lib/gds_api/exceptions.rb
180
+ - lib/gds_api/helpers.rb
181
181
  - README.md
182
182
  - Rakefile
183
- - test/imminence_api_test.rb
184
183
  - test/contactotron_api_test.rb
185
- - test/licence_application_api_test.rb
186
- - test/json_client_test.rb
184
+ - test/panopticon_api_test.rb
187
185
  - test/publisher_api_test.rb
186
+ - test/imminence_api_test.rb
188
187
  - test/panopticon_registerer_test.rb
189
- - test/panopticon_api_test.rb
190
- - test/test_helper.rb
191
- - test/gds_api_base_test.rb
192
188
  - test/content_api_test.rb
189
+ - test/json_client_test.rb
190
+ - test/gds_api_base_test.rb
191
+ - test/licence_application_api_test.rb
192
+ - test/test_helper.rb
193
193
  homepage: http://github.com/alphagov/gds-api-adapters
194
194
  licenses: []
195
195
 
@@ -203,7 +203,7 @@ required_ruby_version: !ruby/object:Gem::Requirement
203
203
  requirements:
204
204
  - - ">="
205
205
  - !ruby/object:Gem::Version
206
- hash: -3981900027952463709
206
+ hash: -2941031205011421741
207
207
  segments:
208
208
  - 0
209
209
  version: "0"
@@ -212,7 +212,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
212
212
  requirements:
213
213
  - - ">="
214
214
  - !ruby/object:Gem::Version
215
- hash: -3981900027952463709
215
+ hash: -2941031205011421741
216
216
  segments:
217
217
  - 0
218
218
  version: "0"
@@ -224,13 +224,13 @@ signing_key:
224
224
  specification_version: 3
225
225
  summary: Adapters to work with GDS APIs
226
226
  test_files:
227
- - test/imminence_api_test.rb
228
227
  - test/contactotron_api_test.rb
229
- - test/licence_application_api_test.rb
230
- - test/json_client_test.rb
228
+ - test/panopticon_api_test.rb
231
229
  - test/publisher_api_test.rb
230
+ - test/imminence_api_test.rb
232
231
  - test/panopticon_registerer_test.rb
233
- - test/panopticon_api_test.rb
234
- - test/test_helper.rb
235
- - test/gds_api_base_test.rb
236
232
  - test/content_api_test.rb
233
+ - test/json_client_test.rb
234
+ - test/gds_api_base_test.rb
235
+ - test/licence_application_api_test.rb
236
+ - test/test_helper.rb