Class: Waistband::Connection

Inherits:
Object
  • Object
show all
Defined in:
lib/waistband/connection.rb

Defined Under Namespace

Classes: NoMoreServers

Instance Method Summary collapse

Constructor Details

#initialize(options = {}) ⇒ Connection

Returns a new instance of Connection.



11
12
13
14
15
16
# File 'lib/waistband/connection.rb', line 11

def initialize(options = {})
  @blacklist      = []
  @retry_on_fail  = options.fetch :retry_on_fail, true
  @orderly        = options.fetch :orderly, false
  pick_server
end

Instance Method Details

#create!(index) ⇒ Object



18
19
20
21
22
# File 'lib/waistband/connection.rb', line 18

def create!(index)
  execute! 'post', relative_url_for_index(index), index_json(index)
rescue RestClient::BadRequest => ex
  nil
end

#delete!(index, key) ⇒ Object



49
50
51
# File 'lib/waistband/connection.rb', line 49

def delete!(index, key)
  execute! 'delete', relative_url_for_key(index, key)
end

#destroy!(index) ⇒ Object



24
25
26
27
28
# File 'lib/waistband/connection.rb', line 24

def destroy!(index)
  execute! 'delete', relative_url_for_index(index)
rescue RestClient::ResourceNotFound => ex
  nil
end

#put(index, key, data) ⇒ Object



45
46
47
# File 'lib/waistband/connection.rb', line 45

def put(index, key, data)
  execute! 'put', relative_url_for_key(index, key), data.to_json
end

#read(index, key) ⇒ Object



38
39
40
41
42
43
# File 'lib/waistband/connection.rb', line 38

def read(index, key)
  fetched = execute! 'get', relative_url_for_key(index, key)
  JSON.parse(fetched)['_source'].with_indifferent_access
rescue RestClient::ResourceNotFound => ex
  nil
end

#refresh(index) ⇒ Object



34
35
36
# File 'lib/waistband/connection.rb', line 34

def refresh(index)
  execute! 'post', "#{relative_url_for_index(index)}/_refresh", {}
end

#search_url_for_index(index) ⇒ Object



53
54
55
# File 'lib/waistband/connection.rb', line 53

def search_url_for_index(index)
  "#{url}/#{relative_url_for_index(index)}/_search"
end

#update_settings!(index) ⇒ Object



30
31
32
# File 'lib/waistband/connection.rb', line 30

def update_settings!(index)
  execute! 'put', "#{relative_url_for_index(index)}/_settings", settings_json(index)
end