Class: SearchKit::Clients::Indices
- Inherits:
-
Object
- Object
- SearchKit::Clients::Indices
- Defined in:
- lib/search_kit/clients/indices.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
- #archive(slug) ⇒ Object
- #create(name) ⇒ Object
-
#initialize ⇒ Indices
constructor
A new instance of Indices.
- #show(slug) ⇒ Object
- #update(slug, options) ⇒ Object
Constructor Details
Instance Attribute Details
#connection ⇒ Object (readonly)
Returns the value of attribute connection.
7 8 9 |
# File 'lib/search_kit/clients/indices.rb', line 7 def connection @connection end |
#token ⇒ Object (readonly)
Returns the value of attribute token.
7 8 9 |
# File 'lib/search_kit/clients/indices.rb', line 7 def token @token end |
Instance Method Details
#archive(slug) ⇒ Object
15 16 17 18 19 20 21 22 23 |
# 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) ⇒ Object
25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 |
# File 'lib/search_kit/clients/indices.rb', line 25 def create(name) = { token: token, data: { type: 'indices', attributes: { name: name } } } response = connection.post('', ) 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) ⇒ Object
41 42 43 44 45 46 47 48 49 |
# 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) ⇒ Object
51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 |
# File 'lib/search_kit/clients/indices.rb', line 51 def update(slug, ) = { token: token, 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::Unauthorized if response.status == 401 fail Errors::IndexNotFound if response.status == 404 fail Errors::Unprocessable if response.status == 422 body end |