gds-api-adapters 30.2.0 → 30.2.1

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.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: caa6bb00e5f2ebd0cf88d785836ca4a034271d60
4
- data.tar.gz: 89afbd1e27b272902ef2007022743cda48b8cf25
3
+ metadata.gz: 969acb8ae599f5c52ed298ddd20c282defb88372
4
+ data.tar.gz: 195b6054704e7dd2d48aa363e984e04633914c36
5
5
  SHA512:
6
- metadata.gz: ddb41be6da100058a5f31a3680c6c9fc1773cb26415fa29c40015757ea2dc886d902ce7297e3e8f25eaedd3da95631a95c6804ad2c9ee91d90c1a9ec4c6bee43
7
- data.tar.gz: 034d0c128336323787a1246633797370f787f5b20a1d2efbe4bd5f5299062a5066a8680b773390bcd175b2d9e6fefc18ede604a58467dbffaa17c066d7f3e164
6
+ metadata.gz: e6850acb92b32f599b93073fff01b73deb2fb857a8d5578dfcc9e5d35c96c4c4fceadbf999295b00c166c21fe6daccbe0031807826b2425677698efe6e3b772e
7
+ data.tar.gz: 1d16735000c6ab008c52ab4a69f8485b54c25eace4c38b0298f04e6e1982cad0a825e313f74d13d073e8a427e0dbd944aa766fb15e1f5ad837b0d170fac6b4a9
data/README.md CHANGED
@@ -1,15 +1,20 @@
1
- A set of API adapters to work with the GDS APIs, extracted from the frontend
2
- app.
1
+ # GDS API Adapters
2
+
3
+ A set of API adapters to work with the GDS APIs.
3
4
 
4
5
  Example usage:
5
6
 
6
- publisher_api = GdsApi::Publisher.new("environment")
7
- ostruct_publication = publisher_api.publication_for_slug('my-published-item')
7
+ ```ruby
8
+ require 'gds_api/rummager'
9
+ rummager = GdsApi::Rummager.new(Plek.new.find('rummager'))
10
+ results = rummager.unified_search(q: "taxes")
11
+ ```
8
12
 
9
- panopticon_api = GdsApi::Panopticon.new("environment")
10
- ostruct_metadata = panopticon_api.artefact_for_slug('my-published-item')
13
+ Example adapters for frequently used applications:
11
14
 
