gds-api-adapters 0.0.13 → 0.0.14

Sign up to get free protection for your applications and to get access to all the features.
@@ -6,7 +6,7 @@ class GdsApi::Base
6
6
  include GdsApi::JsonUtils
7
7
 
8
8
  attr_reader :options
9
-
9
+
10
10
  class << self
11
11
  attr_writer :logger
12
12
  end
@@ -28,7 +28,7 @@ class GdsApi::Base
28
28
  def adapter_name
29
29
  self.class.to_s.split("::").last.downcase
30
30
  end
31
-
31
+
32
32
  def url_for_slug(slug, options={})
33
33
  base = "#{base_url}/#{slug}.json#{query_string(options)}"
34
34
  end
@@ -41,7 +41,7 @@ private
41
41
  if platform == 'development'
42
42
  "http://#{adapter_name}.dev.gov.uk"
43
43
  else
44
- "http://#{adapter_name}.#{platform}.alphagov.co.uk"
44
+ "https://#{adapter_name}.#{platform}.alphagov.co.uk"
45
45
  end
46
46
  end
47
47
 
@@ -1,4 +1,4 @@
1
1
  module GdsApi
2
2
  class EndpointNotFound < StandardError
3
3
  end
4
- end
4
+ end
@@ -15,7 +15,7 @@ module GdsApi
15
15
  def panopticon_api
16
16
  @panopticon_api ||= GdsApi::Panopticon.new(Plek.current.environment)
17
17
  end
18
-
18
+
19
19
  def fetch_artefact(params)
20
20
  panopticon_api.artefact_for_slug(params[:slug]) || OpenStruct.new(section: 'missing', need_id: 'missing', kind: 'missing')
21
21
  end
@@ -7,7 +7,7 @@ require_relative 'exceptions'
7
7
 
8
8
  module GdsApi::JsonUtils
9
9
  REQUEST_HEADERS = {
10
- 'Accept' => 'application/json',
10
+ 'Accept' => 'application/json',
11
11
  'Content-Type' => 'application/json',
12
12
  'User-Agent' => "GDS Api Client v. #{GdsApi::VERSION}"
13
13
  }
@@ -69,7 +69,7 @@ module GdsApi::JsonUtils
69
69
  http.put(path, params.to_json, REQUEST_HEADERS)
70
70
  end
71
71
  end
72
-
72
+
73
73
  def to_ostruct(object)
74
74
  case object
75
75
  when Hash
@@ -4,14 +4,14 @@ class GdsApi::Needotron < GdsApi::Base
4
4
  def need_by_id(id, opts = {})
5
5
  need_hash = get_json("#{base_url}/#{id}.json")
6
6
  return nil if need_hash.nil? or need_hash['need'].nil?
7
-
7
+
8
8
  if opts[:as_hash]
9
9
  need_hash
10
10
  else
11
- to_ostruct(need_hash['need'])
11
+ to_ostruct(need_hash['need'])
12
12
  end
13
13
  end
14
-
14
+
15
15
  private
16
16
  def base_url
17
17
  "#{@endpoint}/needs"
@@ -4,23 +4,23 @@ class GdsApi::Panopticon < GdsApi::Base
4
4
 
5
5
  def artefact_for_slug(slug, opts = {})
6
6
  return nil if slug.nil? or slug == ''
7
-
7
+
8
8
  details = get_json(url_for_slug(slug))
9
9
  if opts[:as_hash]
10
10
  details
11
11
  else
12
- to_ostruct(details)
12
+ to_ostruct(details)
13
13
  end
14
14
  end
15
15
 
16
16
  def create_artefact(artefact)
17
17
  post_json(base_url + ".json", artefact)
18
18
  end
19
-
19
+
20
20
  def update_artefact(id_or_slug, artefact)
21
21
  put_json("#{base_url}/#{id_or_slug}.json", artefact)
22
22
  end
23
-
23
+
24
24
  private
25
25
  def base_url
26
26
  "#{endpoint}/artefacts"
@@ -1,7 +1,7 @@
1
1
  module GdsApi
2
2
  module TestHelpers
3
3
  module Contactotron
4
-
4
+
5
5
  def contactotron_has_contact(uri, details)
