gds-api-adapters 2.7.2 → 2.8.0

Sign up to get free protection for your applications and to get access to all the features.
@@ -20,8 +20,16 @@ class GdsApi::ContentApi < GdsApi::Base
20
20
  get_json("#{base_url}/with_tag.json?tag=#{CGI.escape(tag)}&sort=curated")
21
21
  end
22
22
 
23
- def artefact(slug)
24
- get_json("#{base_url}/#{slug}.json")
23
+ def artefact(slug, edition=nil)
24
+ url = "#{base_url}/#{slug}.json"
25
+ if edition
26
+ if options.include?(:bearer_token)
27
+ url += "?edition=#{edition}"
28
+ else
29
+ raise GdsApi::NoBearerToken
30
+ end
31
+ end
32
+ get_json(url)
25
33
  end
26
34
 
27
35
  def artefact_with_snac_code(slug, snac)
@@ -19,6 +19,8 @@ module GdsApi
19
19
  class HTTPNotFound < HTTPErrorResponse
20
20
  end
21
21
 
22
+ class NoBearerToken < BaseError; end
23
+
22
24
  module ExceptionHandling
23
25
  def ignoring(exception, &block)
24
26
  yield
@@ -34,6 +34,11 @@ module GdsApi
34
34
  stub_request(:get, url).to_return(status: 200, body: body.to_json, headers: {})
35
35
  end
36
36
 
37
+ def content_api_has_unpublished_artefact(slug, edition, body = artefact_for_slug(slug))
38
+ url = "#{CONTENT_API_ENDPOINT}/#{slug}.json?edition=#{edition}"
39
+ stub_request(:get, url).to_return(status: 200, body: body.to_json, headers: {})
40
+ end
41
+
37
42
  def content_api_has_an_artefact_with_snac_code(slug, snac, body = artefact_for_slug(slug))
38
43
  url = "#{CONTENT_API_ENDPOINT}/#{slug}.json?snac=#{snac}"
39
44
  stub_request(:get, url).to_return(status: 200, body: body.to_json, headers: {})
@@ -1,3 +1,3 @@
1
1
  module GdsApi
2
- VERSION = '2.7.2'
2
+ VERSION = '2.8.0'
3
3
  end
@@ -19,6 +19,28 @@ describe GdsApi::ContentApi do
19
19
  end
20
20
  end
21
21
 
22
+ describe "artefact" do
23
+ it "should show the artefact" do
24
+ content_api_has_an_artefact("devolution-uk")
25
+ response = @api.artefact("devolution-uk")
26
+ assert_equal "http://contentapi.test.gov.uk/devolution-uk.json", response["id"]
27
+ end
28
+
29
+ it "should be able to fetch unpublished editions when authenticated" do
30
+ api = GdsApi::ContentApi.new('test', { bearer_token: 'MY_BEARER_TOKEN' })
31
+ content_api_has_unpublished_artefact("devolution-uk", 3)
32
+ response = api.artefact("devolution-uk", 3)
33
+ assert_equal "http://contentapi.test.gov.uk/devolution-uk.json", response["id"]
34
+ end
35
+
36
+ it "should raise an exception if no bearer token is used when fetching unpublished editions" do
37
+ content_api_has_unpublished_artefact("devolution-uk", 3)
38
+ assert_raises GdsApi::NoBearerToken do
39
+ @api.artefact("devolution-uk", 3)
40
+ end
41
+ end
42
+ end
43
+
22
44
  describe "tags" do
23
45
  it "should produce an artefact with the provided tag" do
24
46
  tag = "crime-and-justice"
metadata CHANGED
@@ -2,7 +2,7 @@
2
2
  name: gds-api-adapters
3
3
  version: !ruby/object:Gem::Version
4
4
  prerelease:
5
- version: 2.7.2
5
+ version: 2.8.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-25 00:00:00 Z
13
+ date: 2012-09-26 00:00:00 Z
14
14
  dependencies:
15
15
  - !ruby/object:Gem::Dependency
16
16
  name: plek
@@ -205,7 +205,7 @@ required_ruby_version: !ruby/object:Gem::Requirement
205
205
  requirements:
206
206
  - - ">="
207
207
  - !ruby/object:Gem::Version
208
- hash: -333858796237205157
208
+ hash: -243511613045247910
209
209
  segments:
210
210
  - 0
211
211
  version: "0"
@@ -214,7 +214,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
214
214
  requirements:
215
215
  - - ">="
216
216
  - !ruby/object:Gem::Version
217
- hash: -333858796237205157
217
+ hash: -243511613045247910
218
218
  segments:
219
219
  - 0
220
220
  version: "0"