typesense 0.2.0 → 0.4.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.
@@ -9,9 +9,10 @@ module Typesense
9
9
 
10
10
  def initialize(options = {})
11
11
  @configuration = Configuration.new(options)
12
- @collections = Collections.new(@configuration)
13
- @aliases = Aliases.new(@configuration)
14
- @debug = Debug.new(@configuration)
12
+ @api_call = ApiCall.new(@configuration)
13
+ @collections = Collections.new(@api_call)
14
+ @aliases = Aliases.new(@api_call)
15
+ @debug = Debug.new(@api_call)
15
16
  end
16
17
  end
17
18
  end
@@ -5,19 +5,19 @@ module Typesense
5
5
  attr_reader :documents
6
6
  attr_reader :overrides
7
7
 
8
- def initialize(configuration, name)
9
- @configuration = configuration
10
- @name = name
11
- @documents = Documents.new(@configuration, @name)
12
- @overrides = Overrides.new(@configuration, @name)
8
+ def initialize(name, api_call)
9
+ @name = name
10
+ @api_call = api_call
11
+ @documents = Documents.new(@name, @api_call)
12
+ @overrides = Overrides.new(@name, @api_call)
13
13
  end
14
14
 
15
15
  def retrieve
16
- ApiCall.new(@configuration).get(endpoint_path)
16
+ @api_call.get(endpoint_path)
17
17
  end
18
18
 
19
19
  def delete
20
- ApiCall.new(@configuration).delete(endpoint_path)
20
+ @api_call.delete(endpoint_path)
21
21
  end
22
22
 
23
23
  private
@@ -4,21 +4,21 @@ module Typesense
4
4
  class Collections
5
5
  RESOURCE_PATH = '/collections'
6
6
 
7
- def initialize(configuration)
8
- @configuration = configuration
9
- @collections = {}
7
+ def initialize(api_call)
8
+ @api_call = api_call
9
+ @collections = {}
10
10
  end
11
11
 
12
12
  def create(schema)
13
- ApiCall.new(@configuration).post(RESOURCE_PATH, schema)
13
+ @api_call.post(RESOURCE_PATH, schema)
14
14
  end
15
15
 
16
16
  def retrieve
17
- ApiCall.new(@configuration).get(RESOURCE_PATH)
17
+ @api_call.get(RESOURCE_PATH)
18
18
  end
19
19
 
20
20
  def [](collection_name)
21
- @collections[collection_name] ||= Collection.new(@configuration, collection_name)
21
+ @collections[collection_name] ||= Collection.new(collection_name, @api_call)
22
22
  end
23
23
  end
24
24
  end
@@ -2,37 +2,53 @@
2
2
 
3
3
  module Typesense
4
4
  class Configuration
5
- attr_accessor :master_node
6
- attr_accessor :read_replica_nodes
7
- attr_accessor :timeout_seconds
5
+ attr_accessor :nodes
6
+ attr_accessor :nearest_node
7
+ attr_accessor :connection_timeout_seconds
8
+ attr_accessor :healthcheck_interval_seconds
9
+ attr_accessor :num_retries
10
+ attr_accessor :retry_interval_seconds
11
+ attr_accessor :api_key
12
+ attr_accessor :logger
13
+ attr_accessor :log_level
8
14
 
9
15
  def initialize(options = {})
10
- @master_node = options[:master_node] || {
11
- host: 'localhost',
12
- port: '8108',
13
- protocol: 'http'
14
- }
15
-
16
- @read_replica_nodes = options[:read_replica_nodes] || []
17
- @timeout_seconds = options[:timeout_seconds] || 10
16
+ @nodes = options[:nodes] || []
17
+ @nearest_node = options[:nearest_node]
18
+ @connection_timeout_seconds = options[:connection_timeout_seconds] || options[:timeout_seconds] || 10
19
+ @healthcheck_interval_seconds = options[:healthcheck_interval_seconds] || 15
20
+ @num_retries = options[:num_retries] || @nodes.length + (@nearest_node.nil? ? 0 : 1) || 3
21
+ @retry_interval_seconds = options[:retry_interval_seconds] || 0.1
22
+ @api_key = options[:api_key]
23
+
24
+ @logger = options[:logger] || Logger.new(STDOUT)
25
+ @log_level = options[:log_level] || Logger::WARN
26
+ @logger.level = @log_level
27
+
28
+ show_deprecation_warnings(options)
29
+ validate!
18
30
  end
19
31
 
20
32
  def validate!
