gds-api-adapters 39.2.0 → 40.0.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.
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: 39.2.0
4
+ version: 40.0.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: 2017-02-08 00:00:00.000000000 Z
11
+ date: 2017-02-22 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: plek
@@ -363,8 +363,6 @@ files:
363
363
  - lib/gds_api/need_api.rb
364
364
  - lib/gds_api/null_cache.rb
365
365
  - lib/gds_api/organisations.rb
366
- - lib/gds_api/panopticon.rb
367
- - lib/gds_api/panopticon/registerer.rb
368
366
  - lib/gds_api/performance_platform/data_in.rb
369
367
  - lib/gds_api/performance_platform/data_out.rb
370
368
  - lib/gds_api/publishing_api.rb
@@ -394,7 +392,6 @@ files:
394
392
  - lib/gds_api/test_helpers/mapit.rb
395
393
  - lib/gds_api/test_helpers/need_api.rb
396
394
  - lib/gds_api/test_helpers/organisations.rb
397
- - lib/gds_api/test_helpers/panopticon.rb
398
395
  - lib/gds_api/test_helpers/performance_platform/data_in.rb
399
396
  - lib/gds_api/test_helpers/performance_platform/data_out.rb
400
397
  - lib/gds_api/test_helpers/publishing_api.rb
@@ -407,6 +404,14 @@ files:
407
404
  - lib/gds_api/test_helpers/worldwide.rb
408
405
  - lib/gds_api/version.rb
409
406
  - lib/gds_api/worldwide.rb
407
+ - test/fixtures/finder_api/cma-case-schema.json
408
+ - test/fixtures/hello.txt
409
+ - test/fixtures/new_policies_for_dwp.json
410
+ - test/fixtures/no_services_and_info_data_found_fixture.json
411
+ - test/fixtures/old_policies_for_dwp.json
412
+ - test/fixtures/services_and_info_fixture.json
413
+ - test/fixtures/sub_sector_organisations.json
414
+ - test/fixtures/world_organisations_australia.json
410
415
  homepage: http://github.com/alphagov/gds-api-adapters
411
416
  licenses: []
412
417
  metadata: {}
@@ -431,4 +436,3 @@ signing_key:
431
436
  specification_version: 4
432
437
  summary: Adapters to work with GDS APIs
433
438
  test_files: []
