lib/ragios-client.rb in ragios-client-0.0.6 vs lib/ragios-client.rb in ragios-client-0.0.7

- old
+ new

@@ -48,30 +48,42 @@ api_request { RestClient.get "#{address_port}/monitors/attributes?#{URI.encode_www_form(options)}", auth_cookie } end def update(monitor_id, options) api_request { RestClient.put "#{address_port}/monitors/#{monitor_id}",generate_json(options), http_request_options } end + def find_event(event_id) + api_request { RestClient.get "#{address_port}/events/#{event_id}/", auth_cookie } + end + def all_events(limit = nil) + params = limit ? "?take=#{limit}" : "" + api_request { RestClient.get "#{address_port}/events#{params}", auth_cookie } + end + def delete_event(event_id) + api_request { RestClient.delete "#{address_port}/events/#{event_id}", auth_cookie } + end def events(monitor_id, startdate, enddate, limit=nil) - api_request { RestClient.get "#{address_port}/monitors/#{monitor_id}/events", {params: options(startdate, enddate, limit)} } + api_request { RestClient.get "#{address_port}/monitors/#{monitor_id}/events", options(startdate, enddate, limit) } end def events_by_type(monitor_id, type, startdate, enddate, limit=nil) - api_request { RestClient.get "#{address_port}/monitors/#{monitor_id}/events_by_type/#{type}", {params: options(startdate, enddate, limit)} } + api_request { RestClient.get "#{address_port}/monitors/#{monitor_id}/events_by_type/#{type}", options(startdate, enddate, limit) } end def events_by_state(monitor_id, state, startdate, enddate, limit=nil) - api_request { RestClient.get "#{address_port}/monitors/#{monitor_id}/events_by_state/#{state}", {params: options(startdate, enddate, limit)} } + api_request { RestClient.get "#{address_port}/monitors/#{monitor_id}/events_by_state/#{state}", options(startdate, enddate, limit) } end def test(monitor_id) api_request { RestClient.post "#{address_port}/tests", {:id => monitor_id}, http_request_options } end private def options(startdate, enddate, limit = nil) - options = {} - options[:start_date] = startdate - options[:end_date] = enddate - options[:take] = limit if limit - options + params = {} + params[:start_date] = startdate + params[:end_date] = enddate + params[:take] = limit if limit + query_options = auth_cookie + query_options[:params] = params + query_options end def api_request response = yield parse_json(response) rescue => e @@ -81,16 +93,16 @@ def raise_error(e) e.respond_to?('response') ? raise(ClientException, e.response) : raise(e) end def auth_cookie - {:cookies => {:AuthSession => auth_session}} + {:cookies => {:RagiosAuthSession => auth_session}} end def http_request_options {:content_type => :json, - :cookies => {:AuthSession => auth_session} + :cookies => {:RagiosAuthSession => auth_session} } end def address_port "#{@address}:#{@port}" @@ -106,10 +118,10 @@ def auth_session return "" if [@username, @password].any? { |e| e.nil? } auth = RestClient.post "#{address_port}/session", { :username=> @username, :password => @password} hash = parse_json(auth) - hash[:AuthSession] + hash[:RagiosAuthSession] rescue => e raise_error(e) end end end