Skip to content

Simplify files organization #36

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
May 25, 2020
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
22 changes: 10 additions & 12 deletions .rubocop_todo.yml
Original file line number Diff line number Diff line change
@@ -1,16 +1,21 @@
# This configuration was generated by
# `rubocop --auto-gen-config`
# on 2020-03-11 15:59:15 +0100 using RuboCop version 0.79.0.
# on 2020-05-24 23:52:41 +0200 using RuboCop version 0.84.0.
# The point is for the user to remove these configuration records
# one by one as the offenses are removed from the code base.
# Note that changes in the inspected code, or installation of new
# versions of RuboCop, may require this file to be generated again.

# Offense count: 21
# Offense count: 19
# Configuration parameters: CountComments, ExcludedMethods.
# ExcludedMethods: refine
Metrics/BlockLength:
Max: 343
Max: 434

# Offense count: 1
# Configuration parameters: CountComments.
Metrics/ClassLength:
Max: 160

# Offense count: 1
# Configuration parameters: CountComments, ExcludedMethods.
Expand All @@ -20,15 +25,8 @@ Metrics/MethodLength:
# Offense count: 1
Naming/AccessorMethodName:
Exclude:
- 'lib/meilisearch/index/updates.rb'
- 'lib/meilisearch/index.rb'

# Offense count: 17
# Offense count: 5
Style/Documentation:
Enabled: false

# Offense count: 73
# Cop supports --auto-correct.
# Configuration parameters: AutoCorrect, AllowHeredoc, AllowURI, URISchemes, IgnoreCopDirectives, IgnoredPatterns.
# URISchemes: http, https
Layout/LineLength:
Max: 107
94 changes: 86 additions & 8 deletions lib/meilisearch/client.rb
Original file line number Diff line number Diff line change
@@ -1,16 +1,94 @@
# frozen_string_literal: true

require 'meilisearch/http_request'
require 'meilisearch/client/keys'
require 'meilisearch/client/stats'
require 'meilisearch/client/health'
require 'meilisearch/client/indexes'

module MeiliSearch
class Client < HTTPRequest
include MeiliSearch::Client::Keys
include MeiliSearch::Client::Stats
include MeiliSearch::Client::Health
include MeiliSearch::Client::Indexes
### INDEXES

def indexes
http_get '/indexes'
end

def show_index(index_uid)
index_object(index_uid).show
end

# Usage:
# create_index('indexUID')
# create_index(uid: 'indexUID')
# create_index(uid: 'indexUID', primaryKey: 'id')
def create_index(attributes)
body = if attributes.is_a?(Hash)
attributes
else
{ uid: attributes }
end
res = http_post '/indexes', body
index_object(res['uid'])
end

def delete_index(index_uid)
index_object(index_uid).delete
end

# Usage:
# index('indexUID')
# index(uid: 'indexUID')
def index(attribute)
uid = attribute.is_a?(Hash) ? attribute[:uid] : attribute
raise IndexUidError if uid.nil?

index_object(uid)
end
alias get_index index

### KEYS

def keys
http_get '/keys'
end
alias get_keys keys

### HEALTH

def healthy?
http_get '/health'
true
rescue StandardError
false
end

def health
http_get '/health'
end

def update_health(bool)
http_put '/health', health: bool
end

### STATS

def version
http_get '/version'
end

def sysinfo
http_get '/sys-info'
end

def pretty_sysinfo
http_get '/sys-info/pretty'
end

def stats
http_get '/stats'
end

private

def index_object(uid)
Index.new(uid, @base_url, @api_key)
end
end
end
22 changes: 0 additions & 22 deletions lib/meilisearch/client/health.rb

This file was deleted.

50 changes: 0 additions & 50 deletions lib/meilisearch/client/indexes.rb

This file was deleted.

12 changes: 0 additions & 12 deletions lib/meilisearch/client/keys.rb

This file was deleted.

23 changes: 0 additions & 23 deletions lib/meilisearch/client/stats.rb

This file was deleted.

11 changes: 0 additions & 11 deletions lib/meilisearch/http_request.rb
Original file line number Diff line number Diff line change
Expand Up @@ -53,17 +53,6 @@ def http_put(path = '', body = nil, params = nil)
validate(response)
end

def http_patch(path = '', body = nil)
body = body.to_json unless body.nil?
response = self.class.patch(
@base_url + path,
body: body,
headers: @headers,
timeout: 1
)
validate(response)
end

def http_delete(path = '')
response = self.class.delete(
@base_url + path,
Expand Down
Loading