swiftype-enterprise 2.0.0 → 3.0.0

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
- SHA256:
3
- metadata.gz: f4ca1438be2d0d405b2636dee9f8f3246a172363520954ab8f657cea15c437af
4
- data.tar.gz: 993f393f196d9ebc0205f8ef25a322c5dbc0eca5d3bfc8d3382ef0c303c104f4
2
+ SHA1:
3
+ metadata.gz: 0d73928e6d01ff6eec555c4579ec5dd576b64e39
4
+ data.tar.gz: d6de4d034cf9fd60ed7578cb888b145b15c28237
5
5
  SHA512:
6
- metadata.gz: 0a9b55da2d0ddd9fb92a28268561f0c645e16702b1c91ace38533d86a85835223e84b1b6f02fed4718402733d3345452fd12a01ccf5826a8bf83887d2693a73e
7
- data.tar.gz: d61bc6a04940221f82ecb0f5d681c454554398f3a73cd362b0b2ba403795c5090f952c51b23fa0960fd9d290d2ad863035d8185e9bfd71b1a1f042efd6caa992
6
+ metadata.gz: 006d6f3aeec117d7323e02517590e88f608efcdf45bb687e1f5013fcf6b6050484837e18650725053954c14790cb5e2103b8e73448d84cdcc4de3a5da919c0a5
7
+ data.tar.gz: 5603ef92625268c22c1fc007713e64b5590458a823c042e71d2ca80c4b27db8520aa869d81aec39ba58c1635f9125c0420c54ebc810517e5c41e7e4c3030fc83
data/README.md CHANGED
@@ -31,6 +31,14 @@ Create a new instance of the Swiftype Enterprise Client with your access token:
31
31
  SwiftypeEnterprise.access_token = '' # your access token
32
32
  swiftype = SwiftypeEnterprise::Client.new
33
33
 
34
+ ### Change API endpoint
35
+
36
+ ```
37
+ swiftype = SwiftypeEnterprise::Client.new
38
+ SwiftypeEnterprise.endpoint = 'https://your-server.example.com/api/v1'
39
+ ```
40
+
41
+
34
42
  ### Indexing Documents
35
43
 
36
44
  This example shows how to use the index_documents method:
@@ -38,13 +46,13 @@ This example shows how to use the index_documents method:
38
46
  content_source_key = '' # your content source key