6
6
  json = JSON.dump(details)
7
7
  stub_request(:get, uri).to_return(:status => 200, :body => json, :headers => {})
@@ -2,23 +2,23 @@ module GdsApi
2
2
  module TestHelpers
3
3
  module Panopticon
4
4
  PANOPTICON_ENDPOINT = 'http://panopticon.test.alphagov.co.uk'
5
-
5
+
6
6
  def stringify_hash_keys(input_hash)
7
7
  input_hash.inject({}) do |options, (key, value)|
8
8
  options[key.to_s] = value
9
9
  options
10
10
  end
11
11
  end
12
-
12
+
13
13
  def panopticon_has_metadata(metadata)
14
14
  metadata = stringify_hash_keys(metadata)
15
-
15
+
16
16
  json = JSON.dump(metadata)
17
17
 
18
18
  urls = []
19
19
  urls << "#{PANOPTICON_ENDPOINT}/artefacts/#{metadata['id']}.json" if metadata['id']
20
20
  urls << "#{PANOPTICON_ENDPOINT}/artefacts/#{metadata['slug']}.json" if metadata['slug']
21
-
21
+
22
22
  urls.each { |url| stub_request(:get, url).to_return(:status => 200, :body => json, :headers => {}) }
23
23
 
24
24
  return urls.first
@@ -29,7 +29,7 @@ module GdsApi
29
29
  json = JSON.dump(output_details)
30
30
  slug = input_details.delete('slug')
31
31
  uri = "#{PUBLISHER_ENDPOINT}/local_transactions/#{slug}/verify_snac.json"
