gds-api-adapters 20.0.0 → 20.1.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/lib/gds_api/json_client.rb +8 -4
- data/lib/gds_api/test_helpers/licence_application.rb +2 -2
- data/lib/gds_api/test_helpers/publisher.rb +1 -1
- data/lib/gds_api/version.rb +1 -1
- data/test/content_api_test.rb +5 -5
- data/test/imminence_api_test.rb +3 -3
- data/test/json_client_test.rb +17 -1
- data/test/licence_application_api_test.rb +3 -3
- data/test/publisher_api_test.rb +1 -1
- metadata +2 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 8f249c43968b74233f754d973f471144e2a185a0
|
4
|
+
data.tar.gz: 182a6d9f34f93423bcb0cb41b73ee0984237234a
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: e7e46ebb41ab055a7d2081423fd660b44941cb2870b042ec57efcb3491233b1092b144ddc556a41b391f4808ebc409d0d455f00f7f44d3020008b0b4ba93c303
|
7
|
+
data.tar.gz: 894eed8cae0e2167be50334160010f00d6689b658cacb4cf70e23daf4833f9f1d0123443c0a109127ea18092cdefa8b85a4bc529e9f9ed83b277409eb0102239
|
data/lib/gds_api/json_client.rb
CHANGED
@@ -50,11 +50,15 @@ module GdsApi
|
|
50
50
|
@options = options
|
51
51
|
end
|
52
52
|
|
53
|
-
|
53
|
+
def self.default_request_headers
|
54
|
+
{
|
54
55
|
'Accept' => 'application/json',
|
55
56
|
'Content-Type' => 'application/json',
|
56
|
-
|
57
|
-
|
57
|
+
# GOVUK_APP_NAME is set for all apps by Puppet
|
58
|
+
'User-Agent' => "gds-api-adapters/#{GdsApi::VERSION} (#{ENV["GOVUK_APP_NAME"]})"
|
59
|
+
}
|
60
|
+
end
|
61
|
+
|
58
62
|
DEFAULT_TIMEOUT_IN_SECONDS = 4
|
59
63
|
DEFAULT_CACHE_SIZE = 100
|
60
64
|
DEFAULT_CACHE_TTL = 15 * 60 # 15 minutes
|
@@ -232,7 +236,7 @@ module GdsApi
|
|
232
236
|
method_params = {
|
233
237
|
method: method,
|
234
238
|
url: url,
|
235
|
-
headers:
|
239
|
+
headers: self.class.default_request_headers
|
236
240
|
}
|
237
241
|
method_params[:payload] = params
|
238
242
|
method_params = with_auth_options(method_params)
|
@@ -10,14 +10,14 @@ module GdsApi
|
|
10
10
|
def licence_exists(identifier, licence)
|
11
11
|
licence = licence.to_json unless licence.is_a?(String)
|
12
12
|
stub_request(:get, "#{LICENCE_APPLICATION_ENDPOINT}/api/licence/#{identifier}").
|
13
|
-
with(headers: GdsApi::JsonClient
|
13
|
+
with(headers: GdsApi::JsonClient.default_request_headers).
|
14
14
|
to_return(status: 200,
|
15
15
|
body: licence)
|
16
16
|
end
|
17
17
|
|
18
18
|
def licence_does_not_exist(identifier)
|
19
19
|
stub_request(:get, "#{LICENCE_APPLICATION_ENDPOINT}/api/licence/#{identifier}").
|
20
|
-
with(headers: GdsApi::JsonClient
|
20
|
+
with(headers: GdsApi::JsonClient.default_request_headers).
|
21
21
|
to_return(status: 404,
|
22
22
|
body: "{\"error\": [\"Unrecognised Licence Id: #{identifier}\"]}")
|
23
23
|
end
|
@@ -47,7 +47,7 @@ module GdsApi
|
|
47
47
|
slug = input_details.delete('slug')
|
48
48
|
uri = "#{PUBLISHER_ENDPOINT}/local_transactions/#{slug}/verify_snac.json"
|
49
49
|
stub_request(:post, uri).with(:body => JSON.dump(input_details),
|
50
|
-
:headers => GdsApi::JsonClient
|
50
|
+
:headers => GdsApi::JsonClient.default_request_headers).
|
51
51
|
to_return(:body => json, :status => 200)
|
52
52
|
end
|
53
53
|
|
data/lib/gds_api/version.rb
CHANGED
data/test/content_api_test.rb
CHANGED
@@ -484,7 +484,7 @@ describe GdsApi::ContentApi do
|
|
484
484
|
describe "local authorities" do
|
485
485
|
it "should return nil if no local authority found" do
|
486
486
|
stub_request(:get, "#{@base_api_url}/local_authorities/does-not-exist.json").
|
487
|
-
with(:headers => GdsApi::JsonClient
|
487
|
+
with(:headers => GdsApi::JsonClient.default_request_headers).
|
488
488
|
to_return(:status => 404,
|
489
489
|
:body => {"_response_info" => {"status" => "ok"}}.to_json,
|
490
490
|
:headers => {})
|
@@ -501,7 +501,7 @@ describe GdsApi::ContentApi do
|
|
501
501
|
}
|
502
502
|
|
503
503
|
stub_request(:get, "#{@base_api_url}/local_authorities/00CT.json").
|
504
|
-
with(:headers => GdsApi::JsonClient
|
504
|
+
with(:headers => GdsApi::JsonClient.default_request_headers).
|
505
505
|
to_return(:status => 200,
|
506
506
|
:body => body_response.to_json,
|
507
507
|
:headers => {})
|
@@ -520,7 +520,7 @@ describe GdsApi::ContentApi do
|
|
520
520
|
}.to_json
|
521
521
|
|
522
522
|
stub_request(:get, "#{@base_api_url}/local_authorities.json?name=Swansalona").
|
523
|
-
with(:headers => GdsApi::JsonClient
|
523
|
+
with(:headers => GdsApi::JsonClient.default_request_headers).
|
524
524
|
to_return(:status => 200,
|
525
525
|
:body => body_response,
|
526
526
|
:headers => {})
|
@@ -540,7 +540,7 @@ describe GdsApi::ContentApi do
|
|
540
540
|
}.to_json
|
541
541
|
|
542
542
|
stub_request(:get, "#{@base_api_url}/local_authorities.json?snac_code=SNACKS").
|
543
|
-
with(:headers => GdsApi::JsonClient
|
543
|
+
with(:headers => GdsApi::JsonClient.default_request_headers).
|
544
544
|
to_return(:status => 200,
|
545
545
|
:body => body_response,
|
546
546
|
:headers => {})
|
@@ -569,7 +569,7 @@ describe GdsApi::ContentApi do
|
|
569
569
|
}.to_json
|
570
570
|
|
571
571
|
stub_request(:get, "#{@base_api_url}/local_authorities.json?name=Swans").
|
572
|
-
with(:headers => GdsApi::JsonClient
|
572
|
+
with(:headers => GdsApi::JsonClient.default_request_headers).
|
573
573
|
to_return(:status => 200,
|
574
574
|
:body => body_response,
|
575
575
|
:headers => {})
|
data/test/imminence_api_test.rb
CHANGED
@@ -157,7 +157,7 @@ class ImminenceApiTest < MiniTest::Unit::TestCase
|
|
157
157
|
EOS
|
158
158
|
|
159
159
|
stub_request(:get, "#{ROOT}/places/test.kml").
|
160
|
-
with(headers: GdsApi::JsonClient
|
160
|
+
with(headers: GdsApi::JsonClient.default_request_headers).
|
161
161
|
to_return(status: 200, body: kml_body )
|
162
162
|
|
163
163
|
response_body = api_client.places_kml("test")
|
@@ -176,7 +176,7 @@ EOS
|
|
176
176
|
}
|
177
177
|
|
178
178
|
stub_request(:get, "#{ROOT}/areas/WC2B%206SE.json").
|
179
|
-
with(headers: GdsApi::JsonClient
|
179
|
+
with(headers: GdsApi::JsonClient.default_request_headers).
|
180
180
|
to_return(status: 200, body: results.to_json )
|
181
181
|
|
182
182
|
response = api_client.areas_for_postcode("WC2B 6SE")
|
@@ -200,7 +200,7 @@ EOS
|
|
200
200
|
}
|
201
201
|
|
202
202
|
stub_request(:get, "#{ROOT}/areas/EUR.json").
|
203
|
-
with(headers: GdsApi::JsonClient
|
203
|
+
with(headers: GdsApi::JsonClient.default_request_headers).
|
204
204
|
to_return(status: 200, body: results.to_json )
|
205
205
|
|
206
206
|
response = api_client.areas_for_type("EUR")
|
data/test/json_client_test.rb
CHANGED
@@ -625,7 +625,7 @@ class JsonClientTest < MiniTest::Spec
|
|
625
625
|
|
626
626
|
def test_client_can_use_bearer_token
|
627
627
|
client = GdsApi::JsonClient.new(bearer_token: 'SOME_BEARER_TOKEN')
|
628
|
-
expected_headers = GdsApi::JsonClient
|
628
|
+
expected_headers = GdsApi::JsonClient.default_request_headers.
|
629
629
|
merge('Authorization' => 'Bearer SOME_BEARER_TOKEN')
|
630
630
|
|
631
631
|
stub_request(:put, "http://some.other.endpoint/some.json").
|
@@ -789,4 +789,20 @@ class JsonClientTest < MiniTest::Spec
|
|
789
789
|
GdsApi::JsonClient.new(:timeout => -1)
|
790
790
|
end
|
791
791
|
end
|
792
|
+
|
793
|
+
def test_should_add_user_agent_using_env
|
794
|
+
previous_govuk_app_name = ENV['GOVUK_APP_NAME']
|
795
|
+
ENV['GOVUK_APP_NAME'] = "api-tests"
|
796
|
+
|
797
|
+
url = "http://some.other.endpoint/some.json"
|
798
|
+
stub_request(:get, url).to_return(:status => 200)
|
799
|
+
|
800
|
+
GdsApi::JsonClient.new.get_json(url)
|
801
|
+
|
802
|
+
assert_requested(:get, %r{/some.json}) do |request|
|
803
|
+
request.headers["User-Agent"] == "gds-api-adapters/#{GdsApi::VERSION} (api-tests)"
|
804
|
+
end
|
805
|
+
ensure
|
806
|
+
ENV['GOVUK_APP_NAME'] = previous_govuk_app_name
|
807
|
+
end
|
792
808
|
end
|
@@ -19,7 +19,7 @@ class LicenceApplicationApiTest < MiniTest::Unit::TestCase
|
|
19
19
|
|
20
20
|
def test_should_return_list_of_licences
|
21
21
|
stub_request(:get, "#{@core_url}/api/licences").
|
22
|
-
with(headers: GdsApi::JsonClient
|
22
|
+
with(headers: GdsApi::JsonClient.default_request_headers).
|
23
23
|
to_return(:status => 200,
|
24
24
|
:body => <<-EOS
|
25
25
|
[
|
@@ -59,7 +59,7 @@ EOS
|
|
59
59
|
|
60
60
|
def test_should_return_error_message_if_licences_collection_not_found
|
61
61
|
stub_request(:get, "#{@core_url}/api/licences").
|
62
|
-
with(headers: GdsApi::JsonClient
|
62
|
+
with(headers: GdsApi::JsonClient.default_request_headers).
|
63
63
|
to_return(status: 404,
|
64
64
|
body: "{\"error\": \"Error\"}")
|
65
65
|
|
@@ -104,7 +104,7 @@ EOS
|
|
104
104
|
|
105
105
|
def test_should_return_error_message_to_pick_a_relevant_snac_code_for_the_provided_licence_id
|
106
106
|
stub_request(:get, "#{@core_url}/api/licence/590001/sw10").
|
107
|
-
with(headers: GdsApi::JsonClient
|
107
|
+
with(headers: GdsApi::JsonClient.default_request_headers).
|
108
108
|
to_return(status: 404,
|
109
109
|
body: "{\"error\": \"No authorities found for the licence 590001 and for the snacCode sw10\"}")
|
110
110
|
|
data/test/publisher_api_test.rb
CHANGED
@@ -102,7 +102,7 @@ describe GdsApi::Publisher do
|
|
102
102
|
|
103
103
|
it "should be able to retrieve local transaction details" do
|
104
104
|
stub_request(:post, "#{PUBLISHER_ENDPOINT}/local_transactions/fake-transaction/verify_snac.json").
|
105
|
-
with(:body => "{\"snac_codes\":[12345]}", :headers => GdsApi::JsonClient
|
105
|
+
with(:body => "{\"snac_codes\":[12345]}", :headers => GdsApi::JsonClient.default_request_headers).
|
106
106
|
to_return(:status => 200, :body => '{"snac": "12345"}', :headers => {})
|
107
107
|
assert_equal '12345', api.council_for_slug('fake-transaction', [12345])
|
108
108
|
end
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: gds-api-adapters
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 20.
|
4
|
+
version: 20.1.0
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- James Stewart
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2015-
|
11
|
+
date: 2015-07-02 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: plek
|