434
- has_rdoc:
@@ -1,80 +0,0 @@
1
- require_relative 'base'
2
- require_relative 'panopticon/registerer'
3
- require_relative 'exceptions'
4
-
5
- class GdsApi::Panopticon < GdsApi::Base
6
- include GdsApi::ExceptionHandling
7
-
8
- def all
9
- url = base_url + '.json'
10
- json = get_json url
11
- to_ostruct json
12
- end
13
-
14
- def artefact_for_slug(slug, _opts = {})
15
- return nil if slug.nil? || slug == ''
16
- get_json(url_for_slug(slug))
17
- end
18
-
19
- def create_artefact(artefact)
20
- ignoring GdsApi::HTTPErrorResponse do
21
- create_artefact! artefact
22
- end
23
- end
24
-
25
- def create_artefact!(artefact)
26
- post_json(base_url + ".json", artefact)
27
- end
28
-
29
- def put_artefact(id_or_slug, artefact)
30
- ignoring GdsApi::HTTPErrorResponse do
31
- put_artefact! id_or_slug, artefact
32
- end
33
- end
34
-
35
- def put_artefact!(id_or_slug, artefact)
36
- put_json("#{base_url}/#{id_or_slug}.json", artefact)
37
- end
38
-
39
- def update_artefact(id_or_slug, artefact)
40
- self.class.logger.warn(
41
- "The update_artefact method is deprecated and may be removed in a " +
42
- "future release. You should use put_artefact instead."
43
- )
44
- put_artefact(id_or_slug, artefact)
45
- end
46
-
47
- def delete_artefact!(id_or_slug)
48
- delete_json("#{base_url}/#{id_or_slug}.json")
49
- end
50
-
51
- def create_tag(attributes)
52
- post_json("#{endpoint}/tags.json", attributes)
53
- end
54
-
55
- def put_tag(tag_type, tag_id, attributes)
56
- put_json(
57
- tag_url(tag_type, tag_id),
58
- attributes
59
- )
60
- end
61
-
62
- def publish_tag(tag_type, tag_id)
63
- post_json(
64
- tag_url(tag_type, tag_id, '/publish'),
65
- # we don't need to send any more data along with the publish request,
66
- # but a body is still required, so sending an empty JSON hash instead
67
- {}
68
- )
69
- end
70
-
71
- private
72
-
73
- def base_url
74
- "#{endpoint}/artefacts"
75
- end
76
-
77
- def tag_url(tag_type, tag_id, action = '')
78
- "#{endpoint}/tags/#{tag_type}/#{tag_id}#{action}.json"
79
- end
80
- end
@@ -1,100 +0,0 @@
1
- require 'plek'
2
-
3
- module GdsApi
4
- class Panopticon < GdsApi::Base
5
- class Registerer
6
- attr_accessor :logger, :owning_app, :rendering_app, :kind
7
-
8
- def initialize(options)
9
- @logger = options[:logger] || GdsApi::Base.logger
10
- @owning_app = options[:owning_app]
11
- @rendering_app = options[:rendering_app]
12
- @kind = options[:kind] || 'custom-application'
13
- @panopticon = options[:panopticon]
14
- @endpoint_url = options[:endpoint_url] || Plek.current.find("panopticon")
15
- @timeout = options[:timeout] || 10
16
- end
17
-
18
- def record_to_artefact(record)
19
- hash = {
20
- slug: record.slug,
21
- owning_app: owning_app,
22
- kind: kind,
23
- name: record.title,
24
- description: record.description,
25
- state: record.state
26
- }
27
-
28
- if rendering_app
29
- hash[:rendering_app] = rendering_app
30
- end
31
-
32
- optional_params = [
33
- :need_id,
34
- :need_ids,
35
-
36
- :paths,
37
- :prefixes,
38
-
39
- :public_timestamp,
40
- :latest_change_note,
41
-
42
- :content_id,
43
- ]
44
-
45
- deprecated_params = {
46
- section: [:primary_section, :sections]
47
- }
48
-
49
- deprecated_params.each do |attr_name, replacements|
50
- if record.respond_to?(attr_name)
51
- replacements = Array(replacements)
52
- logger.warn "#{attr_name} has been deprecated in favour of #{replacements.join(' and ')}"
53
- end
54
- end
55
-
56
- optional_params.each do |attr_name|
57
- if record.respond_to? attr_name
58
- hash[attr_name] = record.public_send(attr_name)
59
- end
60
- end
61
-
62
- hash
63
- end
64
-
65
- # record should respond to #slug and #title, or override #record_to_artefact
66
- def register(record)
67
- register_artefact(record_to_artefact(record))
68
- end
69
-
70
- protected
71
-
72
- def register_artefact(artefact)
73
- logger.info "Putting #{artefact[:slug]}"
74
-
75
- # Error responses here are pretty fatal, so propagate them
76
- response = panopticon.put_artefact!(artefact[:slug], artefact)
77
- case response.code
78
- when 200
79
- logger.info "Updated #{artefact[:slug]}"
80
- when 201
81
- logger.info "Created #{artefact[:slug]}"
82
- else
83
- # Only expect 200 or 201 success codes, but best to have a fallback
84
- logger.info "Registered #{artefact[:slug]} (code #{response.code})"
85
- end
86
- end
87
-
88
- def panopticon
89
- options = {
90
- timeout: @timeout
91
- }
92
- @panopticon ||= GdsApi::Panopticon.new(@endpoint_url, options.merge(panopticon_api_credentials))
93
- end
94
-
95
- def panopticon_api_credentials
96
- Object::const_defined?(:PANOPTICON_API_CREDENTIALS) ? PANOPTICON_API_CREDENTIALS : {}
97
- end
98
- end
99
- end
100
- end
@@ -1,76 +0,0 @@
1
- require 'gds_api/test_helpers/json_client_helper'
2
-
3
- module GdsApi
4
- module TestHelpers
5
- module Panopticon
6
- # Generally true. If you are initializing the client differently,
7
- # you could redefine/override the constant or stub directly.
8
- PANOPTICON_ENDPOINT = Plek.current.find('panopticon')
9
-
10
- def stringify_hash_keys(input_hash)
11
- input_hash.inject({}) do |options, (key, value)|
12
- options[key.to_s] = value
13
- options
14
- end
15
- end
16
-
17
- def panopticon_has_metadata(metadata)
18
- metadata = stringify_hash_keys(metadata)
19
-
20
- json = JSON.dump(metadata)
21
-
22
- urls = []
23
- urls << "#{PANOPTICON_ENDPOINT}/artefacts/#{metadata['id']}.json" if metadata['id']
24
- urls << "#{PANOPTICON_ENDPOINT}/artefacts/#{metadata['slug']}.json" if metadata['slug']
25
-
26
- urls.each { |url| stub_request(:get, url).to_return(status: 200, body: json, headers: {}) }
27
-
28
- urls.first
29
- end
30
-
31
- def panopticon_has_no_metadata_for(slug)
32
- url = "#{PANOPTICON_ENDPOINT}/artefacts/#{slug}.json"
33
- stub_request(:get, url).to_return(status: 404, body: "", headers: {})
34
- end
35
-
36
- def stub_panopticon_default_artefact
37
- stub_request(:get, %r{\A#{PANOPTICON_ENDPOINT}/artefacts}).to_return { |request|
38
- # return a response with only a slug, and set that slug to match the requested artefact slug
39
- { body: JSON.dump("slug" => request.uri.path.split('/').last.chomp('.json')) }
40
- }
41
- end
42
-
43
- def stub_artefact_registration(slug, request_details = nil, custom_matcher = false)
44
- stub = stub_http_request(:put, "#{PANOPTICON_ENDPOINT}/artefacts/#{slug}.json")
45
-
46
- if request_details
47
- request_details = request_details.to_json unless custom_matcher
48
- stub.with(body: request_details)
49
- end
50
-
51
- stub.to_return(status: 201)
52
- end
53
-
54
- def stub_panopticon_tag_creation(attributes)
55
- url = "#{PANOPTICON_ENDPOINT}/tags.json"
56
- stub_request(:post, url)
57
- .with(body: attributes.to_json)
58
- .to_return(status: 201, body: attributes.to_json)
59
- end
60
-
61
- def stub_panopticon_tag_update(tag_type, tag_id, attributes)
62
- url = "#{PANOPTICON_ENDPOINT}/tags/#{tag_type}/#{tag_id}.json"
63
- stub_request(:put, url)
64
- .with(body: attributes.to_json)
65
- .to_return(status: 200)
66
- end
67
-
68
- def stub_panopticon_tag_publish(tag_type, tag_id)
69
- url = "#{PANOPTICON_ENDPOINT}/tags/#{tag_type}/#{tag_id}/publish.json"
70
- stub_request(:post, url)
71
- .with(body: {}.to_json)
72
- .to_return(status: 200)
73
- end
74
- end
75
- end
76
- end