32
- stub_request(:post, uri).with(:body => JSON.dump(input_details),
32
+ stub_request(:post, uri).with(:body => JSON.dump(input_details),
33
33
  :headers => GdsApi::JsonUtils::REQUEST_HEADERS).
34
34
  to_return(:body => json, :status => 200)
35
35
  end
@@ -1,3 +1,3 @@
1
1
  module GdsApi
2
- VERSION = '0.0.13'
2
+ VERSION = '0.0.14'
3
3
  end
@@ -4,13 +4,13 @@ require 'gds_api/test_helpers/contactotron'
4
4
 
5
5
  class ContactotronApiTest < MiniTest::Unit::TestCase
6
6
  include GdsApi::TestHelpers::Contactotron
7
-
7
+
8
8
  def api
9
9
  GdsApi::Contactotron.new "test"
10
10
  end
11
11
 
12
12
  def test_should_fetch_and_parse_JSON_into_ostruct
13
- uri = "http://contactotron.platform/contacts/1"
13
+ uri = "http://contactotron.platform/contacts/1"
14
14
  contactotron_has_contact(uri, {details: 'value'})
15
15
  assert_equal OpenStruct, api.contact_for_uri(uri).class
16
16
  end
@@ -54,12 +54,12 @@ class GdsApiBaseTest < MiniTest::Unit::TestCase
54
54
  u = URI.parse(url)
55
55
  assert_match /^concreteapi\.test/, u.host
56
56
  end
57
-
57
+
58
58
  def test_should_treat_second_positional_arg_as_endpoint_url_if_string
59
59
  api = ConcreteApi.new("test", "endpoint")
60
60
  assert_equal "endpoint", api.options[:endpoint_url]
61
61
  end
62
-
62
+
63
63
  def test_should_accept_options_as_second_arg
64
64
  api = ConcreteApi.new("test", {endpoint_url: "endpoint", foo: "bar"})
65
65
  assert_equal "endpoint", api.options[:endpoint_url]
@@ -47,7 +47,7 @@ class JsonUtilsTest < MiniTest::Unit::TestCase
47
47
  stub_request(:post, url).to_raise(Timeout::Error)
48
48
  assert_nil post_json(url, {})
49
49
  end
50
-
50
+
51
51
  def test_should_fetch_and_parse_json_into_hash
52
52
  url = "http://some.endpoint/some.json"
53
53
  stub_request(:get, url).to_return(:body => "{}",:status => 200)
@@ -59,11 +59,11 @@ class JsonUtilsTest < MiniTest::Unit::TestCase
59
59
  stub_request(:get, url).to_return(:body => "{}", :status => 404)
60
60
  assert_nil get_json(url)
61
61
  end
62
-
62
+
63
63
  def test_put_json_does_put_with_json_encoded_packet
64
64
  url = "http://some.endpoint/some.json"
65
65
  payload = {a:1}
66
66
  stub_request(:put, url).with(body: payload.to_json).to_return(:body => "{}", :status => 200)
67
67
  assert_equal({}, put_json(url, payload))
68
68
  end
69
- end
69
+ end
@@ -7,7 +7,7 @@ class PanopticonApiTest < MiniTest::Unit::TestCase
7
7
 
8
8
  def basic_artefact
9
9
  {
10
- name: 'An artefact',
10
+ name: 'An artefact',
11
11
  slug: 'a-basic-artefact'
12
12
  }
13
13
  end
@@ -29,35 +29,35 @@ class PanopticonApiTest < MiniTest::Unit::TestCase
29
29
 
30
30
  def test_given_a_slug__should_fetch_artefact_from_panopticon
31
31
  panopticon_has_metadata(basic_artefact)
32
-
32
+
33
33
  artefact = api.artefact_for_slug(basic_artefact[:slug])
34
34
  assert_equal 'An artefact', artefact.name
35
35
  end
36
-
36
+
37
37
  def test_given_a_slug_can_fetch_artefact_as_hash
38
38
  panopticon_has_metadata(basic_artefact)
39
39
  artefact = api.artefact_for_slug(basic_artefact[:slug], :as_hash => true)
40
40
  assert artefact.is_a?(Hash)
41
41
  end
42
-
42
+
43
43
  def should_fetch_and_parse_JSON_into_hash
44
44
  url = "#{PANOPTICON_ENDPOINT}/some.json"
45
45
  stub_request(:get, url).to_return(body: {}.to_json)
46
-
46
+
47
47
  assert_equal Hash, api.get_json(url).class
48
48
  end
49
-
49
+
50
50
  def test_should_return_nil_if_404_returned_from_endpoint
51
51
  url = "#{PANOPTICON_ENDPOINT}/some.json"
52
52
  stub_request(:get, url).to_return(status: Rack::Utils.status_code(:not_found))
53
-
53
+
54
54
  assert_nil api.get_json(url)
55
55
  end
56
-
56
+
57
57
  def test_should_construct_correct_url_for_a_slug
58
58
  assert_equal "#{PANOPTICON_ENDPOINT}/artefacts/slug.json", api.url_for_slug('slug')
59
59
  end
60
-
60
+
61
61
  def test_contacts_should_be_deserialised_into_whole_objects
62
62
  panopticon_has_metadata(artefact_with_contact)
63
63
 
@@ -65,22 +65,22 @@ class PanopticonApiTest < MiniTest::Unit::TestCase
65
65
  assert_equal 'Department for Environment, Food and Rural Affairs (Defra)', artefact.contact.name
66
66
  assert_equal 'helpline@defra.gsi.gov.uk', artefact.contact.email_address
67
67
  end
68
-
68
+
69
69
  def test_can_create_a_new_artefact
70
70
  url = "#{PANOPTICON_ENDPOINT}/artefacts.json"
71
71
  stub_request(:post, url)
72
72
  .with(body: basic_artefact.to_json)
73
73
  .to_return(body: basic_artefact.merge(id: 1).to_json)
74
-
74
+
75
75
  api.create_artefact(basic_artefact)
76
76
  end
77
-
77
+
78
78
  def test_can_update_existing_artefact
79
79
  url = "#{PANOPTICON_ENDPOINT}/artefacts/1.json"
80
80
  stub_request(:put, url)
81
81
  .with(body: basic_artefact.to_json)
82
82
  .to_return(status: 200, body: '{}')
83
-
83
+
84
84
  api.update_artefact(1, basic_artefact)
85
85
  end
86
86
  end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: gds-api-adapters
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.0.13
4
+ version: 0.0.14
5
5
  prerelease:
6
6
  platform: ruby
7
7
  authors:
@@ -9,11 +9,11 @@ authors:
9
9
  autorequire:
10
10
  bindir: bin
11
11
  cert_chain: []
12
- date: 2011-12-21 00:00:00.000000000Z
12
+ date: 2011-12-29 00:00:00.000000000Z
13
13
  dependencies:
14
14
  - !ruby/object:Gem::Dependency
15
15
  name: plek
16
- requirement: &70165614975140 !ruby/object:Gem::Requirement
16
+ requirement: &70288970799060 !ruby/object:Gem::Requirement
17
17
  none: false
18
18
  requirements:
19
19
  - - ! '>='
@@ -21,10 +21,10 @@ dependencies:
21
21
  version: '0'
22
22
  type: :runtime
23
23
  prerelease: false
24
- version_requirements: *70165614975140
24
+ version_requirements: *70288970799060
25
25
  - !ruby/object:Gem::Dependency
26
26
  name: null_logger
27
- requirement: &70165614974680 !ruby/object:Gem::Requirement
27
+ requirement: &70288970797800 !ruby/object:Gem::Requirement
28
28
  none: false
29
29
  requirements:
30
30
  - - ! '>='
@@ -32,10 +32,10 @@ dependencies:
32
32
  version: '0'
33
33
  type: :runtime
34
34
  prerelease: false
35
- version_requirements: *70165614974680
35
+ version_requirements: *70288970797800
36
36
  - !ruby/object:Gem::Dependency
37
37
  name: rake
38
- requirement: &70165614974160 !ruby/object:Gem::Requirement
38
+ requirement: &70288970795860 !ruby/object:Gem::Requirement
39
39
  none: false
40
40
  requirements:
41
41
  - - ~>
@@ -43,10 +43,10 @@ dependencies:
43
43
  version: 0.9.2.2
44
44
  type: :development
45
45
  prerelease: false
46
- version_requirements: *70165614974160
46
+ version_requirements: *70288970795860
47
47
  - !ruby/object:Gem::Dependency
48
48
  name: webmock
49
- requirement: &70165614973620 !ruby/object:Gem::Requirement
49
+ requirement: &70288970794880 !ruby/object:Gem::Requirement
50
50
  none: false
51
51
  requirements:
52
52
  - - ~>
@@ -54,10 +54,10 @@ dependencies:
54
54
  version: '1.7'
55
55
  type: :development
56
56
  prerelease: false
57
- version_requirements: *70165614973620
57
+ version_requirements: *70288970794880
58
58
  - !ruby/object:Gem::Dependency
59
59
  name: rack
60
- requirement: &70165614973220 !ruby/object:Gem::Requirement
60
+ requirement: &70288970794300 !ruby/object:Gem::Requirement
61
61
  none: false
62
62
  requirements:
63
63
  - - ! '>='
@@ -65,10 +65,10 @@ dependencies:
65
65
  version: '0'
66
66
  type: :development
67
67
  prerelease: false
68
- version_requirements: *70165614973220
68
+ version_requirements: *70288970794300
69
69
  - !ruby/object:Gem::Dependency
70
70
  name: simplecov
71
- requirement: &70165614972680 !ruby/object:Gem::Requirement
71
+ requirement: &70288970793380 !ruby/object:Gem::Requirement
72
72
  none: false
73
73
  requirements:
74
74
  - - =
@@ -76,10 +76,10 @@ dependencies:
76
76
  version: 0.4.2
77
77
  type: :development
78
78
  prerelease: false
79
- version_requirements: *70165614972680
79
+ version_requirements: *70288970793380
80
80
  - !ruby/object:Gem::Dependency
81
81
  name: simplecov-rcov
82
- requirement: &70165614972260 !ruby/object:Gem::Requirement
82
+ requirement: &70288970792900 !ruby/object:Gem::Requirement
83
83
  none: false
84
84
  requirements:
85
85
  - - ! '>='
@@ -87,7 +87,7 @@ dependencies:
87
87
  version: '0'
88
88
  type: :development
89
89
  prerelease: false
90
- version_requirements: *70165614972260
90
+ version_requirements: *70288970792900
91
91
  description: A set of adapters providing easy access to the GDS gov.uk APIs
92
92
  email:
93
93
  - jystewart@gmail.com