39
47
  documents = [
40
48
  {
41
- 'external_id' => 'INscMGmhmX4',
49
+ 'id' => 'INscMGmhmX4',
42
50
  'url' => 'http://www.youtube.com/watch?v=v1uyQZNg2vE',
43
51
  'title' => 'The Original Grumpy Cat',
44
52
  'body' => 'this is a test'
45
53
  },
46
54
  {
47
- 'external_id' => 'JNDFojsd02',
55
+ 'id' => 'JNDFojsd02',
48
56
  'url' => 'http://www.youtube.com/watch?v=tsdfhk2j',
49
57
  'title' => 'Another Grumpy Cat',
50
58
  'body' => 'this is also a test'
@@ -61,10 +69,10 @@ This example shows how to use the index_documents method:
61
69
  ### Destroying Documents
62
70
 
63
71
  content_source_key = '' # your content source key
64
- document_external_ids = ['INscMGmhmX4', 'JNDFojsd02']
72
+ document_ids = ['INscMGmhmX4', 'JNDFojsd02']
65
73
 
66
74
  begin
67
- destroy_document_results = swiftype.destroy_documents(content_source_key, document_external_ids)
75
+ destroy_document_results = swiftype.destroy_documents(content_source_key, document_ids)
68
76
  # handle destroy document results
69
77
  rescue SwiftypeEnterprise::ClientException => e
70
78
  # handle error
@@ -41,18 +41,6 @@ module SwiftypeEnterprise
41
41
  #
42
42
  # For more information on indexing documents, see the {Content Source documentation}[https://app.swiftype.com/ent/docs/custom_sources].
43
43
  module ContentSourceDocuments
44
- REQUIRED_TOP_LEVEL_KEYS = [
45
- 'external_id',
46
- 'url',
47
- 'title',
48
- 'body'
49
- ].map!(&:freeze).to_set.freeze
50
- OPTIONAL_TOP_LEVEL_KEYS = [
51
- 'created_at',
52
- 'updated_at',
53
- 'type',
54
- ].map!(&:freeze).to_set.freeze
55
- CORE_TOP_LEVEL_KEYS = (REQUIRED_TOP_LEVEL_KEYS + OPTIONAL_TOP_LEVEL_KEYS).freeze
56
44
 
57
45
  # Index a batch of documents using the {Content Source API}[https://app.swiftype.com/ent/docs/custom_sources].
58
46
  #
@@ -64,7 +52,7 @@ module SwiftypeEnterprise
64
52
  # @raise [SwiftypeEnterprise::InvalidDocument] when a single document is missing required fields or contains unsupported fields
65
53
  # @raise [Timeout::Error] when timeout expires waiting for results
66
54
  def index_documents(content_source_key, documents)
67
- documents = Array(documents).map! { |document| validate_and_normalize_document(document) }
55
+ documents = Array(documents).map! { |document| normalize_document(document) }
68
56
 
69
57
  async_create_or_update_documents(content_source_key, documents)
70
58
  end
@@ -87,16 +75,8 @@ module SwiftypeEnterprise
87
75
  post("ent/sources/#{content_source_key}/documents/bulk_create.json", documents)
88
76
  end
89
77
 
90
- def validate_and_normalize_document(document)
91
- document = Utils.stringify_keys(document)
92
- document_keys = document.keys.to_set
93
- missing_keys = REQUIRED_TOP_LEVEL_KEYS - document_keys
94
- raise SwiftypeEnterprise::InvalidDocument.new("missing required fields (#{missing_keys.to_a.join(', ')})") if missing_keys.any?
95
-
96
- surplus_keys = document_keys - CORE_TOP_LEVEL_KEYS
97
- raise SwiftypeEnterprise::InvalidDocument.new("unsupported fields supplied (#{surplus_keys.to_a.join(', ')}), supported fields are (#{CORE_TOP_LEVEL_KEYS.to_a.join(', ')})") if surplus_keys.any?
98
-
99
- document
78
+ def normalize_document(document)
79
+ Utils.stringify_keys(document)
100
80
  end
101
81
  end
102
82
 
@@ -3,7 +3,7 @@ require 'swiftype-enterprise/version'
3
3
 
4
4
  module SwiftypeEnterprise
5
5
  module Configuration
6
- DEFAULT_ENDPOINT = "https://api.swiftype.com/api/v1/"
6
+ DEFAULT_ENDPOINT = "http://localhost:3002/api/v1/"
7
7
  DEFAULT_USER_AGENT = "swiftype-enterprise-ruby/#{SwiftypeEnterprise::VERSION}"
8
8
 
9
9
  VALID_OPTIONS_KEYS = [
@@ -1,3 +1,3 @@
1
1
  module SwiftypeEnterprise
2
- VERSION = '2.0.0'
2
+ VERSION = '3.0.0'
3
3
  end
data/spec/client_spec.rb CHANGED
@@ -12,19 +12,19 @@ describe SwiftypeEnterprise::Client do
12
12
  def check_receipt_response_format(response, options = {})
13
13
  expect(response.keys).to match_array(["document_receipts", "batch_link"])
14
14
  expect(response["document_receipts"]).to be_a_kind_of(Array)
15
- expect(response["document_receipts"].first.keys).to match_array(["id", "external_id", "links", "status", "errors"])
16
- expect(response["document_receipts"].first["external_id"]).to eq(options[:external_id]) if options[:external_id]
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
17
  expect(response["document_receipts"].first["status"]).to eq(options[:status]) if options[:status]
18
18
  expect(response["document_receipts"].first["errors"]).to eq(options[:errors]) if options[:errors]
19
19
  end
20
20
 
21
21
  let(:content_source_key) { '59542d332139de0acacc7dd4' }
22
22
  let(:documents) do
23
- [{'external_id'=>'INscMGmhmX4',
23
+ [{'id'=>'INscMGmhmX4',
24
24
  'url' => 'http://www.youtube.com/watch?v=v1uyQZNg2vE',
25
25
  'title' => 'The Original Grumpy Cat',
26
26
  'body' => 'this is a test'},
27
- {'external_id'=>'JNDFojsd02',
27
+ {'id'=>'JNDFojsd02',
28
28
  'url' => 'http://www.youtube.com/watch?v=tsdfhk2j',
29
29
  'title' => 'Another Grumpy Cat',
30
30
  'body' => 'this is also a test'}]
@@ -45,7 +45,7 @@ describe SwiftypeEnterprise::Client do
45
45
  VCR.use_cassette(:document_receipts_multiple_complete) do
46
46
  client.index_documents(content_source_key, documents)
47
47
  VCR.use_cassette(:destroy_documents_success) do
48
- response = client.destroy_documents(content_source_key, [documents.first['external_id']])
48
+ response = client.destroy_documents(content_source_key, [documents.first['id']])
49
49
  expect(response.size).to eq(1)
50
50
  expect(response.first['success']).to eq(true)
51
51
  end
@@ -5,8 +5,8 @@ http_interactions:
5
5
  uri: http://localhost:3002/api/v1/ent/sources/59542d332139de0acacc7dd4/documents/bulk_create.json
6
6
  body:
7
7
  encoding: UTF-8
8
- string: '[{"external_id":"INscMGmhmX4","url":"http://www.youtube.com/watch?v=v1uyQZNg2vE","title":"The
9
- Original Grumpy Cat","body":"this is a test"},{"external_id":"JNDFojsd02","url":"http://www.youtube.com/watch?v=tsdfhk2j","title":"Another
8
+ string: '[{"id":"INscMGmhmX4","url":"http://www.youtube.com/watch?v=v1uyQZNg2vE","title":"The
9
+ Original Grumpy Cat","body":"this is a test"},{"id":"JNDFojsd02","url":"http://www.youtube.com/watch?v=tsdfhk2j","title":"Another
10
10
  Grumpy Cat","body":"this is also a test"}]'
11
11
  headers:
12
12
  Accept-Encoding:
@@ -47,7 +47,7 @@ http_interactions:
47
47
  - thin 1.5.0 codename Knife
48
48
  body:
49
49
  encoding: UTF-8
50
- string: '[{"id":null,"external_id":"1234","errors":[]},{"id":null,"external_id":"1235","errors":[]}]'
50
+ string: '[{"id":null,"id":"1234","errors":[]},{"id":null,"id":"1235","errors":[]}]'
51
51
  http_version:
52
52
  recorded_at: Wed, 05 Jul 2017 17:52:09 GMT
53
53
  recorded_with: VCR 3.0.3
@@ -47,7 +47,7 @@ http_interactions:
47
47
  - thin 1.5.0 codename Knife
48
48
  body:
49
49
  encoding: UTF-8
50
- string: '[{"external_id":"INscMGmhmX4","success":true}]'
51
- http_version:
50
+ string: '[{"id":"INscMGmhmX4","success":true}]'
51
+ http_version:
52
52
  recorded_at: Wed, 05 Jul 2017 17:52:12 GMT
53
53
  recorded_with: VCR 3.0.3
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: swiftype-enterprise
3
3
  version: !ruby/object:Gem::Version
4
- version: 2.0.0
4
+ version: 3.0.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-05-03 00:00:00.000000000 Z
11
+ date: 2019-07-25 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: rspec
@@ -114,7 +114,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
114
114
  version: '0'
115
115
  requirements: []
116
116
  rubyforge_project:
117
- rubygems_version: 2.7.6
117
+ rubygems_version: 2.5.2.3
118
118
  signing_key:
119
119
  specification_version: 4
120
120
  summary: Official gem for accessing the Swiftype Enterprise API