Class: Waistband::Connection
- Inherits:
-
Object
- Object
- Waistband::Connection
- Defined in:
- lib/waistband/connection.rb
Defined Under Namespace
Classes: NoMoreServers
Instance Method Summary collapse
- #create!(index) ⇒ Object
- #delete!(index, key) ⇒ Object
- #destroy!(index) ⇒ Object
-
#initialize(options = {}) ⇒ Connection
constructor
A new instance of Connection.
- #put(index, key, data) ⇒ Object
- #read(index, key) ⇒ Object
- #refresh(index) ⇒ Object
- #search_url_for_index(index) ⇒ Object
- #update_settings!(index) ⇒ Object
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( = {}) @blacklist = [] @retry_on_fail = .fetch :retry_on_fail, true @orderly = .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 |