elastic-enterprise-search 0.2.1 → 0.3.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/README.md +59 -3
- data/lib/elastic/enterprise-search/client.rb +4 -43
- data/lib/elastic/enterprise-search/client/content_source_documents.rb +46 -0
- data/lib/elastic/enterprise-search/client/permissions.rb +30 -0
- data/lib/elastic/enterprise-search/request.rb +1 -1
- data/lib/elastic/enterprise-search/version.rb +1 -1
- data/spec/client/content_source_documents_spec.rb +55 -0
- data/spec/client/permissions_spec.rb +75 -0
- data/spec/fixtures/vcr/add_user_permissions.yml +55 -0
- data/spec/fixtures/vcr/get_user_permissions.yml +55 -0
- data/spec/fixtures/vcr/list_all_permissions.yml +55 -0
- data/spec/fixtures/vcr/list_all_permissions_with_paging.yml +55 -0
- data/spec/fixtures/vcr/remove_user_permissions.yml +55 -0
- data/spec/fixtures/vcr/update_user_permissions.yml +55 -0
- metadata +21 -6
- data/spec/client_spec.rb +0 -57
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 4515fe152cfe00b0bcc53e873771342434c5dd5a61f776805b89e3b52b44c795
|
4
|
+
data.tar.gz: 100c01185713f91eb9648da0fd38acd059ae0a30fc5f3d900acec85a540efaab
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: cfe7f71022fe098efdbe20442151ba14fdf75947c3fd24a240310f2d853d4fa0995f7ac469dc86e3c770eb950cd68f13a82b1064cd7a7590052c3b81cc210fe3
|
7
|
+
data.tar.gz: a3b97981a52556f9966858abd1d1767ab13c16ac3494908f3bdb8712f539a62ae896bbf386b8a0d6f1658ab8d8792dad4bfc9269eea2d02bcfd415370466bb74
|
data/README.md
CHANGED
@@ -22,7 +22,7 @@ To install the gem, execute:
|
|
22
22
|
gem install elastic-enterprise-search
|
23
23
|
```
|
24
24
|
|
25
|
-
Or place `gem 'elastic-enterprise-search', '~> 0.
|
25
|
+
Or place `gem 'elastic-enterprise-search', '~> 0.3.0` in your `Gemfile` and run `bundle install`.
|
26
26
|
|
27
27
|
## Usage
|
28
28
|
|
@@ -46,7 +46,9 @@ Elastic::EnterpriseSearch.endpoint = 'https://your-server.example.com/api/v1'
|
|
46
46
|
client = Elastic::EnterpriseSearch::Client.new(:proxy => 'http://localhost:8888')
|
47
47
|
```
|
48
48
|
|
49
|
-
###
|
49
|
+
### Documents
|
50
|
+
|
51
|
+
#### Indexing Documents
|
50
52
|
|
51
53
|
This example shows how to use the index_documents method:
|
52
54
|
|
@@ -75,7 +77,7 @@ rescue Elastic::EnterpriseSearch::ClientException => e
|
|
75
77
|
end
|
76
78
|
```
|
77
79
|
|
78
|
-
|
80
|
+
#### Destroying Documents
|
79
81
|
|
80
82
|
```ruby
|
81
83
|
content_source_key = '' # your content source key
|
@@ -89,6 +91,60 @@ rescue Elastic::EnterpriseSearch::ClientException => e
|
|
89
91
|
end
|
90
92
|
```
|
91
93
|
|
94
|
+
### Permissions
|
95
|
+
|
96
|
+
#### Listing all permissions
|
97
|
+
|
98
|
+
```ruby
|
99
|
+
content_source_key = '' # your content source key
|
100
|
+
|
101
|
+
client.list_all_permissions(content_source_key)
|
102
|
+
```
|
103
|
+
|
104
|
+
#### Listing all permissions with paging
|
105
|
+
|
106
|
+
```ruby
|
107
|
+
content_source_key = '' # your content source key
|
108
|
+
|
109
|
+
client.list_all_permissions(content_source_key, :current => 2, :size => 20)
|
110
|
+
```
|
111
|
+
|
112
|
+
#### Retrieve a User's permissions
|
113
|
+
|
114
|
+
```ruby
|
115
|
+
content_source_key = '' # your content source key
|
116
|
+
user = 'enterprise_search'
|
117
|
+
|
118
|
+
client.get_user_permissions(content_source_key, user)
|
119
|
+
```
|
120
|
+
|
121
|
+
#### Add permissions to a User
|
122
|
+
```ruby
|
123
|
+
content_source_key = '' # your content source key
|
124
|
+
user = 'enterprise_search'
|
125
|
+
permissions = ['permission1']
|
126
|
+
|
127
|
+
client.add_user_permissions(content_source_key, user, :permissions => permissions)
|
128
|
+
```
|
129
|
+
|
130
|
+
#### Update a User's permissions
|
131
|
+
```ruby
|
132
|
+
content_source_key = '' # your content source key
|
133
|
+
user = 'enterprise_search'
|
134
|
+
permissions = ['permission2']
|
135
|
+
|
136
|
+
client.update_user_permissions(content_source_key, user, :permissions => permissions)
|
137
|
+
```
|
138
|
+
|
139
|
+
#### Remove permissions from a User
|
140
|
+
```ruby
|
141
|
+
content_source_key = '' # your content source key
|
142
|
+
user = 'enterprise_search'
|
143
|
+
permissions = ['permission2']
|
144
|
+
|
145
|
+
client.remove_user_permissions(content_source_key, user, :permissions => permissions)
|
146
|
+
```
|
147
|
+
|
92
148
|
## Running tests
|
93
149
|
|
94
150
|
Run tests via rspec:
|
@@ -7,6 +7,9 @@ module Elastic
|
|
7
7
|
module EnterpriseSearch
|
8
8
|
# API client for the {Elastic Enterprise Search API}[https://swiftype.com/enterprise-search].
|
9
9
|
class Client
|
10
|
+
autoload :ContentSourceDocuments, 'elastic/enterprise-search/client/content_source_documents.rb'
|
11
|
+
autoload :Permissions, 'elastic/enterprise-search/client/permissions.rb'
|
12
|
+
|
10
13
|
DEFAULT_TIMEOUT = 15
|
11
14
|
|
12
15
|
include Elastic::EnterpriseSearch::Request
|
@@ -43,50 +46,8 @@ module Elastic
|
|
43
46
|
(@options[:overall_timeout] || DEFAULT_TIMEOUT).to_f
|
44
47
|
end
|
45
48
|
|
46
|
-
# Documents have fields that can be searched or filtered.
|
47
|
-
#
|
48
|
-
# For more information on indexing documents, see the {Content Source documentation}[https://swiftype.com/documentation/enterprise-search/guides/content-sources].
|
49
|
-
module ContentSourceDocuments
|
50
|
-
|
51
|
-
# Index a batch of documents using the {Content Source API}[https://swiftype.com/documentation/enterprise-search/api/custom-sources].
|
52
|
-
#
|
53
|
-
# @param [String] content_source_key the unique Content Source key as found in your Content Sources dashboard
|
54
|
-
# @param [Array] documents an Array of Document Hashes
|
55
|
-
#
|
56
|
-
# @return [Array<Hash>] an Array of Document indexing Results
|
57
|
-
#
|
58
|
-
# @raise [Elastic::EnterpriseSearch::InvalidDocument] when a single document is missing required fields or contains unsupported fields
|
59
|
-
# @raise [Timeout::Error] when timeout expires waiting for results
|
60
|
-
def index_documents(content_source_key, documents)
|
61
|
-
documents = Array(documents).map! { |document| normalize_document(document) }
|
62
|
-
|
63
|
-
async_create_or_update_documents(content_source_key, documents)
|
64
|
-
end
|
65
|
-
|
66
|
-
# Destroy a batch of documents given a list of external IDs
|
67
|
-
#
|
68
|
-
# @param [Array<String>] document_ids an Array of Document External IDs
|
69
|
-
#
|
70
|
-
# @return [Array<Hash>] an Array of Document destroy result hashes
|
71
|
-
#
|
72
|
-
# @raise [Timeout::Error] when timeout expires waiting for results
|
73
|
-
def destroy_documents(content_source_key, document_ids)
|
74
|
-
document_ids = Array(document_ids)
|
75
|
-
post("ent/sources/#{content_source_key}/documents/bulk_destroy.json", document_ids)
|
76
|
-
end
|
77
|
-
|
78
|
-
private
|
79
|
-
|
80
|
-
def async_create_or_update_documents(content_source_key, documents)
|
81
|
-
post("ent/sources/#{content_source_key}/documents/bulk_create.json", documents)
|
82
|
-
end
|
83
|
-
|
84
|
-
def normalize_document(document)
|
85
|
-
Utils.stringify_keys(document)
|
86
|
-
end
|
87
|
-
end
|
88
|
-
|
89
49
|
include Elastic::EnterpriseSearch::Client::ContentSourceDocuments
|
50
|
+
include Elastic::EnterpriseSearch::Client::Permissions
|
90
51
|
end
|
91
52
|
end
|
92
53
|
end
|
@@ -0,0 +1,46 @@
|
|
1
|
+
# Content Source API - https://swiftype.com/documentation/enterprise-search/api/custom-sources
|
2
|
+
module Elastic
|
3
|
+
module EnterpriseSearch
|
4
|
+
class Client
|
5
|
+
module ContentSourceDocuments
|
6
|
+
|
7
|
+
# Index a batch of documents.
|
8
|
+
#
|
9
|
+
# @param [String] content_source_key the unique Content Source key as found in your Content Sources dashboard
|
10
|
+
# @param [Array] documents an Array of Document Hashes
|
11
|
+
#
|
12
|
+
# @return [Array<Hash>] an Array of Document indexing Results
|
13
|
+
#
|
14
|
+
# @raise [Elastic::EnterpriseSearch::InvalidDocument] when a single document is missing required fields or contains unsupported fields
|
15
|
+
# @raise [Timeout::Error] when timeout expires waiting for results
|
16
|
+
def index_documents(content_source_key, documents)
|
17
|
+
documents = Array(documents).map! { |document| normalize_document(document) }
|
18
|
+
|
19
|
+
async_create_or_update_documents(content_source_key, documents)
|
20
|
+
end
|
21
|
+
|
22
|
+
# Destroy a batch of documents given a list of external IDs
|
23
|
+
#
|
24
|
+
# @param [Array<String>] document_ids an Array of Document External IDs
|
25
|
+
#
|
26
|
+
# @return [Array<Hash>] an Array of Document destroy result hashes
|
27
|
+
#
|
28
|
+
# @raise [Timeout::Error] when timeout expires waiting for results
|
29
|
+
def destroy_documents(content_source_key, document_ids)
|
30
|
+
document_ids = Array(document_ids)
|
31
|
+
post("ent/sources/#{content_source_key}/documents/bulk_destroy.json", document_ids)
|
32
|
+
end
|
33
|
+
|
34
|
+
private
|
35
|
+
|
36
|
+
def async_create_or_update_documents(content_source_key, documents)
|
37
|
+
post("ent/sources/#{content_source_key}/documents/bulk_create.json", documents)
|
38
|
+
end
|
39
|
+
|
40
|
+
def normalize_document(document)
|
41
|
+
Utils.stringify_keys(document)
|
42
|
+
end
|
43
|
+
end
|
44
|
+
end
|
45
|
+
end
|
46
|
+
end
|
@@ -0,0 +1,30 @@
|
|
1
|
+
# Document Permissions API - /documentation/enterprise-search/api/document-permissions
|
2
|
+
module Elastic
|
3
|
+
module EnterpriseSearch
|
4
|
+
class Client
|
5
|
+
module Permissions
|
6
|
+
|
7
|
+
def list_all_permissions(content_source_key, current: 1, size: 25)
|
8
|
+
get("ent/sources/#{content_source_key}/permissions", "page[current]" => current, "page[size]" => size )
|
9
|
+
end
|
10
|
+
|
11
|
+
def get_user_permissions(content_source_key, user)
|
12
|
+
get("ent/sources/#{content_source_key}/permissions/#{user}")
|
13
|
+
end
|
14
|
+
|
15
|
+
def update_user_permissions(content_source_key, user, options)
|
16
|
+
post("ent/sources/#{content_source_key}/permissions/#{user}", options)
|
17
|
+
end
|
18
|
+
|
19
|
+
def add_user_permissions(content_source_key, user, options)
|
20
|
+
post("ent/sources/#{content_source_key}/permissions/#{user}/add", options)
|
21
|
+
end
|
22
|
+
|
23
|
+
def remove_user_permissions(content_source_key, user, options)
|
24
|
+
post("ent/sources/#{content_source_key}/permissions/#{user}/remove", options)
|
25
|
+
end
|
26
|
+
|
27
|
+
end
|
28
|
+
end
|
29
|
+
end
|
30
|
+
end
|
@@ -70,7 +70,7 @@ module Elastic
|
|
70
70
|
when Net::HTTPNotFound
|
71
71
|
raise Elastic::EnterpriseSearch::NonExistentRecord
|
72
72
|
when Net::HTTPBadRequest
|
73
|
-
raise Elastic::EnterpriseSearch::BadRequest
|
73
|
+
raise Elastic::EnterpriseSearch::BadRequest, "#{response.code} #{response.body}"
|
74
74
|
when Net::HTTPForbidden
|
75
75
|
raise Elastic::EnterpriseSearch::Forbidden
|
76
76
|
else
|
@@ -0,0 +1,55 @@
|
|
1
|
+
require 'spec_helper'
|
2
|
+
|
3
|
+
describe Elastic::EnterpriseSearch::Client::ContentSourceDocuments do
|
4
|
+
let(:engine_slug) { 'enterprise-search-api-example' }
|
5
|
+
let(:client) { Elastic::EnterpriseSearch::Client.new }
|
6
|
+
|
7
|
+
before :each do
|
8
|
+
Elastic::EnterpriseSearch.access_token = 'cGUN-vBokevBhhzyA669'
|
9
|
+
end
|
10
|
+
|
11
|
+
def check_receipt_response_format(response, options = {})
|
12
|
+
expect(response.keys).to match_array(["document_receipts", "batch_link"])
|
13
|
+
expect(response["document_receipts"]).to be_a_kind_of(Array)
|
14
|
+
expect(response["document_receipts"].first.keys).to match_array(["id", "id", "links", "status", "errors"])
|
15
|
+
expect(response["document_receipts"].first["id"]).to eq(options[:id]) if options[:id]
|
16
|
+
expect(response["document_receipts"].first["status"]).to eq(options[:status]) if options[:status]
|
17
|
+
expect(response["document_receipts"].first["errors"]).to eq(options[:errors]) if options[:errors]
|
18
|
+
end
|
19
|
+
|
20
|
+
let(:content_source_key) { '59542d332139de0acacc7dd4' }
|
21
|
+
let(:documents) do
|
22
|
+
[{'id'=>'INscMGmhmX4',
|
23
|
+
'url' => 'http://www.youtube.com/watch?v=v1uyQZNg2vE',
|
24
|
+
'title' => 'The Original Grumpy Cat',
|
25
|
+
'body' => 'this is a test'},
|
26
|
+
{'id'=>'JNDFojsd02',
|
27
|
+
'url' => 'http://www.youtube.com/watch?v=tsdfhk2j',
|
28
|
+
'title' => 'Another Grumpy Cat',
|
29
|
+
'body' => 'this is also a test'}]
|
30
|
+
end
|
31
|
+
|
32
|
+
context '#index_documents' do
|
33
|
+
it 'returns results when successful' do
|
34
|
+
VCR.use_cassette(:async_create_or_update_document_success) do
|
35
|
+
response = client.index_documents(content_source_key, documents)
|
36
|
+
expect(response.size).to eq(2)
|
37
|
+
end
|
38
|
+
end
|
39
|
+
end
|
40
|
+
|
41
|
+
context '#destroy_documents' do
|
42
|
+
it 'returns #async_create_or_update_documents format return when async has been passed as true' do
|
43
|
+
VCR.use_cassette(:async_create_or_update_document_success) do
|
44
|
+
VCR.use_cassette(:document_receipts_multiple_complete) do
|
45
|
+
client.index_documents(content_source_key, documents)
|
46
|
+
VCR.use_cassette(:destroy_documents_success) do
|
47
|
+
response = client.destroy_documents(content_source_key, [documents.first['id']])
|
48
|
+
expect(response.size).to eq(1)
|
49
|
+
expect(response.first['success']).to eq(true)
|
50
|
+
end
|
51
|
+
end
|
52
|
+
end
|
53
|
+
end
|
54
|
+
end
|
55
|
+
end
|
@@ -0,0 +1,75 @@
|
|
1
|
+
require 'spec_helper'
|
2
|
+
|
3
|
+
describe Elastic::EnterpriseSearch::Client::Permissions do
|
4
|
+
let(:client) { Elastic::EnterpriseSearch::Client.new }
|
5
|
+
|
6
|
+
before :each do
|
7
|
+
Elastic::EnterpriseSearch.access_token = 'xyT3mm3ecPsPuYxd_6fX'
|
8
|
+
end
|
9
|
+
|
10
|
+
let(:content_source_key) { '5d96387b75444bf49532c24a' }
|
11
|
+
let(:user) { 'enterprise_search' }
|
12
|
+
|
13
|
+
context '#list_all_permissions' do
|
14
|
+
it 'lists all permissions' do
|
15
|
+
VCR.use_cassette(:list_all_permissions) do
|
16
|
+
response = client.list_all_permissions(content_source_key)
|
17
|
+
expect(response['results'].size).to eq(2)
|
18
|
+
end
|
19
|
+
end
|
20
|
+
|
21
|
+
it 'lists all permissions with paging' do
|
22
|
+
VCR.use_cassette(:list_all_permissions_with_paging) do
|
23
|
+
response = client.list_all_permissions(content_source_key, :current => 2, :size => 5)
|
24
|
+
expect(response['meta']['page']['current']).to eq(2)
|
25
|
+
expect(response['meta']['page']['size']).to eq(5)
|
26
|
+
expect(response['results'].size).to eq(0)
|
27
|
+
end
|
28
|
+
end
|
29
|
+
end
|
30
|
+
|
31
|
+
context '#add_user_permissions' do
|
32
|
+
let(:permissions) { ['permission1'] }
|
33
|
+
|
34
|
+
it 'adds permissions to a user' do
|
35
|
+
VCR.use_cassette(:add_user_permissions) do
|
36
|
+
response = client.add_user_permissions(content_source_key, user, :permissions => permissions)
|
37
|
+
expect(response['permissions']).to eq(['permission1'])
|
38
|
+
end
|
39
|
+
end
|
40
|
+
end
|
41
|
+
|
42
|
+
context '#get_user_permissions' do
|
43
|
+
let(:permissions) { ['permission1'] }
|
44
|
+
|
45
|
+
it 'gets permissions for a user' do
|
46
|
+
VCR.use_cassette(:get_user_permissions) do
|
47
|
+
response = client.get_user_permissions(content_source_key, user)
|
48
|
+
expect(response['permissions']).to eq(['permission1'])
|
49
|
+
end
|
50
|
+
end
|
51
|
+
end
|
52
|
+
|
53
|
+
context '#update_user_permissions' do
|
54
|
+
let(:permissions) { ['permission2'] }
|
55
|
+
|
56
|
+
it 'updates permissions for a user' do
|
57
|
+
VCR.use_cassette(:update_user_permissions) do
|
58
|
+
response = client.update_user_permissions(content_source_key, user, :permissions => permissions)
|
59
|
+
expect(response['permissions']).to eq(['permission2'])
|
60
|
+
end
|
61
|
+
end
|
62
|
+
end
|
63
|
+
|
64
|
+
context '#remove_user_permissions' do
|
65
|
+
let(:permissions) { ['permission2'] }
|
66
|
+
|
67
|
+
it 'removes permissions from a user' do
|
68
|
+
VCR.use_cassette(:remove_user_permissions) do
|
69
|
+
response = client.remove_user_permissions(content_source_key, user, :permissions => permissions)
|
70
|
+
expect(response['permissions']).to eq([])
|
71
|
+
end
|
72
|
+
end
|
73
|
+
end
|
74
|
+
|
75
|
+
end
|
@@ -0,0 +1,55 @@
|
|
1
|
+
---
|
2
|
+
http_interactions:
|
3
|
+
- request:
|
4
|
+
method: post
|
5
|
+
uri: http://localhost:3002/api/v1/ent/sources/5d96387b75444bf49532c24a/permissions/enterprise_search/add
|
6
|
+
body:
|
7
|
+
encoding: UTF-8
|
8
|
+
string: '{"permissions":["permission1"]}'
|
9
|
+
headers:
|
10
|
+
Accept-Encoding:
|
11
|
+
- gzip;q=1.0,deflate;q=0.6,identity;q=0.3
|
12
|
+
Accept:
|
13
|
+
- "*/*"
|
14
|
+
User-Agent:
|
15
|
+
- Ruby
|
16
|
+
Content-Type:
|
17
|
+
- application/json
|
18
|
+
X-Swiftype-Client:
|
19
|
+
- elastic-enterprise-search-ruby
|
20
|
+
X-Swiftype-Client-Version:
|
21
|
+
- 0.3.0
|
22
|
+
Authorization:
|
23
|
+
- Bearer xyT3mm3ecPsPuYxd_6fX
|
24
|
+
response:
|
25
|
+
status:
|
26
|
+
code: 200
|
27
|
+
message: OK
|
28
|
+
headers:
|
29
|
+
X-Frame-Options:
|
30
|
+
- SAMEORIGIN
|
31
|
+
X-Xss-Protection:
|
32
|
+
- 1; mode=block
|
33
|
+
X-Content-Type-Options:
|
34
|
+
- nosniff
|
35
|
+
Content-Type:
|
36
|
+
- application/json; charset=utf-8
|
37
|
+
Etag:
|
38
|
+
- W/"6cb0d74ff26d6f74253df3ee283a38dd"
|
39
|
+
Cache-Control:
|
40
|
+
- max-age=0, private, must-revalidate
|
41
|
+
Set-Cookie:
|
42
|
+
- _st_frito_togo_session=KzdUM3ZvN3Z3aUIvRHNudUF0ZzJaT01EK2tNUk53akxDNVBlNWZxYVVDd3o4YlhqZXVUWjA3MWlqSlZnNzB0eFJrRW5RaUZBRFdHeVdtRnBtWUs5bWc9PS0tcEhjSk0xekxrOGRrcXNsWE83dlJrUT09--6f1c0da2f24a45042ff4492d5bac3ae214cd3731;
|
43
|
+
path=/; expires=Mon, 08 Oct 2029 18:04:32 -0000; HttpOnly
|
44
|
+
X-Request-Id:
|
45
|
+
- 616a8613-11c8-4031-8767-16f3ff735170
|
46
|
+
X-Runtime:
|
47
|
+
- '0.310198'
|
48
|
+
Transfer-Encoding:
|
49
|
+
- chunked
|
50
|
+
body:
|
51
|
+
encoding: UTF-8
|
52
|
+
string: '{"user":"enterprise_search","permissions":["permission1"]}'
|
53
|
+
http_version:
|
54
|
+
recorded_at: Tue, 08 Oct 2019 18:04:32 GMT
|
55
|
+
recorded_with: VCR 3.0.3
|
@@ -0,0 +1,55 @@
|
|
1
|
+
---
|
2
|
+
http_interactions:
|
3
|
+
- request:
|
4
|
+
method: get
|
5
|
+
uri: http://localhost:3002/api/v1/ent/sources/5d96387b75444bf49532c24a/permissions/enterprise_search
|
6
|
+
body:
|
7
|
+
encoding: US-ASCII
|
8
|
+
string: ''
|
9
|
+
headers:
|
10
|
+
Accept-Encoding:
|
11
|
+
- gzip;q=1.0,deflate;q=0.6,identity;q=0.3
|
12
|
+
Accept:
|
13
|
+
- "*/*"
|
14
|
+
User-Agent:
|
15
|
+
- Ruby
|
16
|
+
Content-Type:
|
17
|
+
- application/json
|
18
|
+
X-Swiftype-Client:
|
19
|
+
- elastic-enterprise-search-ruby
|
20
|
+
X-Swiftype-Client-Version:
|
21
|
+
- 0.3.0
|
22
|
+
Authorization:
|
23
|
+
- Bearer xyT3mm3ecPsPuYxd_6fX
|
24
|
+
response:
|
25
|
+
status:
|
26
|
+
code: 200
|
27
|
+
message: OK
|
28
|
+
headers:
|
29
|
+
X-Frame-Options:
|
30
|
+
- SAMEORIGIN
|
31
|
+
X-Xss-Protection:
|
32
|
+
- 1; mode=block
|
33
|
+
X-Content-Type-Options:
|
34
|
+
- nosniff
|
35
|
+
Content-Type:
|
36
|
+
- application/json; charset=utf-8
|
37
|
+
Etag:
|
38
|
+
- W/"6cb0d74ff26d6f74253df3ee283a38dd"
|
39
|
+
Cache-Control:
|
40
|
+
- max-age=0, private, must-revalidate
|
41
|
+
Set-Cookie:
|
42
|
+
- _st_frito_togo_session=NFJOYW80dHcxSGVmMTZTYUJaSTN4aUhKZjhtNmRhUVowN29zV3doakdJOHpyUDdzRnhoMlJJeE9nd1RvWWh0R1E1Zk1lUnhvTzNvajNUbXpmWnZIcVE9PS0tbENURG5USHgwYTZOUlcxS3lNUkdtQT09--e15485e53d7c2a3aa83288a815d1dcdfe6b9788a;
|
43
|
+
path=/; expires=Mon, 08 Oct 2029 18:04:48 -0000; HttpOnly
|
44
|
+
X-Request-Id:
|
45
|
+
- 67442386-136f-4f13-8f8e-0ac1b9ac10ce
|
46
|
+
X-Runtime:
|
47
|
+
- '0.303674'
|
48
|
+
Transfer-Encoding:
|
49
|
+
- chunked
|
50
|
+
body:
|
51
|
+
encoding: UTF-8
|
52
|
+
string: '{"user":"enterprise_search","permissions":["permission1"]}'
|
53
|
+
http_version:
|
54
|
+
recorded_at: Tue, 08 Oct 2019 18:04:48 GMT
|
55
|
+
recorded_with: VCR 3.0.3
|
@@ -0,0 +1,55 @@
|
|
1
|
+
---
|
2
|
+
http_interactions:
|
3
|
+
- request:
|
4
|
+
method: get
|
5
|
+
uri: http://localhost:3002/api/v1/ent/sources/5d96387b75444bf49532c24a/permissions?page%5Bcurrent%5D=1&page%5Bsize%5D=25
|
6
|
+
body:
|
7
|
+
encoding: US-ASCII
|
8
|
+
string: ''
|
9
|
+
headers:
|
10
|
+
Accept-Encoding:
|
11
|
+
- gzip;q=1.0,deflate;q=0.6,identity;q=0.3
|
12
|
+
Accept:
|
13
|
+
- "*/*"
|
14
|
+
User-Agent:
|
15
|
+
- Ruby
|
16
|
+
Content-Type:
|
17
|
+
- application/json
|
18
|
+
X-Swiftype-Client:
|
19
|
+
- elastic-enterprise-search-ruby
|
20
|
+
X-Swiftype-Client-Version:
|
21
|
+
- 0.3.0
|
22
|
+
Authorization:
|
23
|
+
- Bearer xyT3mm3ecPsPuYxd_6fX
|
24
|
+
response:
|
25
|
+
status:
|
26
|
+
code: 200
|
27
|
+
message: OK
|
28
|
+
headers:
|
29
|
+
X-Frame-Options:
|
30
|
+
- SAMEORIGIN
|
31
|
+
X-Xss-Protection:
|
32
|
+
- 1; mode=block
|
33
|
+
X-Content-Type-Options:
|
34
|
+
- nosniff
|
35
|
+
Content-Type:
|
36
|
+
- application/json; charset=utf-8
|
37
|
+
Etag:
|
38
|
+
- W/"5c7f433cb2ebcb5549f57098f3ceab57"
|
39
|
+
Cache-Control:
|
40
|
+
- max-age=0, private, must-revalidate
|
41
|
+
Set-Cookie:
|
42
|
+
- _st_frito_togo_session=UFpRY1dUSldpNXhOdVUxVGlGaUl3c20ybGFkVGZFemhJZGFqVjNHcDhGWWdjVVpBVDVIWENNQkVWVXJXYnRKcmxqSm1TdHY0WjRoMDNmczJvT2Yzamc9PS0tcDkzWmV3MXN4Z0labTNxMXJrbitMdz09--ed529bc01c2d5cc98d6272fa033a876b1a7e689c;
|
43
|
+
path=/; expires=Mon, 08 Oct 2029 17:56:03 -0000; HttpOnly
|
44
|
+
X-Request-Id:
|
45
|
+
- 9bee4837-355a-4486-a35f-a92d5f13f389
|
46
|
+
X-Runtime:
|
47
|
+
- '0.230366'
|
48
|
+
Transfer-Encoding:
|
49
|
+
- chunked
|
50
|
+
body:
|
51
|
+
encoding: UTF-8
|
52
|
+
string: '{"meta":{"page":{"current":1,"total_pages":1,"total_results":2,"size":25}},"results":[{"user":"elastic","permissions":[]},{"user":"enterprise_search","permissions":[]}]}'
|
53
|
+
http_version:
|
54
|
+
recorded_at: Tue, 08 Oct 2019 17:56:03 GMT
|
55
|
+
recorded_with: VCR 3.0.3
|
@@ -0,0 +1,55 @@
|
|
1
|
+
---
|
2
|
+
http_interactions:
|
3
|
+
- request:
|
4
|
+
method: get
|
5
|
+
uri: http://localhost:3002/api/v1/ent/sources/5d96387b75444bf49532c24a/permissions?page%5Bcurrent%5D=2&page%5Bsize%5D=5
|
6
|
+
body:
|
7
|
+
encoding: US-ASCII
|
8
|
+
string: ''
|
9
|
+
headers:
|
10
|
+
Accept-Encoding:
|
11
|
+
- gzip;q=1.0,deflate;q=0.6,identity;q=0.3
|
12
|
+
Accept:
|
13
|
+
- "*/*"
|
14
|
+
User-Agent:
|
15
|
+
- Ruby
|
16
|
+
Content-Type:
|
17
|
+
- application/json
|
18
|
+
X-Swiftype-Client:
|
19
|
+
- elastic-enterprise-search-ruby
|
20
|
+
X-Swiftype-Client-Version:
|
21
|
+
- 0.3.0
|
22
|
+
Authorization:
|
23
|
+
- Bearer xyT3mm3ecPsPuYxd_6fX
|
24
|
+
response:
|
25
|
+
status:
|
26
|
+
code: 200
|
27
|
+
message: OK
|
28
|
+
headers:
|
29
|
+
X-Frame-Options:
|
30
|
+
- SAMEORIGIN
|
31
|
+
X-Xss-Protection:
|
32
|
+
- 1; mode=block
|
33
|
+
X-Content-Type-Options:
|
34
|
+
- nosniff
|
35
|
+
Content-Type:
|
36
|
+
- application/json; charset=utf-8
|
37
|
+
Etag:
|
38
|
+
- W/"701f9ddd65c2586e892ac7f10050825f"
|
39
|
+
Cache-Control:
|
40
|
+
- max-age=0, private, must-revalidate
|
41
|
+
Set-Cookie:
|
42
|
+
- _st_frito_togo_session=ZXVYWkI5SFNTSm94Z29MY2thQTQvcmx4aStDenhUWkFWOVNyUWFCYWZaL3NJcDI2N21BcXJzK2h5dzNHNjd3NUdDYUNMYmgwYkNVczhjUmQ1dkd6Y2c9PS0tM3B5ciswcGlxek1QVXVjMUFsbFdPdz09--cea9576c7338c79cbd06216fe476cb63a9f6364f;
|
43
|
+
path=/; expires=Mon, 08 Oct 2029 17:58:09 -0000; HttpOnly
|
44
|
+
X-Request-Id:
|
45
|
+
- 1f924257-ed83-4715-a2f3-88be62d7d3c5
|
46
|
+
X-Runtime:
|
47
|
+
- '0.211862'
|
48
|
+
Transfer-Encoding:
|
49
|
+
- chunked
|
50
|
+
body:
|
51
|
+
encoding: UTF-8
|
52
|
+
string: '{"meta":{"page":{"current":2,"total_pages":1,"total_results":2,"size":5}},"results":[]}'
|
53
|
+
http_version:
|
54
|
+
recorded_at: Tue, 08 Oct 2019 17:58:09 GMT
|
55
|
+
recorded_with: VCR 3.0.3
|
@@ -0,0 +1,55 @@
|
|
1
|
+
---
|
2
|
+
http_interactions:
|
3
|
+
- request:
|
4
|
+
method: post
|
5
|
+
uri: http://localhost:3002/api/v1/ent/sources/5d96387b75444bf49532c24a/permissions/enterprise_search/remove
|
6
|
+
body:
|
7
|
+
encoding: UTF-8
|
8
|
+
string: '{"permissions":["permission2"]}'
|
9
|
+
headers:
|
10
|
+
Accept-Encoding:
|
11
|
+
- gzip;q=1.0,deflate;q=0.6,identity;q=0.3
|
12
|
+
Accept:
|
13
|
+
- "*/*"
|
14
|
+
User-Agent:
|
15
|
+
- Ruby
|
16
|
+
Content-Type:
|
17
|
+
- application/json
|
18
|
+
X-Swiftype-Client:
|
19
|
+
- elastic-enterprise-search-ruby
|
20
|
+
X-Swiftype-Client-Version:
|
21
|
+
- 0.3.0
|
22
|
+
Authorization:
|
23
|
+
- Bearer xyT3mm3ecPsPuYxd_6fX
|
24
|
+
response:
|
25
|
+
status:
|
26
|
+
code: 200
|
27
|
+
message: OK
|
28
|
+
headers:
|
29
|
+
X-Frame-Options:
|
30
|
+
- SAMEORIGIN
|
31
|
+
X-Xss-Protection:
|
32
|
+
- 1; mode=block
|
33
|
+
X-Content-Type-Options:
|
34
|
+
- nosniff
|
35
|
+
Content-Type:
|
36
|
+
- application/json; charset=utf-8
|
37
|
+
Etag:
|
38
|
+
- W/"eaf0aef29a99d5f9dda5844986aa3880"
|
39
|
+
Cache-Control:
|
40
|
+
- max-age=0, private, must-revalidate
|
41
|
+
Set-Cookie:
|
42
|
+
- _st_frito_togo_session=aGhGT0VyRUVVZDIzMEJMTkpjR3U5TURLR01MVFIvajlqUmtEVG85My9ZWlk3dU1OdC9nWVVnNFhIRGlTdC9Ddks4dzNoeGx6d20raFVjSUI4d0Q5NWc9PS0tT2hwcXNkZnA1T2gyUUVDcUZIWEtrUT09--0e523f810425ee9c2b201bef99048a24b7f4e5d0;
|
43
|
+
path=/; expires=Mon, 08 Oct 2029 18:04:32 -0000; HttpOnly
|
44
|
+
X-Request-Id:
|
45
|
+
- 32583732-daf1-4153-9978-f2567862b21d
|
46
|
+
X-Runtime:
|
47
|
+
- '0.295464'
|
48
|
+
Transfer-Encoding:
|
49
|
+
- chunked
|
50
|
+
body:
|
51
|
+
encoding: UTF-8
|
52
|
+
string: '{"user":"enterprise_search","permissions":[]}'
|
53
|
+
http_version:
|
54
|
+
recorded_at: Tue, 08 Oct 2019 18:04:32 GMT
|
55
|
+
recorded_with: VCR 3.0.3
|
@@ -0,0 +1,55 @@
|
|
1
|
+
---
|
2
|
+
http_interactions:
|
3
|
+
- request:
|
4
|
+
method: post
|
5
|
+
uri: http://localhost:3002/api/v1/ent/sources/5d96387b75444bf49532c24a/permissions/enterprise_search
|
6
|
+
body:
|
7
|
+
encoding: UTF-8
|
8
|
+
string: '{"permissions":["permission2"]}'
|
9
|
+
headers:
|
10
|
+
Accept-Encoding:
|
11
|
+
- gzip;q=1.0,deflate;q=0.6,identity;q=0.3
|
12
|
+
Accept:
|
13
|
+
- "*/*"
|
14
|
+
User-Agent:
|
15
|
+
- Ruby
|
16
|
+
Content-Type:
|
17
|
+
- application/json
|
18
|
+
X-Swiftype-Client:
|
19
|
+
- elastic-enterprise-search-ruby
|
20
|
+
X-Swiftype-Client-Version:
|
21
|
+
- 0.3.0
|
22
|
+
Authorization:
|
23
|
+
- Bearer xyT3mm3ecPsPuYxd_6fX
|
24
|
+
response:
|
25
|
+
status:
|
26
|
+
code: 200
|
27
|
+
message: OK
|
28
|
+
headers:
|
29
|
+
X-Frame-Options:
|
30
|
+
- SAMEORIGIN
|
31
|
+
X-Xss-Protection:
|
32
|
+
- 1; mode=block
|
33
|
+
X-Content-Type-Options:
|
34
|
+
- nosniff
|
35
|
+
Content-Type:
|
36
|
+
- application/json; charset=utf-8
|
37
|
+
Etag:
|
38
|
+
- W/"d9b34b6591f5971aeb0f3d706560e171"
|
39
|
+
Cache-Control:
|
40
|
+
- max-age=0, private, must-revalidate
|
41
|
+
Set-Cookie:
|
42
|
+
- _st_frito_togo_session=VXFPc0pKQitCSkcvb2c4Wjl3ZEx2YXRTL1NXWW5KbHVwdHhIcEVpd3lJS3orVVM3eVV0UVo1bTJ5MGFxQXhMQjZCM3VOZmV3bDl5NHl1a3ZkV2UxOHc9PS0tc2Nma0NRR0FmcWs0S0tJdFBxUXF3UT09--97d427ee534c30c51d1770571623a1d361b61b6f;
|
43
|
+
path=/; expires=Mon, 08 Oct 2029 18:04:31 -0000; HttpOnly
|
44
|
+
X-Request-Id:
|
45
|
+
- 9404a936-7a58-4412-8ab8-e08f71a0380c
|
46
|
+
X-Runtime:
|
47
|
+
- '0.388014'
|
48
|
+
Transfer-Encoding:
|
49
|
+
- chunked
|
50
|
+
body:
|
51
|
+
encoding: UTF-8
|
52
|
+
string: '{"user":"enterprise_search","permissions":["permission2"]}'
|
53
|
+
http_version:
|
54
|
+
recorded_at: Tue, 08 Oct 2019 18:04:31 GMT
|
55
|
+
recorded_with: VCR 3.0.3
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: elastic-enterprise-search
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.
|
4
|
+
version: 0.3.0
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Quin Hoxie
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2019-
|
11
|
+
date: 2019-10-17 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: rspec
|
@@ -86,16 +86,25 @@ files:
|
|
86
86
|
- lib/elastic-enterprise-search.rb
|
87
87
|
- lib/elastic/enterprise-search.rb
|
88
88
|
- lib/elastic/enterprise-search/client.rb
|
89
|
+
- lib/elastic/enterprise-search/client/content_source_documents.rb
|
90
|
+
- lib/elastic/enterprise-search/client/permissions.rb
|
89
91
|
- lib/elastic/enterprise-search/configuration.rb
|
90
92
|
- lib/elastic/enterprise-search/exceptions.rb
|
91
93
|
- lib/elastic/enterprise-search/request.rb
|
92
94
|
- lib/elastic/enterprise-search/utils.rb
|
93
95
|
- lib/elastic/enterprise-search/version.rb
|
94
96
|
- logo-enterprise-search.png
|
95
|
-
- spec/
|
97
|
+
- spec/client/content_source_documents_spec.rb
|
98
|
+
- spec/client/permissions_spec.rb
|
96
99
|
- spec/configuration_spec.rb
|
100
|
+
- spec/fixtures/vcr/add_user_permissions.yml
|
97
101
|
- spec/fixtures/vcr/async_create_or_update_document_success.yml
|
98
102
|
- spec/fixtures/vcr/destroy_documents_success.yml
|
103
|
+
- spec/fixtures/vcr/get_user_permissions.yml
|
104
|
+
- spec/fixtures/vcr/list_all_permissions.yml
|
105
|
+
- spec/fixtures/vcr/list_all_permissions_with_paging.yml
|
106
|
+
- spec/fixtures/vcr/remove_user_permissions.yml
|
107
|
+
- spec/fixtures/vcr/update_user_permissions.yml
|
99
108
|
- spec/spec_helper.rb
|
100
109
|
homepage: https://github.com/elastic/enterprise-search-ruby
|
101
110
|
licenses:
|
@@ -116,14 +125,20 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
116
125
|
- !ruby/object:Gem::Version
|
117
126
|
version: '0'
|
118
127
|
requirements: []
|
119
|
-
|
120
|
-
rubygems_version: 2.7.6
|
128
|
+
rubygems_version: 3.0.4
|
121
129
|
signing_key:
|
122
130
|
specification_version: 4
|
123
131
|
summary: Official gem for accessing the Elastic Enterprise Search API
|
124
132
|
test_files:
|
125
|
-
- spec/
|
133
|
+
- spec/client/content_source_documents_spec.rb
|
134
|
+
- spec/client/permissions_spec.rb
|
126
135
|
- spec/configuration_spec.rb
|
136
|
+
- spec/fixtures/vcr/add_user_permissions.yml
|
127
137
|
- spec/fixtures/vcr/async_create_or_update_document_success.yml
|
128
138
|
- spec/fixtures/vcr/destroy_documents_success.yml
|
139
|
+
- spec/fixtures/vcr/get_user_permissions.yml
|
140
|
+
- spec/fixtures/vcr/list_all_permissions.yml
|
141
|
+
- spec/fixtures/vcr/list_all_permissions_with_paging.yml
|
142
|
+
- spec/fixtures/vcr/remove_user_permissions.yml
|
143
|
+
- spec/fixtures/vcr/update_user_permissions.yml
|
129
144
|
- spec/spec_helper.rb
|
data/spec/client_spec.rb
DELETED
@@ -1,57 +0,0 @@
|
|
1
|
-
require 'spec_helper'
|
2
|
-
|
3
|
-
describe Elastic::EnterpriseSearch::Client do
|
4
|
-
let(:engine_slug) { 'enterprise-search-api-example' }
|
5
|
-
let(:client) { Elastic::EnterpriseSearch::Client.new }
|
6
|
-
|
7
|
-
before :each do
|
8
|
-
Elastic::EnterpriseSearch.access_token = 'cGUN-vBokevBhhzyA669'
|
9
|
-
end
|
10
|
-
|
11
|
-
context 'ContentSourceDocuments' do
|
12
|
-
def check_receipt_response_format(response, options = {})
|
13
|
-
expect(response.keys).to match_array(["document_receipts", "batch_link"])
|
14
|
-
expect(response["document_receipts"]).to be_a_kind_of(Array)
|
15
|
-
expect(response["document_receipts"].first.keys).to match_array(["id", "id", "links", "status", "errors"])
|
16
|
-
expect(response["document_receipts"].first["id"]).to eq(options[:id]) if options[:id]
|
17
|
-
expect(response["document_receipts"].first["status"]).to eq(options[:status]) if options[:status]
|
18
|
-
expect(response["document_receipts"].first["errors"]).to eq(options[:errors]) if options[:errors]
|
19
|
-
end
|
20
|
-
|
21
|
-
let(:content_source_key) { '59542d332139de0acacc7dd4' }
|
22
|
-
let(:documents) do
|
23
|
-
[{'id'=>'INscMGmhmX4',
|
24
|
-
'url' => 'http://www.youtube.com/watch?v=v1uyQZNg2vE',
|
25
|
-
'title' => 'The Original Grumpy Cat',
|
26
|
-
'body' => 'this is a test'},
|
27
|
-
{'id'=>'JNDFojsd02',
|
28
|
-
'url' => 'http://www.youtube.com/watch?v=tsdfhk2j',
|
29
|
-
'title' => 'Another Grumpy Cat',
|
30
|
-
'body' => 'this is also a test'}]
|
31
|
-
end
|
32
|
-
|
33
|
-
context '#index_documents' do
|
34
|
-
it 'returns results when successful' do
|
35
|
-
VCR.use_cassette(:async_create_or_update_document_success) do
|
36
|
-
response = client.index_documents(content_source_key, documents)
|
37
|
-
expect(response.size).to eq(2)
|
38
|
-
end
|
39
|
-
end
|
40
|
-
end
|
41
|
-
|
42
|
-
context '#destroy_documents' do
|
43
|
-
it 'returns #async_create_or_update_documents format return when async has been passed as true' do
|
44
|
-
VCR.use_cassette(:async_create_or_update_document_success) do
|
45
|
-
VCR.use_cassette(:document_receipts_multiple_complete) do
|
46
|
-
client.index_documents(content_source_key, documents)
|
47
|
-
VCR.use_cassette(:destroy_documents_success) do
|
48
|
-
response = client.destroy_documents(content_source_key, [documents.first['id']])
|
49
|
-
expect(response.size).to eq(1)
|
50
|
-
expect(response.first['success']).to eq(true)
|
51
|
-
end
|
52
|
-
end
|
53
|
-
end
|
54
|
-
end
|
55
|
-
end
|
56
|
-
end
|
57
|
-
end
|