Class: SearchKit::Documents
- Inherits:
-
Object
- Object
- SearchKit::Documents
- Defined in:
- lib/search_kit/documents.rb,
lib/search_kit/documents/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(slug, options) ⇒ Object
- #delete(slug, id) ⇒ Object
-
#initialize ⇒ Documents
constructor
A new instance of Documents.
- #show(slug, id) ⇒ Object
- #update(slug, id, options) ⇒ Object
Constructor Details
Instance Attribute Details
#connection ⇒ Object (readonly)
Returns the value of attribute connection.
9 10 11 |
# File 'lib/search_kit/documents.rb', line 9 def connection @connection end |
Instance Method Details
#create(slug, options) ⇒ Object
16 17 18 19 20 21 22 23 24 25 26 |
# File 'lib/search_kit/documents.rb', line 16 def create(slug, ) document = { data: { type: "documents", attributes: } } response = connection.post(slug, document) 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 |
#delete(slug, id) ⇒ Object
49 50 51 52 53 54 55 56 |
# File 'lib/search_kit/documents.rb', line 49 def delete(slug, id) response = connection.delete("#{slug}/#{id}") body = JSON.parse(response.body, symbolize_names: true) fail Errors::IndexNotFound if response.status == 404 body end |
#show(slug, id) ⇒ Object
28 29 30 31 32 33 34 35 |
# File 'lib/search_kit/documents.rb', line 28 def show(slug, id) response = connection.get("#{slug}/#{id}") body = JSON.parse(response.body, symbolize_names: true) fail Errors::IndexNotFound if response.status == 404 body end |
#update(slug, id, options) ⇒ Object
37 38 39 40 41 42 43 44 45 46 47 |
# File 'lib/search_kit/documents.rb', line 37 def update(slug, id, ) document = { data: { type: "documents", id: id, attributes: } } response = connection.patch("#{slug}/#{id}", document) 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 |