Class: SearchKit::Indices
- Inherits:
-
Object
- Object
- SearchKit::Indices
- Defined in:
- lib/search_kit/indices.rb,
lib/search_kit/indices/cli.rb
Defined Under Namespace
Classes: CLI
Instance Attribute Summary collapse
-
#connection ⇒ Object
readonly
Returns the value of attribute connection.
Instance Method Summary collapse
- #create(name) ⇒ Object
- #delete(slug) ⇒ Object
-
#initialize ⇒ Indices
constructor
A new instance of Indices.
- #show(slug) ⇒ Object
- #update(slug, options) ⇒ Object
Constructor Details
#initialize ⇒ Indices
Returns a new instance of Indices.
11 12 13 14 |
# File 'lib/search_kit/indices.rb', line 11 def initialize uri = [SearchKit.config.app_uri, "indices"].join("/") @connection = Faraday.new(uri) end |
Instance Attribute Details
#connection ⇒ Object (readonly)
Returns the value of attribute connection.
9 10 11 |
# File 'lib/search_kit/indices.rb', line 9 def connection @connection end |
Instance Method Details
#create(name) ⇒ Object
25 26 27 28 29 30 31 32 33 34 |
# File 'lib/search_kit/indices.rb', line 25 def create(name) = { data: { type: 'indices', attributes: { name: name } } } response = connection.post('/', ) body = JSON.parse(response.body, symbolize_names: true) fail Errors::Unprocessable if response.status == 422 fail Errors::BadRequest if response.status == 400 body end |
#delete(slug) ⇒ Object
48 49 50 51 52 53 54 55 |
# File 'lib/search_kit/indices.rb', line 48 def delete(slug) response = connection.delete(slug) body = JSON.parse(response.body, symbolize_names: true) fail Errors::IndexNotFound if response.status == 404 body end |
#show(slug) ⇒ Object
16 17 18 19 20 21 22 23 |
# File 'lib/search_kit/indices.rb', line 16 def show(slug) response = connection.get(slug) body = JSON.parse(response.body, symbolize_names: true) fail Errors::IndexNotFound if response.status == 404 body end |
#update(slug, options) ⇒ Object
36 37 38 39 40 41 42 43 44 45 46 |
# File 'lib/search_kit/indices.rb', line 36 def update(slug, ) = { data: { type: 'indices', attributes: } } response = connection.patch(slug, ) body = JSON.parse(response.body, symbolize_names: true) fail Errors::BadRequest if response.status == 400 fail Errors::IndexNotFound if response.status == 404 fail Errors::Unprocessable if response.status == 422 body end |