gds-api-adapters 50.7.0 → 50.8.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.
- checksums.yaml +4 -4
- data/lib/gds_api/rummager.rb +64 -15
- data/lib/gds_api/version.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: d32b7a11e6c88bfa89fe4586abcb1eb802385a3c
|
4
|
+
data.tar.gz: 9387022778924d8df0ef6379912aa88d059a0c0d
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 02f43b8750d1bc646dc608f16eac7e9176691d2d5b7536b2a6c807f63e82bc4db22c65c01882b2d75b5592fe40ca139adceca12921279600e7aab9a2723fd7c1
|
7
|
+
data.tar.gz: 39f75553dd24fce6da6c17fecf314ffe911556337fea3542e242fa6b8fe9b2edd40dcd250f35dc3480eecded8829646e5ec7bb9b550b17769ec68597960a55a8
|
data/lib/gds_api/rummager.rb
CHANGED
@@ -4,6 +4,62 @@ require 'rack/utils'
|
|
4
4
|
module GdsApi
|
5
5
|
# @api documented
|
6
6
|
class Rummager < Base
|
7
|
+
# @api documented
|
8
|
+
class V1 < SimpleDelegator
|
9
|
+
def add_document(type, id, document)
|
10
|
+
post_json(
|
11
|
+
documents_url,
|
12
|
+
document.merge(
|
13
|
+
_type: type,
|
14
|
+
_id: id,
|
15
|
+
)
|
16
|
+
)
|
17
|
+
end
|
18
|
+
|
19
|
+
def delete_document(type, id)
|
20
|
+
delete_json(
|
21
|
+
"#{documents_url}/#{id}",
|
22
|
+
_type: type,
|
23
|
+
)
|
24
|
+
end
|
25
|
+
end
|
26
|
+
|
27
|
+
# @api documented
|
28
|
+
class V2 < SimpleDelegator
|
29
|
+
class InvalidIndex < StandardError; end
|
30
|
+
|
31
|
+
def add_document(id, document, index_name)
|
32
|
+
raise(InvalidIndex, index_name) unless index_name == 'metasearch'
|
33
|
+
post_json(
|
34
|
+
"#{base_url}/v2/metasearch/documents",
|
35
|
+
document.merge(
|
36
|
+
_id: id,
|
37
|
+
)
|
38
|
+
)
|
39
|
+
end
|
40
|
+
|
41
|
+
def delete_document(id, index_name)
|
42
|
+
raise(InvalidIndex, index_name) unless index_name == 'metasearch'
|
43
|
+
delete_json("#{base_url}/v2/metasearch/documents/#{id}")
|
44
|
+
end
|
45
|
+
end
|
46
|
+
|
47
|
+
DEFAULT_API_VERSION = 'V1'.freeze
|
48
|
+
API_VERSIONS = {
|
49
|
+
'V1' => GdsApi::Rummager::V1,
|
50
|
+
'V2' => GdsApi::Rummager::V2,
|
51
|
+
}.freeze
|
52
|
+
class UnknownAPIVersion < StandardError; end
|
53
|
+
|
54
|
+
def initialize(endpoint_url, options = {})
|
55
|
+
super
|
56
|
+
# The API version provides a simple wrapper around this base class so that we
|
57
|
+
# can still access the shared methods present in this class.
|
58
|
+
version = options.fetch(:api_version, DEFAULT_API_VERSION)
|
59
|
+
api_class = API_VERSIONS[version] || raise(UnknownAPIVersion)
|
60
|
+
@api = api_class.new(self)
|
61
|
+
end
|
62
|
+
|
7
63
|
# Perform a search.
|
8
64
|
#
|
9
65
|
# @param args [Hash] A valid search query. See Rummager documentation for options.
|
@@ -52,17 +108,13 @@ module GdsApi
|
|
52
108
|
# @param type [String] The rummager/elasticsearch document type.
|
53
109
|
# @param id [String] The rummager/elasticsearch id. Typically the same as the `link` field, but this is not strictly enforced.
|
54
110
|
# @param document [Hash] The document to add. Must match the rummager schema matchin the `type` parameter and contain a `link` field.
|
111
|
+
# @param index_name (V2 only) Name of the index to be deleted from on
|
112
|
+
# GOV.UK - we only allow deletion from metasearch
|
55
113
|
# @return [GdsApi::Response] A status code of 202 indicates the document has been successfully queued.
|
56
114
|
#
|
57
115
|
# @see https://github.com/alphagov/rummager/blob/master/doc/documents.md
|
58
|
-
def add_document(
|
59
|
-
|
60
|
-
documents_url,
|
61
|
-
document.merge(
|
62
|
-
_type: type,
|
63
|
-
_id: id,
|
64
|
-
)
|
65
|
-
)
|
116
|
+
def add_document(*args)
|
117
|
+
@api.add_document(*args)
|
66
118
|
end
|
67
119
|
|
68
120
|
# Delete a content-document from the index by base path.
|
@@ -107,15 +159,12 @@ module GdsApi
|
|
107
159
|
#
|
108
160
|
# @param type [String] The rummager/elasticsearch document type.
|
109
161
|
# @param id [String] The rummager/elasticsearch id. Typically the same as the `link` field.
|
110
|
-
|
111
|
-
|
112
|
-
|
113
|
-
|
114
|
-
)
|
162
|
+
# @param index_name (V2 only) Name of the index to be deleted from on
|
163
|
+
# GOV.UK - we only allow deletion from metasearch
|
164
|
+
def delete_document(*args)
|
165
|
+
@api.delete_document(*args)
|
115
166
|
end
|
116
167
|
|
117
|
-
private
|
118
|
-
|
119
168
|
def base_url
|
120
169
|
endpoint
|
121
170
|
end
|
data/lib/gds_api/version.rb
CHANGED
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: 50.
|
4
|
+
version: 50.8.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-12-
|
11
|
+
date: 2017-12-21 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: plek
|