gds-api-adapters 2.11.0 → 3.0.0

Sign up to get free protection for your applications and to get access to all the features.
@@ -32,20 +32,20 @@ class GdsApi::ContentApi < GdsApi::Base
32
32
  get_json!("#{base_url}/with_tag.json?tag=#{CGI.escape(tag)}&sort=#{sort_by}")
33
33
  end
34
34
 
35
- def artefact(slug, edition=nil)
35
+ def artefact(slug, params={})
36
+ edition = params[:edition]
37
+ snac = params[:snac]
38
+
36
39
  url = "#{base_url}/#{slug}.json"
37
- if edition
38
- if options.include?(:bearer_token)
39
- url += "?edition=#{edition}"
40
- else
41
- raise GdsApi::NoBearerToken
42
- end
40
+ query = params.map { |k,v| "#{k}=#{v}" }
41
+ if query.any?
42
+ url += "?#{query.join("&")}"
43
43
  end
44
- get_json(url)
45
- end
46
44
 
47
- def artefact_with_snac_code(slug, snac)
48
- get_json("#{base_url}/#{slug}.json?snac=#{CGI.escape(snac)}")
45
+ if edition && ! options.include?(:bearer_token)
46
+ raise GdsApi::NoBearerToken
47
+ end
48
+ get_json(url)
49
49
  end
50
50
 
51
51
  def local_authority(snac_code)
@@ -1,3 +1,3 @@
1
1
  module GdsApi
2
- VERSION = '2.11.0'
2
+ VERSION = '3.0.0'
3
3
  end
@@ -29,14 +29,14 @@ describe GdsApi::ContentApi do
29
29
  it "should be able to fetch unpublished editions when authenticated" do
30
30
  api = GdsApi::ContentApi.new('test', { bearer_token: 'MY_BEARER_TOKEN' })
31
31
  content_api_has_unpublished_artefact("devolution-uk", 3)
32
- response = api.artefact("devolution-uk", 3)
32
+ response = api.artefact("devolution-uk", edition: 3)
33
33
  assert_equal "http://contentapi.test.gov.uk/devolution-uk.json", response["id"]
34
34
  end
35
35
 
36
36
  it "should raise an exception if no bearer token is used when fetching unpublished editions" do
37
37
  content_api_has_unpublished_artefact("devolution-uk", 3)
38
38
  assert_raises GdsApi::NoBearerToken do
39
- @api.artefact("devolution-uk", 3)
39
+ @api.artefact("devolution-uk", edition: 3)
40
40
  end
41
41
  end
42
42
  end
@@ -80,7 +80,7 @@ describe GdsApi::ContentApi do
80
80
  }
81
81
  }
82
82
  })
83
- response = @api.artefact_with_snac_code('licence-example', '1234')
83
+ response = @api.artefact('licence-example', snac: '1234')
84
84
 
85
85
  assert_equal "Licence Example", response["title"]
86
86
  assert_equal [ "England", "Wales" ], response["details"]["licence"]["availability"]
@@ -92,10 +92,21 @@ describe GdsApi::ContentApi do
92
92
  :body => {"test" => "ing"}.to_json,
93
93
  :headers => {})
94
94
 
95
- @api.artefact_with_snac_code("licence-example","snacks!")
95
+ @api.artefact("licence-example", snac: "snacks!")
96
96
 
97
97
  assert_requested :get, "#{@base_api_url}/licence-example.json?snac=snacks%21"
98
98
  end
99
+
100
+ it "should return an unpublished artefact with a snac code" do
101
+ body = artefact_for_slug('licence-example')
102
+ url = "#{CONTENT_API_ENDPOINT}/licence-example.json?snac=1234&edition=1"
103
+ stub_request(:get, url).to_return(status: 200, body: body.to_json)
104
+
105
+ api = GdsApi::ContentApi.new('test', { bearer_token: 'MY_BEARER_TOKEN' })
106
+ response = api.artefact('licence-example', snac: '1234', edition: '1')
107
+
108
+ assert_equal "Licence example", response["title"]
109
+ end
99
110
  end
100
111
 
101
112
  describe "local authorities" do
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.11.0
5
+ version: 3.0.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-10-02 00:00:00 Z
13
+ date: 2012-10-03 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: 1655582362177723413
208
+ hash: -4542127059758374490
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: 1655582362177723413
217
+ hash: -4542127059758374490
218
218
  segments:
219
219
  - 0
220
220
  version: "0"