class SearchKit::Clients::Indices
Attributes
connection[R]
token[R]
Public Class Methods
new()
click to toggle source
# File lib/search_kit/clients/indices.rb, line 9 def initialize uri = [SearchKit.config.app_uri, "indices"].join("/") @connection = Faraday.new(uri) @token = SearchKit.config.app_token end
Public Instance Methods
archive(slug)
click to toggle source
# File lib/search_kit/clients/indices.rb, line 15 def archive(slug) response = connection.delete(slug, token: token) body = JSON.parse(response.body, symbolize_names: true) fail Errors::Unauthorized if response.status == 401 fail Errors::IndexNotFound if response.status == 404 body end
create(name)
click to toggle source
# File lib/search_kit/clients/indices.rb, line 25 def create(name) options = { token: token, data: { type: 'indices', attributes: { name: name } } } response = connection.post('', options) body = JSON.parse(response.body, symbolize_names: true) fail Errors::Unauthorized if response.status == 401 fail Errors::BadRequest if response.status == 400 fail Errors::Unprocessable if response.status == 422 body end
show(slug)
click to toggle source
# File lib/search_kit/clients/indices.rb, line 41 def show(slug) response = connection.get(slug, token: token) body = JSON.parse(response.body, symbolize_names: true) fail Errors::Unauthorized if response.status == 401 fail Errors::IndexNotFound if response.status == 404 body end
update(slug, options)
click to toggle source
# File lib/search_kit/clients/indices.rb, line 51 def update(slug, options) options = { token: token, data: { type: 'indices', attributes: options } } response = connection.patch(slug, options) body = JSON.parse(response.body, symbolize_names: true) fail Errors::BadRequest if response.status == 400 fail Errors::Unauthorized if response.status == 401 fail Errors::IndexNotFound if response.status == 404 fail Errors::Unprocessable if response.status == 422 body end