Class: SearchKit::Clients::Search
- Inherits:
-
Object
- Object
- SearchKit::Clients::Search
- Defined in:
- lib/search_kit/clients/search.rb
Instance Attribute Summary collapse
-
#connection ⇒ Object
readonly
Returns the value of attribute connection.
-
#token ⇒ Object
readonly
Returns the value of attribute token.
Instance Method Summary collapse
- #create(slug, options) ⇒ Object
-
#initialize ⇒ Search
constructor
A new instance of Search.
Constructor Details
Instance Attribute Details
#connection ⇒ Object (readonly)
Returns the value of attribute connection.
7 8 9 |
# File 'lib/search_kit/clients/search.rb', line 7 def connection @connection end |
#token ⇒ Object (readonly)
Returns the value of attribute token.
7 8 9 |
# File 'lib/search_kit/clients/search.rb', line 7 def token @token end |
Instance Method Details
#create(slug, options) ⇒ Object
15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 |
# File 'lib/search_kit/clients/search.rb', line 15 def create(slug, ) params = { token: token, data: { type: "searches", attributes: } } 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 |