lib/ragios-client.rb in ragios-client-0.0.2 vs lib/ragios-client.rb in ragios-client-0.0.3
- old
+ new
@@ -27,18 +27,18 @@
def add(monitors)
response = RestClient.post "#{address_port}/monitors/", json(monitors), http_request_options
parse_json(response.body)
rescue => e
- raise ClientException, e.response
+ raise_error(e)
end
def find(monitor_id)
response = RestClient.get "#{address_port}/monitors/#{monitor_id}/", auth_cookie
parse_json(response.body)
rescue => e
- raise ClientException, e.response
+ raise_error(e)
end
def all
response = RestClient.get "#{address_port}/monitors/", auth_cookie
parse_json(response.body)
@@ -46,48 +46,52 @@
def stop(monitor_id)
response = RestClient.put "#{address_port}/monitors/#{monitor_id}",{:status => "stopped"}, http_request_options
parse_json(response)
rescue => e
- raise ClientException, e.response
+ raise_error(e)
end
def restart(monitor_id)
response = RestClient.put "#{address_port}/monitors/#{monitor_id}",{:status => "active"},http_request_options
parse_json(response)
rescue => e
- raise ClientException, e.response
+ raise_error(e)
end
def delete(monitor_id)
response = RestClient.delete "#{address_port}/monitors/#{monitor_id}", auth_cookie
parse_json(response)
rescue => e
- raise ClientException, e.response
+ raise_error(e)
end
- def find_by(options)
+ def where(options)
response = RestClient.get "#{address_port}/monitors?#{URI.encode_www_form(options)}", auth_cookie
parse_json(response)
end
def update(monitor_id, options)
response = RestClient.put "#{address_port}/monitors/#{monitor_id}",json(options), http_request_options
parse_json(response)
rescue => e
- raise ClientException, e.response
+ raise_error(e)
end
def test(monitor_id)
response = RestClient.post "#{address_port}/tests", {:id => monitor_id}, http_request_options
parse_json(response)
rescue => e
- raise ClientException, e.response
+ raise_error(e)
end
private
+ def raise_error(e)
+ e.respond_to?('response') ? raise(ClientException, e.response) : raise(e)
+ end
+
def auth_cookie
{:cookies => {:AuthSession => auth_session}}
end
def http_request_options
@@ -112,9 +116,9 @@
#deal with performance when it becomes a problem not yet a priority
auth = RestClient.post "#{address_port}/session", { :username=> @username, :password => @password}
hash = Yajl::Parser.parse(auth.to_str)
hash['AuthSession']
rescue => e
- raise ClientException, e.response
+ raise_error(e)
end
end
end