Sha256: fe01b4399bf64cab688ea6cf820f012f53374accc2189bdecb7cc9580b4883d1
Contents?: true
Size: 892 Bytes
Versions: 5
Compression:
Stored size: 892 Bytes
Contents
require 'faraday' require 'json' module SearchKit module Clients class Search attr_reader :connection, :token def initialize uri = [SearchKit.config.app_uri, "search"].join("/") @connection = Faraday.new(uri) @token = SearchKit.config.app_token end def search(slug, options) params = { token: token, data: { type: "searches", attributes: options } } response = connection.post(slug, params) 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 SearchKit::Models::Search.new(body.fetch(:data, {})) end end end end
Version data entries
5 entries across 5 versions & 1 rubygems