12
- Very much still a work in progress.
15
+ - [Publishing API](lib/gds_api/publishing_api_v2.rb) ([docs](http://www.rubydoc.info/gems/gds-api-adapters/GdsApi/PublishingApiV2), [test helper code](https://github.com/alphagov/gds-api-adapters/blob/master/lib/gds_api/test_helpers/publishing_api_v2.rb), [test helper docs](http://www.rubydoc.info/gems/gds-api-adapters/GdsApi/TestHelpers/PublishingApiV2))
16
+ - [Content Store](lib/gds_api/content_store.rb) ([docs](http://www.rubydoc.info/gems/gds-api-adapters/GdsApi/ContentStore), [test helper code](https://github.com/alphagov/gds-api-adapters/blob/master/lib/gds_api/test_helpers/content_store.rb), [test helper docs](http://www.rubydoc.info/gems/gds-api-adapters/GdsApi/TestHelpers/ContentStore))
17
+ - [Rummager](lib/gds_api/publishing_api_v2.rb) ([docs](http://www.rubydoc.info/gems/gds-api-adapters/GdsApi/Rummager), [test helper code](https://github.com/alphagov/gds-api-adapters/blob/master/lib/gds_api/test_helpers/rummager.rb), [test helper docs](http://www.rubydoc.info/gems/gds-api-adapters/GdsApi/TestHelpers/Rummager))
13
18
 
14
19
  ## Logging
15
20
 
@@ -1,7 +1,6 @@
1
1
  require 'gds_api/asset_manager'
2
2
  require 'gds_api/business_support_api'
3
3
  require 'gds_api/content_api'
4
- require 'gds_api/content_register'
5
4
  require 'gds_api/content_store'
6
5
  require 'gds_api/imminence'
7
6
  require 'gds_api/licence_application'
@@ -25,10 +24,6 @@ module GdsApi
25
24
  @content_api ||= GdsApi::ContentApi.new(Plek.current.find("contentapi"), options)
26
25
  end
27
26
 
28
- def content_register(options = {})
29
- @content_register ||= GdsApi::ContentRegister.new(Plek.current.find("content-register"), options)
30
- end
31
-
32
27
  def content_store(options = {})
33
28
  @content_store ||= GdsApi::ContentStore.new(Plek.current.find("content-store"), options)
34
29
  end
@@ -1,6 +1,17 @@
1
1
  require_relative 'base'
2
2
 
3
+ # Adapter for the Publishing API.
4
+ #
5
+ # @see https://github.com/alphagov/publishing-api
6
+ # @see https://github.com/alphagov/publishing-api/blob/master/doc/publishing-application-examples.md
7
+ # @see https://github.com/alphagov/publishing-api/blob/master/doc/object-model-explanation.md
3
8
  class GdsApi::PublishingApiV2 < GdsApi::Base
9
+ # Put a content item
10
+ #
11
+ # @param content_id [UUID]
12
+ # @param payload [Hash] A valid content item
13
+ #
14
+ # @see https://github.com/alphagov/publishing-api/blob/master/doc/publishing-api-syntactic-usage.md#put-v2contentcontent_id
4
15
  def put_content(content_id, payload)
5
16
  put_json!(content_url(content_id), payload)
6
17
  end
@@ -14,6 +25,7 @@ class GdsApi::PublishingApiV2 < GdsApi::Base
14
25
  # @option params [String] locale The language, defaults to 'en' in publishing-api.
15
26
  #
16
27
  # @return [GdsApi::Response] a content item
28
+ # @see https://github.com/alphagov/publishing-api/blob/master/doc/publishing-api-syntactic-usage.md#get-v2contentcontent_id
17
29
  def get_content(content_id, params = {})
18
30
  get_json(content_url(content_id, params))
19
31
  end
@@ -29,6 +41,7 @@ class GdsApi::PublishingApiV2 < GdsApi::Base
29
41
  # @return [GdsApi::Response] a content item
30
42
  #
31
43
  # @raise [HTTPNotFound] when the content item is not found
44
+ # @see https://github.com/alphagov/publishing-api/blob/master/doc/publishing-api-syntactic-usage.md#get-v2contentcontent_id
32
45
  def get_content!(content_id, params = {})
33
46
  get_json!(content_url(content_id, params))
34
47
  end
@@ -42,6 +55,7 @@ class GdsApi::PublishingApiV2 < GdsApi::Base
42
55
  # publishing_api.lookup_content_ids(base_paths: ['/foo', '/bar'])
43
56
  # # => { "/foo" => "51ac4247-fd92-470a-a207-6b852a97f2db", "/bar" => "261bd281-f16c-48d5-82d2-9544019ad9ca" }
44
57
  #
58
+ # @see https://github.com/alphagov/publishing-api/blob/master/doc/publishing-api-syntactic-usage.md#post-lookup-by-base-path
45
59
  def lookup_content_ids(base_paths:)
46
60
  response = post_json!("#{endpoint}/lookup-by-base-path", base_paths: base_paths)
47
61
  response.to_hash
@@ -61,11 +75,23 @@ class GdsApi::PublishingApiV2 < GdsApi::Base
61
75
  # publishing_api.lookup_content_id(base_path: '/foo')
62
76
  # # => "51ac4247-fd92-470a-a207-6b852a97f2db"
63
77
  #
78
+ # @see https://github.com/alphagov/publishing-api/blob/master/doc/publishing-api-syntactic-usage.md#post-lookup-by-base-path
64
79
  def lookup_content_id(base_path:)
65
80
  lookups = lookup_content_ids(base_paths: [base_path])
66
81
  lookups[base_path]
67
82
  end
68
83
 
84
+ # Publish a content item
85
+ #
86
+ # The publishing-api will "publish" a draft item, so that it will be visible
87
+ # on the public site.
88
+ #
89
+ # @param content_id [UUID]
90
+ # @param update_type [String] Either 'major', 'minor' or 'republish'
91
+ # @param params [Hash]
92
+ # @option params [String] locale The language, defaults to 'en' in publishing-api.
93
+ #
94
+ # @see https://github.com/alphagov/publishing-api/blob/master/doc/publishing-api-syntactic-usage.md#post-v2contentcontent_idpublish
69
95
  def publish(content_id, update_type, options = {})
70
96
  params = {
71
97
  update_type: update_type
@@ -81,6 +107,15 @@ class GdsApi::PublishingApiV2 < GdsApi::Base
81
107
  post_json!(publish_url(content_id), params)
82
108
  end
83
109
 
110
+ # Discard a draft
111
+ #
112
+ # Deletes the draft content item.
113
+ #
114
+ # @param params [Hash]
115
+ # @option params [String] locale The language, defaults to 'en' in publishing-api.
116
+ # @option params [Integer] previous_version used to ensure the request is discarding the latest lock version of the draft
117
+ #
118
+ # @see https://github.com/alphagov/publishing-api/blob/master/doc/publishing-api-syntactic-usage.md#post-v2contentcontent_iddiscard-draft
84
119
  def discard_draft(content_id, options = {})
85
120
  optional_keys = [
86
121
  :locale,
@@ -92,10 +127,28 @@ class GdsApi::PublishingApiV2 < GdsApi::Base
92
127
  post_json!(discard_url(content_id), params)
93
128
  end
94
129
 
130
+ # FIXME: Add documentation
131
+ #
132
+ # @see https://github.com/alphagov/publishing-api/blob/master/doc/publishing-api-syntactic-usage.md#get-v2linkscontent_id
95
133
  def get_links(content_id)
96
134
  get_json(links_url(content_id))
97
135
  end
98
136
 
137
+ # Patch the links of a content item
138
+ #
139
+ # @param content_id [UUID]
140
+ # @param payload [Hash] A "links hash"
141
+ # @example
142
+ #
143
+ # publishing_api.patch_links(
144
+ # '86963c13-1f57-4005-b119-e7cf3cb92ecf',
145
+ # {
146
+ # topics: ['d6e1527d-d0c0-40d5-9603-b9f3e6866b8a'],
147
+ # mainstream_browse_pages: ['d6e1527d-d0c0-40d5-9603-b9f3e6866b8a'],
148
+ # }
149
+ # )
150
+ #
151
+ # @see https://github.com/alphagov/publishing-api/blob/master/doc/publishing-api-syntactic-usage.md#patch-v2linkscontent_id
99
152
  def patch_links(content_id, payload)
100
153
  params = {
101
154
  links: payload.fetch(:links)
@@ -106,11 +159,17 @@ class GdsApi::PublishingApiV2 < GdsApi::Base
106
159
  patch_json!(links_url(content_id), params)
107
160
  end
108
161
 
162
+ # FIXME: Add documentation
163
+ #
164
+ # @see https://github.com/alphagov/publishing-api/blob/master/doc/publishing-api-syntactic-usage.md#get-v2content
109
165
  def get_content_items(params)
110
166
  query = query_string(params)
111
167
  get_json("#{endpoint}/v2/content#{query}")
112
168
  end
113
169
 
170
+ # FIXME: Add documentation
171
+ #
172
+ # @see https://github.com/alphagov/publishing-api/blob/master/doc/publishing-api-syntactic-usage.md#get-v2linkables
114
173
  def get_linkables(document_type: nil, format: nil)
115
174
  if document_type.nil?
116
175
  if format.nil?
@@ -127,6 +186,9 @@ class GdsApi::PublishingApiV2 < GdsApi::Base
127
186
  get_json("#{endpoint}/v2/linkables?document_type=#{document_type}")
128
187
  end
129
188
 
189
+ # FIXME: Add documentation
190
+ #
191
+ # @see https://github.com/alphagov/publishing-api/blob/master/doc/publishing-api-syntactic-usage.md#get-v2linkedcontent_id
130
192
  def get_linked_items(content_id, params = {})
131
193
  query = query_string(params)
132
194
  validate_content_id(content_id)
@@ -4,17 +4,32 @@ require 'rack/utils'
4
4
  module GdsApi
5
5
  class Rummager < Base
6
6
 
7
+ # Unified search
8
+ #
9
+ # Perform a search
10
+ #
11
+ # @param query [Hash] A valid search query. See Rummager documentation for options.
12
+ #
13
+ # @see https://github.com/alphagov/rummager/blob/master/docs/unified-search-api.md
7
14
  def unified_search(args)
8
15
  request_url = "#{base_url}/unified_search.json?#{Rack::Utils.build_nested_query(args)}"
9
16
  get_json!(request_url)
10
17
  end
11
18
 
19
+ # Advanced search
20
+ #
21
+ # @deprecated Only in use by Whitehall. Use the `unified_search` method.
12
22
  def advanced_search(args)
13
23
  raise ArgumentError.new("Args cannot be blank") if args.nil? || args.empty?
14
24
  request_path = "#{base_url}/advanced_search?#{Rack::Utils.build_nested_query(args)}"
15
25
  get_json!(request_path)
16
26
  end
17
27
 
28
+ # Add a document
29
+ #
30
+ # Adds a document to the index
31
+ #
32
+ # @see https://github.com/alphagov/rummager/blob/master/docs/documents.md
18
33
  def add_document(type, id, document)
19
34
  post_json!(
20
35
  documents_url,
@@ -39,7 +54,7 @@ module GdsApi
39
54
  # Retrieves a content-document from the index. Content documents are pages
40
55
  # on GOV.UK returned by search index.
41
56
  #
42
- # @param base_path Base path of the page on GOV.UK.
57
+ # @param base_path [String] Base path of the page on GOV.UK.
43
58
  # @see https://github.com/alphagov/rummager/blob/master/docs/content-api.md
44
59
  def get_content!(base_path)
45
60
  request_url = "#{base_url}/content?link=#{base_path}"
@@ -51,7 +66,8 @@ module GdsApi
51
66
  # Delete any document from the search index. Unlike `delete_content!` this
52
67
  # needs a type, but can be used to delete non-content documents from the
53
68
  # index.
54
- # @deprecated
69
+ #
70
+ # @deprecated Use `delete_content!`
55
71
  def delete_document(type, id)
56
72
  delete_json!(
57
73
  "#{documents_url}/#{id}",
@@ -1,3 +1,3 @@
1
1
  module GdsApi
2
- VERSION = '30.2.0'
2
+ VERSION = '30.2.1'
3
3
  end
@@ -12,7 +12,6 @@ describe GdsApi::Helpers do
12
12
  refute_nil test_with_helpers.asset_manager_api
13
13
  refute_nil test_with_helpers.business_support_api
14
14
  refute_nil test_with_helpers.content_api
15
- refute_nil test_with_helpers.content_register
16
15
  refute_nil test_with_helpers.content_store
17
16
  refute_nil test_with_helpers.publisher_api
18
17
  refute_nil test_with_helpers.imminence_api
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: 30.2.0
4
+ version: 30.2.1
5
5
  platform: ruby
6
6
  authors:
7
7
  - James Stewart
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2016-04-15 00:00:00.000000000 Z
11
+ date: 2016-04-29 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: plek
@@ -136,34 +136,6 @@ dependencies:
136
136
  - - ">"
137
137
  - !ruby/object:Gem::Version
138
138
  version: 5.0.0
139
- - !ruby/object:Gem::Dependency
140
- name: pact
141
- requirement: !ruby/object:Gem::Requirement
142
- requirements:
143
- - - ">="
144
- - !ruby/object:Gem::Version
145
- version: '0'
146
- type: :development
147
- prerelease: false
148
- version_requirements: !ruby/object:Gem::Requirement
149
- requirements:
150
- - - ">="
151
- - !ruby/object:Gem::Version
152
- version: '0'
153
- - !ruby/object:Gem::Dependency
154
- name: pact-consumer-minitest
155
- requirement: !ruby/object:Gem::Requirement
156
- requirements:
157
- - - ">="
158
- - !ruby/object:Gem::Version
159
- version: '0'
160
- type: :development
161
- prerelease: false
162
- version_requirements: !ruby/object:Gem::Requirement
163
- requirements:
164
- - - ">="
165
- - !ruby/object:Gem::Version
166
- version: '0'
167
139
  - !ruby/object:Gem::Dependency
168
140
  name: pry
169
141
  requirement: !ruby/object:Gem::Requirement
@@ -290,18 +262,60 @@ dependencies:
290
262
  - - '='
291
263
  - !ruby/object:Gem::Version
292
264
  version: 1.24.2
265
+ - !ruby/object:Gem::Dependency
266
+ name: pact
267
+ requirement: !ruby/object:Gem::Requirement
268
+ requirements:
269
+ - - '='
270
+ - !ruby/object:Gem::Version
271
+ version: 1.9.0
272
+ type: :development
273
+ prerelease: false
274
+ version_requirements: !ruby/object:Gem::Requirement
275
+ requirements:
276
+ - - '='
277
+ - !ruby/object:Gem::Version
278
+ version: 1.9.0
279
+ - !ruby/object:Gem::Dependency
280
+ name: pact-mock_service
281
+ requirement: !ruby/object:Gem::Requirement
282
+ requirements:
283
+ - - '='
284
+ - !ruby/object:Gem::Version
285
+ version: 0.8.1
286
+ type: :development
287
+ prerelease: false
288
+ version_requirements: !ruby/object:Gem::Requirement
289
+ requirements:
290
+ - - '='
291
+ - !ruby/object:Gem::Version
292
+ version: 0.8.1
293
+ - !ruby/object:Gem::Dependency
294
+ name: pact-consumer-minitest
295
+ requirement: !ruby/object:Gem::Requirement
296
+ requirements:
297
+ - - '='
298
+ - !ruby/object:Gem::Version
299
+ version: 1.0.1
300
+ type: :development
301
+ prerelease: false
302
+ version_requirements: !ruby/object:Gem::Requirement
303
+ requirements:
304
+ - - '='
305
+ - !ruby/object:Gem::Version
306
+ version: 1.0.1
293
307
  - !ruby/object:Gem::Dependency
294
308
  name: pact_broker-client
295
309
  requirement: !ruby/object:Gem::Requirement
296
310
  requirements:
297
- - - "~>"
311
+ - - '='
298
312
  - !ruby/object:Gem::Version
299
313
  version: 1.0.0
300
314
  type: :development
301
315
  prerelease: false
302
316
  version_requirements: !ruby/object:Gem::Requirement
303
317
  requirements:
304
- - - "~>"
318
+ - - '='
305
319
  - !ruby/object:Gem::Version
306
320
  version: 1.0.0
307
321
  description: A set of adapters providing easy access to the GDS GOV.UK APIs
@@ -318,7 +332,6 @@ files:
318
332
  - lib/gds_api/base.rb
319
333
  - lib/gds_api/business_support_api.rb
320
334
  - lib/gds_api/content_api.rb
321
- - lib/gds_api/content_register.rb
322
335
  - lib/gds_api/content_store.rb
323
336
  - lib/gds_api/core-ext/openstruct.rb
324
337
  - lib/gds_api/email_alert_api.rb
@@ -359,7 +372,6 @@ files:
359
372
  - lib/gds_api/test_helpers/content_api.rb
360
373
  - lib/gds_api/test_helpers/content_api/artefact_stub.rb
361
374
  - lib/gds_api/test_helpers/content_item_helpers.rb
362
- - lib/gds_api/test_helpers/content_register.rb
363
375
  - lib/gds_api/test_helpers/content_store.rb
364
376
  - lib/gds_api/test_helpers/email_alert_api.rb
365
377
  - lib/gds_api/test_helpers/gov_uk_delivery.rb
@@ -387,7 +399,6 @@ files:
387
399
  - test/asset_manager_test.rb
388
400
  - test/business_support_api_test.rb
389
401
  - test/content_api_test.rb
390
- - test/content_register_test.rb
391
402
  - test/content_store_test.rb
392
403
  - test/email_alert_api_test.rb
393
404
  - test/external_link_tracker_test.rb
@@ -469,7 +480,6 @@ test_files:
469
480
  - test/publisher_api_test.rb
470
481
  - test/rummager_helpers_test.rb
471
482
  - test/support_test.rb
472
- - test/content_register_test.rb
473
483
  - test/test_helpers/publishing_api_test.rb
474
484
  - test/test_helpers/pact_helper.rb
475
485
  - test/test_helpers/panopticon_test.rb
@@ -1,23 +0,0 @@
1
- require_relative 'base'
2
- require_relative 'exceptions'
3
-
4
- class GdsApi::ContentRegister < GdsApi::Base
5
-
6
- def put_entry(content_id, entry)
7
- put_json!(entry_url(content_id), entry)
8
- end
9
-
10
- def entries(format)
11
- get_json!(entries_url(format))
12
- end
13
-
14
- private
15
-
16
- def entries_url(format)
17
- "#{endpoint}/entries?format=#{format}"
18
- end
19
-
20
- def entry_url(content_id)
21
- "#{endpoint}/entry/#{content_id}"
22
- end
23
- end
@@ -1,38 +0,0 @@
1
- require 'gds_api/test_helpers/json_client_helper'
2
- require 'json'
3
-
4
- module GdsApi
5
- module TestHelpers
6
- module ContentRegister
7
- CONTENT_REGISTER_ENDPOINT = Plek.find('content-register')
8
-
9
- def stub_content_register_put_entry(content_id, entry)
10
- response_body = entry.merge(content_id: content_id).to_json
11
-
12
- stub_request(:put, content_register_entry_url_for(content_id)).
13
- with(body: entry).
14
- to_return(status: 201, body: response_body)
15
- end
16
-
17
- def stub_content_register_entries(format, entries)
18
- stub_request(:get, content_register_entries_url(format)).
19
- to_return(body: entries.to_json, status: 200)
20
- end
21
-
22
- def content_register_isnt_available
23
- stub_request(:any, /#{CONTENT_REGISTER_ENDPOINT}\/.*/).
24
- to_return(status: 503)
25
- end
26
-
27
- private
28
-
29
- def content_register_entry_url_for(content_id)
30
- CONTENT_REGISTER_ENDPOINT + "/entry/" + content_id
31
- end
32
-
33
- def content_register_entries_url(format)
34
- CONTENT_REGISTER_ENDPOINT + "/entries?format=#{format}"
35
- end
36
- end
37
- end
38
- end
@@ -1,27 +0,0 @@
1
- require 'test_helper'
2
- require 'gds_api/content_register'
3
- require 'gds_api/test_helpers/content_register'
4
-
5
- describe GdsApi::ContentRegister do
6
- include GdsApi::TestHelpers::ContentRegister
7
-
8
- before do
9
- @api_adapter = GdsApi::ContentRegister.new(Plek.find("content-register"))
10
- end
11
-
12
- describe "#put_entry method" do
13
- it "creates an entry in the content register" do
14
- content_id = SecureRandom.uuid
15
- entry = {
16
- "format" => 'organisation',
17
- "title" => 'Organisation',
18
- "base_path" => "/government/organisations/organisation"
19
- }
20
-
21
- stub_content_register_put_entry(content_id, entry)
22
-
23
- response = @api_adapter.put_entry(content_id, entry)
24
- assert_equal 201, response.code
25
- end
26
- end
27
- end