21
- if @master_node.nil? ||
22
- node_missing_parameters?(@master_node)
23
- raise Error::MissingConfiguration, 'Missing required configuration. Ensure that master_node[:protocol], master_node[:host], master_node[:port] and master_node[:api_key] are set.'
33
+ if @nodes.nil? ||
34
+ @nodes.empty? ||
35
+ @nodes.any? { |node| node_missing_parameters?(node) }
36
+ raise Error::MissingConfiguration, 'Missing required configuration. Ensure that nodes[][:protocol], nodes[][:host] and nodes[][:port] are set.'
24
37
  end
25
38
 
26
- if !@read_replica_nodes.nil? &&
27
- @read_replica_nodes.any? { |node| node_missing_parameters?(node) }
28
- raise Error::MissingConfiguration, 'Missing required configuration for read_replica_nodes. Ensure that read_replica_nodes[][:protocol], read_replica_nodes[][:host], read_replica_nodes[][:port] and read_replica_nodes[][:api_key] are set.'
29
- end
39
+ raise Error::MissingConfiguration, 'Missing required configuration. Ensure that api_key is set.' if @api_key.nil?
30
40
  end
31
41
 
32
42
  private
33
43
 
34
44
  def node_missing_parameters?(node)
35
- %i[protocol host port api_key].any? { |attr| node.send(:[], attr).nil? }
45
+ %i[protocol host port].any? { |attr| node.send(:[], attr).nil? }
46
+ end
47
+
48
+ def show_deprecation_warnings(options)
49
+ @logger.warn 'Deprecation warning: timeout_seconds is now renamed to connection_timeout_seconds' unless options[:timeout_seconds].nil?
50
+ @logger.warn 'Deprecation warning: master_node is now consolidated to nodes, starting with Typesense Server v0.12' unless options[:master_node].nil?
51
+ @logger.warn 'Deprecation warning: read_replica_nodes is now consolidated to nodes, starting with Typesense Server v0.12' unless options[:read_replica_nodes].nil?
36
52
  end
37
53
  end
38
54
  end
@@ -4,12 +4,12 @@ module Typesense
4
4
  class Debug
5
5
  RESOURCE_PATH = '/debug'
6
6
 
7
- def initialize(configuration)
8
- @configuration = configuration
7
+ def initialize(api_call)
8
+ @api_call = api_call
9
9
  end
10
10
 
11
11
  def retrieve
12
- ApiCall.new(@configuration).get(RESOURCE_PATH)
12
+ @api_call.get(RESOURCE_PATH)
13
13
  end
14
14
  end
15
15
  end
@@ -2,18 +2,18 @@
2
2
 
3
3
  module Typesense
4
4
  class Document
5
- def initialize(configuration, collection_name, document_id)
6
- @configuration = configuration
5
+ def initialize(collection_name, document_id, api_call)
7
6
  @collection_name = collection_name
8
7
  @document_id = document_id
8
+ @api_call = api_call
9
9
  end
10
10
 
11
11
  def retrieve
12
- ApiCall.new(@configuration).get(endpoint_path)
12
+ @api_call.get(endpoint_path)
13
13
  end
14
14
 
15
15
  def delete
16
- ApiCall.new(@configuration).delete(endpoint_path)
16
+ @api_call.delete(endpoint_path)
17
17
  end
18
18
 
19
19
  private
@@ -4,26 +4,31 @@ module Typesense
4
4
  class Documents
5
5
  RESOURCE_PATH = '/documents'
6
6
 
7
- def initialize(configuration, collection_name)
8
- @configuration = configuration
7
+ def initialize(collection_name, api_call)
9
8
  @collection_name = collection_name
9
+ @api_call = api_call
10
10
  @documents = {}
11
11
  end
12
12
 
13
13
  def create(document)
14
- ApiCall.new(@configuration).post(endpoint_path, document)
14
+ @api_call.post(endpoint_path, document)
15
+ end
16
+
17
+ def create_many(documents)
18
+ documents_in_jsonl_format = documents.map { |document| JSON.dump(document) }.join("\n")
19
+ @api_call.post(endpoint_path('import'), as_json: false, body: documents_in_jsonl_format)
15
20
  end
16
21
 
17
22
  def export
18
- ApiCall.new(@configuration).get_unparsed_response(endpoint_path('export')).split("\n")
23
+ (@api_call.get(endpoint_path('export')) || '').split("\n")
19
24
  end
20
25
 
21
26
  def search(search_parameters)
22
- ApiCall.new(@configuration).get(endpoint_path('search'), search_parameters)
27
+ @api_call.get(endpoint_path('search'), search_parameters)
23
28
  end
24
29
 
