lib/growthforecast/client.rb in growthforecast-client-0.0.2 vs lib/growthforecast/client.rb in growthforecast-client-0.0.3
- old
+ new
@@ -59,12 +59,16 @@
# {"service_name"=>"test",
# "graph_name"=>"<1sec_count",
# "section_name"=>"hostname",
# "id"=>3},
# ]
- def list_graph
- get_json('/json/list/graph')
+ def list_graph(service_name = nil, section_name = nil, graph_name = nil)
+ graphs = get_json('/json/list/graph')
+ graphs = graphs.select {|g| g['service_name'] == service_name } if service_name
+ graphs = graphs.select {|g| g['section_name'] == section_name } if section_name
+ graphs = graphs.select {|g| g['graph_name'] == graph_name } if graph_name
+ graphs
end
# A Helper: Get the list of section
# @return [Hash] list of sections
# @example
@@ -135,11 +139,11 @@
# "adjust"=>"*",
# "type"=>"AREA",
# "sllimit"=>-100000,
# "md5"=>"3c59dc048e8850243be8079a5c74d079"}
def get_graph(service_name, section_name, graph_name)
- get_json("/api/#{service_name}/#{section_name}/#{graph_name}")
+ get_json("/api/#{e service_name}/#{e section_name}/#{e graph_name}")
end
# Get the propety of a graph, /json/graph/:id
# @param [String] id
# @return [Hash] the graph property
@@ -174,19 +178,19 @@
# @param [String] service_name
# @param [String] section_name
# @param [String] graph_name
# @param [Hash] params The POST parameters. See #get_graph
def post_graph(service_name, section_name, graph_name, params)
- post_query("/api/#{service_name}/#{section_name}/#{graph_name}", params)
+ post_query("/api/#{e service_name}/#{e section_name}/#{e graph_name}", params)
end
# Delete a graph, POST /delete/:service_name/:section_name/:graph_name
# @param [String] service_name
# @param [String] section_name
# @param [String] graph_name
def delete_graph(service_name, section_name, graph_name)
- post_query("/delete/#{service_name}/#{section_name}/#{graph_name}")
+ post_query("/delete/#{e service_name}/#{e section_name}/#{e graph_name}")
end
# Update the property of a graph, /json/edit/graph/:id
# @param [String] service_name
# @param [String] section_name
@@ -281,9 +285,13 @@
def delete_complex_by_id(complex_id)
post_query("/delete_complex/#{complex_id}")
end
private
+
+ def e(str)
+ URI.escape(str) if str
+ end
def client
@client ||= HTTPClient.new
end