gds-api-adapters 1.3.0 → 1.4.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/base.rb CHANGED
@@ -17,8 +17,10 @@ class GdsApi::Base
17
17
  end
18
18
  end
19
19
 
20
- def_delegators :client, :get_json, :post_json, :post_json!,
21
- :put_json, :put_json!, :delete_json!,
20
+ def_delegators :client, :get_json, :get_json!,
21
+ :post_json, :post_json!,
22
+ :put_json, :put_json!,
23
+ :delete_json!,
22
24
  :get_raw
23
25
 
24
26
  attr_reader :options
@@ -0,0 +1,15 @@
1
+ require_relative 'base'
2
+ require_relative 'exceptions'
3
+
4
+ class GdsApi::ContentApi < GdsApi::Base
5
+ include GdsApi::ExceptionHandling
6
+
7
+ def sections
8
+ get_json!("#{base_url}/tags.json?type=Section")
9
+ end
10
+
11
+ private
12
+ def base_url
13
+ endpoint
14
+ end
15
+ end
@@ -0,0 +1,55 @@
1
+ require 'gds_api/test_helpers/json_client_helper'
2
+
3
+ module GdsApi
4
+ module TestHelpers
5
+ module ContentApi
6
+ CONTENT_API_ENDPOINT = 'https://contentapi.test.alphagov.co.uk'
7
+
8
+ def content_api_has_root_sections(slugs)
9
+ body = plural_response_base.merge(
10
+ "results" => slugs.map do |slug|
11
+ {
12
+ "id" => "http://contentapi.test.gov.uk/tags/#{slug}.json",
13
+ "web_url" => "http://www.test.gov.uk/browse/#{slug}",
14
+ "title" => slug.gsub("-", " ").capitalize,
15
+ "details" => {
16
+ "type" => "section",
17
+ "description" => "#{slug} description",
18
+ "parent" => nil
19
+ }
20
+ }
21
+ end
22
+ )
23
+ url = "#{CONTENT_API_ENDPOINT}/tags.json?type=Section"
24
+ stub_request(:get, url).to_return(status: 200, body: body.to_json, headers: {})
25
+ end
26
+
27
+ private
28
+ def response_base
29
+ {
30
+ "_response_info" => {
31
+ "status" => "ok"
32
+ }
33
+ }
34
+ end
35
+
36
+ def singular_response_base
37
+ response_base
38
+ end
39
+
40
+ def plural_response_base
41
+ response_base.merge(
42
+ {
43
+ "description" => "Tags!",
44
+ "total" => 100,
45
+ "startIndex" => 1,
46
+ "pageSize" => 100,
47
+ "currentPage" => 1,
48
+ "pages" => 1,
49
+ "results" => []
50
+ }
51
+ )
52
+ end
53
+ end
54
+ end
55
+ end
@@ -1,3 +1,3 @@
1
1
  module GdsApi
2
- VERSION = '1.3.0'
2
+ VERSION = '1.4.0'
3
3
  end
@@ -0,0 +1,18 @@
1
+ require 'test_helper'
2
+ require 'gds_api/content_api'
3
+ require 'gds_api/test_helpers/content_api'
4
+
5
+ class ContentApiTest < MiniTest::Unit::TestCase
6
+ include GdsApi::TestHelpers::ContentApi
7
+
8
+ def api
9
+ GdsApi::ContentApi.new('test')
10
+ end
11
+
12
+ def test_sections
13
+ content_api_has_root_sections(["crime"])
14
+ response = api.sections
15
+ first_section = response["results"][0]
16
+ assert_equal "http://contentapi.test.gov.uk/tags/crime.json", first_section["id"]
17
+ end
18
+ 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.3.0
5
+ version: 1.4.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-08-31 00:00:00 Z
13
+ date: 2012-09-04 00:00:00 Z
14
14
  dependencies:
15
15
  - !ruby/object:Gem::Dependency
16
16
  name: plek
@@ -154,7 +154,9 @@ extensions: []
154
154
  extra_rdoc_files: []
155
155
 
156
156
  files:
157
+ - lib/gds_api/content_api.rb
157
158
  - lib/gds_api/licence_application.rb
159
+ - lib/gds_api/test_helpers/content_api.rb
158
160
  - lib/gds_api/test_helpers/contactotron.rb
159
161
  - lib/gds_api/test_helpers/json_client_helper.rb
160
162
  - lib/gds_api/test_helpers/publisher.rb
@@ -187,6 +189,7 @@ files:
187
189
  - test/panopticon_api_test.rb
188
190
  - test/test_helper.rb
189
191
  - test/gds_api_base_test.rb
192
+ - test/content_api_test.rb
190
193
  homepage: http://github.com/alphagov/gds-api-adapters
191
194
  licenses: []
192
195
 
@@ -200,7 +203,7 @@ required_ruby_version: !ruby/object:Gem::Requirement
200
203
  requirements:
201
204
  - - ">="
202
205
  - !ruby/object:Gem::Version
203
- hash: -3021938998109675237
206
+ hash: -2409433520701457667
204
207
  segments:
205
208
  - 0
206
209
  version: "0"
@@ -209,7 +212,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
209
212
  requirements:
210
213
  - - ">="
211
214
  - !ruby/object:Gem::Version
212
- hash: -3021938998109675237
215
+ hash: -2409433520701457667
213
216
  segments:
214
217
  - 0
215
218
  version: "0"
@@ -230,3 +233,4 @@ test_files:
230
233
  - test/panopticon_api_test.rb
231
234
  - test/test_helper.rb
232
235
  - test/gds_api_base_test.rb
236
+ - test/content_api_test.rb