25
30
  def [](document_id)
26
- @documents[document_id] ||= Document.new(@configuration, @collection_name, document_id)
31
+ @documents[document_id] ||= Document.new(@collection_name, document_id, @api_call)
27
32
  end
28
33
 
29
34
  private
@@ -23,7 +23,13 @@ module Typesense
23
23
  class ServerError < Error
24
24
  end
25
25
 
26
+ class HTTPStatus0Error < Error
27
+ end
28
+
26
29
  class NoMethodError < ::NoMethodError
27
30
  end
31
+
32
+ class HTTPError < Error
33
+ end
28
34
  end
29
35
  end
@@ -2,18 +2,18 @@
2
2
 
3
3
  module Typesense
4
4
  class Override
5
- def initialize(configuration, collection_name, override_id)
6
- @configuration = configuration
5
+ def initialize(collection_name, override_id, api_call)
7
6
  @collection_name = collection_name
8
7
  @override_id = override_id
8
+ @api_call = api_call
9
9
  end
10
10
 
11
11
  def retrieve
12
- ApiCall.new(@configuration).get(endpoint_path)
12
+ @api_call.get(endpoint_path)
13
13
  end
14
14
 
15
15
  def delete
16
- ApiCall.new(@configuration).delete(endpoint_path)
16
+ @api_call.delete(endpoint_path)
17
17
  end
18
18
 
19
19
  private
@@ -4,22 +4,22 @@ module Typesense
4
4
  class Overrides
5
5
  RESOURCE_PATH = '/overrides'
6
6
 
7
- def initialize(configuration, collection_name)
8
- @configuration = configuration
7
+ def initialize(collection_name, api_call)
9
8
  @collection_name = collection_name
9
+ @api_call = api_call
10
10
  @overrides = {}
11
11
  end
12
12
 
13
13
  def create(params)
14
- ApiCall.new(@configuration).put(endpoint_path, params)
14
+ @api_call.put(endpoint_path, params)
15
15
  end
16
16
 
17
17
  def retrieve
18
- ApiCall.new(@configuration).get(endpoint_path)
18
+ @api_call.get(endpoint_path)
19
19
  end
20
20
 
21
21
  def [](override_id)
22
- @overrides[override_id] ||= Override.new(@configuration, @collection_name, override_id)
22
+ @overrides[override_id] ||= Override.new(@collection_name, override_id, @api_call)
23
23
  end
24
24
 
25
25
  private
@@ -1,5 +1,5 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  module Typesense
4
- VERSION = '0.2.0'
4
+ VERSION = '0.4.0'
5
5
  end
data/typesense.gemspec CHANGED
@@ -25,15 +25,16 @@ Gem::Specification.new do |spec|
25
25
  spec.add_development_dependency 'awesome_print', '~> 1.8'
26
26
  spec.add_development_dependency 'bundler', '~> 2.0'
27
27
  spec.add_development_dependency 'codecov', '~> 0.1'
28
- spec.add_development_dependency 'pry-byebug', '~> 3.7'
28
+ spec.add_development_dependency 'pry-byebug', '~> 3.9'
29
29
  spec.add_development_dependency 'rake', '~> 13.0'
30
30
  spec.add_development_dependency 'rspec', '~> 3.9'
31
31
  spec.add_development_dependency 'rspec-legacy_formatters', '~> 1.0' # For codecov formatter
32
32
  spec.add_development_dependency 'rspec_junit_formatter', '~> 0.4'
33
- spec.add_development_dependency 'rubocop', '~> 0.76'
34
- spec.add_development_dependency 'rubocop-rspec', '~> 1.36'
35
- spec.add_development_dependency 'simplecov', '~> 0.17'
36
- spec.add_development_dependency 'webmock', '~> 3.7'
33
+ spec.add_development_dependency 'rubocop', '~> 0.83'
34
+ spec.add_development_dependency 'rubocop-rspec', '~> 1.39'
35
+ spec.add_development_dependency 'simplecov', '~> 0.18'
36
+ spec.add_development_dependency 'timecop', '~> 0.9'
37
+ spec.add_development_dependency 'webmock', '~> 3.8'
37
38
 
38
- spec.add_dependency 'httparty', '~> 0.17'
39
+ spec.add_dependency 'httparty', '~> 0.18'
39
40
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: typesense
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.2.0
4
+ version: 0.4.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Typesense, Inc.
8
8
  autorequire:
9
9
  bindir: exe
10
10
  cert_chain: []
11
- date: 2019-11-04 00:00:00.000000000 Z
11
+ date: 2020-05-23 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: awesome_print
@@ -58,14 +58,14 @@ dependencies:
58
58
  requirements:
