Class: SearchKit::Indices

Inherits:
Object
  • Object
show all
Defined in:
lib/search_kit/indices.rb,
lib/search_kit/indices/cli.rb

Defined Under Namespace

Classes: CLI

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initializeIndices

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

#connectionObject (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)
  options  = { data: { type: 'indices', attributes: { name: name } } }
  response = connection.post('/', options)
  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, options)
  options  = { data: { type: 'indices', attributes: options } }
  response = connection.patch(slug, options)
  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