class SearchKit::Clients::Keys
Attributes
connection[R]
token[R]
Public Class Methods
new()
click to toggle source
# File lib/search_kit/clients/keys.rb, line 9 def initialize uri = [SearchKit.config.app_uri, "keys"].join("/") @connection = Faraday.new(uri) @token = SearchKit.config.app_token end
Public Instance Methods
create(name, options = {})
click to toggle source
# File lib/search_kit/clients/keys.rb, line 15 def create(name, options = {}) options = { token: token, data: { type: 'keys', attributes: { name: name }.merge(options) } } response = connection.post('', 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::Unprocessable if response.status == 422 body end
expire(id)
click to toggle source
# File lib/search_kit/clients/keys.rb, line 31 def expire(id) response = connection.delete(id, token: token) body = JSON.parse(response.body, symbolize_names: true) fail Errors::Unauthorized if response.status == 401 fail Errors::KeyNotFound if response.status == 404 body end
index()
click to toggle source
# File lib/search_kit/clients/keys.rb, line 41 def index response = connection.get("", token: token) body = JSON.parse(response.body, symbolize_names: true) fail Errors::Unauthorized if response.status == 401 body end
show(id)
click to toggle source
# File lib/search_kit/clients/keys.rb, line 50 def show(id) response = connection.get(id, token: token) body = JSON.parse(response.body, symbolize_names: true) fail Errors::Unauthorized if response.status == 401 fail Errors::KeyNotFound if response.status == 404 body end
update(id, options)
click to toggle source
# File lib/search_kit/clients/keys.rb, line 60 def update(id, options) options = { token: token, data: { type: 'keys', attributes: options } } response = connection.patch(id, 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::KeyNotFound if response.status == 404 fail Errors::Unprocessable if response.status == 422 body end