59
59
  - - "~>"
60
60
  - !ruby/object:Gem::Version
61
- version: '3.7'
61
+ version: '3.9'
62
62
  type: :development
63
63
  prerelease: false
64
64
  version_requirements: !ruby/object:Gem::Requirement
65
65
  requirements:
66
66
  - - "~>"
67
67
  - !ruby/object:Gem::Version
68
- version: '3.7'
68
+ version: '3.9'
69
69
  - !ruby/object:Gem::Dependency
70
70
  name: rake
71
71
  requirement: !ruby/object:Gem::Requirement
@@ -128,70 +128,84 @@ dependencies:
128
128
  requirements:
129
129
  - - "~>"
130
130
  - !ruby/object:Gem::Version
131
- version: '0.76'
131
+ version: '0.83'
132
132
  type: :development
133
133
  prerelease: false
134
134
  version_requirements: !ruby/object:Gem::Requirement
135
135
  requirements:
136
136
  - - "~>"
137
137
  - !ruby/object:Gem::Version
138
- version: '0.76'
138
+ version: '0.83'
139
139
  - !ruby/object:Gem::Dependency
140
140
  name: rubocop-rspec
141
141
  requirement: !ruby/object:Gem::Requirement
142
142
  requirements:
143
143
  - - "~>"
144
144
  - !ruby/object:Gem::Version
145
- version: '1.36'
145
+ version: '1.39'
146
146
  type: :development
147
147
  prerelease: false
148
148
  version_requirements: !ruby/object:Gem::Requirement
149
149
  requirements:
150
150
  - - "~>"
151
151
  - !ruby/object:Gem::Version
152
- version: '1.36'
152
+ version: '1.39'
153
153
  - !ruby/object:Gem::Dependency
154
154
  name: simplecov
155
155
  requirement: !ruby/object:Gem::Requirement
156
156
  requirements:
157
157
  - - "~>"
158
158
  - !ruby/object:Gem::Version
159
- version: '0.17'
159
+ version: '0.18'
160
+ type: :development
161
+ prerelease: false
162
+ version_requirements: !ruby/object:Gem::Requirement
163
+ requirements:
164
+ - - "~>"
165
+ - !ruby/object:Gem::Version
166
+ version: '0.18'
167
+ - !ruby/object:Gem::Dependency
168
+ name: timecop
169
+ requirement: !ruby/object:Gem::Requirement
170
+ requirements:
171
+ - - "~>"
172
+ - !ruby/object:Gem::Version
173
+ version: '0.9'
160
174
  type: :development
161
175
  prerelease: false
162
176
  version_requirements: !ruby/object:Gem::Requirement
163
177
  requirements:
164
178
  - - "~>"
165
179
  - !ruby/object:Gem::Version
166
- version: '0.17'
180
+ version: '0.9'
167
181
  - !ruby/object:Gem::Dependency
168
182
  name: webmock
169
183
  requirement: !ruby/object:Gem::Requirement
170
184
  requirements:
171
185
  - - "~>"
172
186
  - !ruby/object:Gem::Version
173
- version: '3.7'
187
+ version: '3.8'
174
188
  type: :development
175
189
  prerelease: false
176
190
  version_requirements: !ruby/object:Gem::Requirement
177
191
  requirements:
178
192
  - - "~>"
179
193
  - !ruby/object:Gem::Version
180
- version: '3.7'
194
+ version: '3.8'
181
195
  - !ruby/object:Gem::Dependency
182
196
  name: httparty
183
197
  requirement: !ruby/object:Gem::Requirement
184
198
  requirements:
185
199
  - - "~>"
186
200
  - !ruby/object:Gem::Version
187
- version: '0.17'
201
+ version: '0.18'
188
202
  type: :runtime
189
203
  prerelease: false
190
204
  version_requirements: !ruby/object:Gem::Requirement
191
205
  requirements:
192
206
  - - "~>"
193
207
  - !ruby/object:Gem::Version
194
- version: '0.17'
208
+ version: '0.18'
195
209
  description: Typesense is an open source search engine for building a delightful search
196
210
  experience.
197
211
  email:
@@ -211,7 +225,9 @@ files:
211
225
  - Rakefile
212
226
  - bin/console
213
227
  - bin/setup
228
+ - codecov.yml
214
229
  - examples/aliases.rb
230
+ - examples/client_initialization.rb
215
231
  - examples/collections_and_documents.rb
216
232
  - examples/overrides.rb
217
233
  - examples/search.rb