Class: SearchKit::Documents::CLI

Inherits:
Thor
  • Object
show all
Includes:
Messaging
Defined in:
lib/search_kit/documents/cli.rb

Instance Method Summary collapse

Methods included from Messaging

#info, #warning

Instance Method Details

#create(slug, document) ⇒ Object



21
22
23
24
25
26
27
28
29
30
31
32
33
# File 'lib/search_kit/documents/cli.rb', line 21

def create(slug, document)
  document = JSON.parse(document, symbolize_names: true)
  response = client.create(slug, document)
  info response.to_json
rescue JSON::ParserError
  warning "Document must be given in the form of a JSON string"
rescue Errors::BadRequest
  warning "Bad request given"
rescue Errors::Unprocessable
  warning "Options given unprocessable"
rescue Faraday::ConnectionFailed
  warning "No running service found"
end

#delete(slug, id) ⇒ Object



53
54
55
56
57
58
59
60
# File 'lib/search_kit/documents/cli.rb', line 53

def delete(slug, id)
  response = client.delete(slug, id)
  info response.to_json
rescue Errors::IndexNotFound
  warning "Unable to find either the given index or document"
rescue Faraday::ConnectionFailed
  warning "No running service found"
end

#show(slug, id) ⇒ Object



11
12
13
14
15
16
17
18
# File 'lib/search_kit/documents/cli.rb', line 11

def show(slug, id)
  response = client.show(slug, id)
  info response.to_json
rescue Errors::IndexNotFound
  warning "No index for that slug found (could also be missing doc)"
rescue Faraday::ConnectionFailed
  warning "No running service found"
end

#update(slug, id, document) ⇒ Object



36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
# File 'lib/search_kit/documents/cli.rb', line 36

def update(slug, id, document)
  document = JSON.parse(document, symbolize_names: true)
  response = client.update(slug, id, document)
  info response.to_json
rescue JSON::ParserError
  warning "Document must be given in the form of a JSON string"
rescue Errors::BadRequest
  warning "Bad request given"
rescue Errors::IndexNotFound
  warning "Unable to find either the given index or document"
rescue Errors::Unprocessable
  warning "Options given unprocessable"
rescue Faraday::ConnectionFailed
  warning "No running service found"
end