Class: Yohoushi::Client
- Inherits:
-
Object
- Object
- Yohoushi::Client
- Defined in:
- lib/yohoushi/client.rb
Instance Attribute Summary collapse
-
#base_uri ⇒ Object
readonly
Returns the value of attribute base_uri.
-
#client ⇒ Object
Returns the value of attribute client.
-
#debug ⇒ Object
Returns the value of attribute debug.
-
#debug_dev ⇒ Object
Returns the value of attribute debug_dev.
Instance Method Summary collapse
-
#get_graph(path) ⇒ Hash
Get parameters from a graph, GET /api/graphs/:path { “number”:“1”, “llimit”:“-1000000000”, “mode”:“gauge”, “stype”:“AREA”, “adjustval”:“1”, “meta”:“”, “service_name”:“multiforecast”, “gmode”:“gauge”, “color”:“#cc6633”, “created_at”:“2013/08/29 11:58:15”, “section_name”:“foo%2Fbar%2Ffoo”, “ulimit”:“1000000000”, “id”:“2”, “graph_name”:“bar”, “description”:“”, “sulimit”:“100000”, “unit”:“”,“sort”:“0”, “updated_at”:“2013/08/29 11:58:15”, “adjust”:“*”, “path”:“foo/bar/foo/bar”, “type”:“AREA”, “sllimit”:“-100000”, “md5”:“c81e728d9d4c2f636f067f89cc14862c”}.
-
#get_json(path) ⇒ Hash
GET the JSON API.
-
#initialize(base_uri = 'http://127.0.0.1:4804') ⇒ Client
constructor
A new instance of Client.
- #last_response ⇒ Object
-
#post_graph(path, params) ⇒ Hash
Post parameters to a graph, POST /api/graphs/:path “data”:{ “number”:“1”, “llimit”:“-1000000000”, “mode”:“gauge”, “stype”:“AREA”, “adjustval”:“1”, “meta”:“”, “service_name”:“multiforecast”, “gmode”:“gauge”, “color”:“#cc6633”, “created_at”:“2013/08/29 11:58:15”, “section_name”:“foo%2Fbar%2Ffoo”, “ulimit”:“1000000000”, “id”:“2”, “graph_name”:“bar”, “description”:“”, “sulimit”:“100000”, “unit”:“”,“sort”:“0”, “updated_at”:“2013/08/29 11:58:15”, “adjust”:“*”, “path”:“foo/bar/foo/bar”, “type”:“AREA”, “sllimit”:“-100000”, “md5”:“c81e728d9d4c2f636f067f89cc14862c”.
-
#post_json(path, data = {}) ⇒ Hash
POST the JSON API.
Constructor Details
#initialize(base_uri = 'http://127.0.0.1:4804') ⇒ Client
Returns a new instance of Client.
19 20 21 |
# File 'lib/yohoushi/client.rb', line 19 def initialize(base_uri = 'http://127.0.0.1:4804') @base_uri = base_uri end |
Instance Attribute Details
#base_uri ⇒ Object (readonly)
Returns the value of attribute base_uri.
16 17 18 |
# File 'lib/yohoushi/client.rb', line 16 def base_uri @base_uri end |
#client ⇒ Object
Returns the value of attribute client.
14 15 16 |
# File 'lib/yohoushi/client.rb', line 14 def client @client end |
#debug ⇒ Object
Returns the value of attribute debug.
13 14 15 |
# File 'lib/yohoushi/client.rb', line 13 def debug @debug end |
#debug_dev ⇒ Object
Returns the value of attribute debug_dev.
15 16 17 |
# File 'lib/yohoushi/client.rb', line 15 def debug_dev @debug_dev end |
Instance Method Details
#get_graph(path) ⇒ Hash
Get parameters from a graph, GET /api/graphs/:path
"number":"1",
"llimit":"-1000000000",
"mode":"gauge",
"stype":"AREA",
"adjustval":"1",
"meta":"",
"service_name":"multiforecast",
"gmode":"gauge",
"color":"#cc6633",
"created_at":"2013/08/29 11:58:15",
"section_name":"foo%2Fbar%2Ffoo",
"ulimit":"1000000000",
"id":"2",
"graph_name":"bar",
"description":"",
"sulimit":"100000",
"unit":"","sort":"0",
"updated_at":"2013/08/29 11:58:15",
"adjust":"*",
"path":"foo/bar/foo/bar",
"type":"AREA",
"sllimit":"-100000",
"md5":"c81e728d9d4c2f636f067f89cc14862c"
119 120 121 |
# File 'lib/yohoushi/client.rb', line 119 def get_graph(path) get_json("/api/graphs/#{escape path}") end |
#get_json(path) ⇒ Hash
GET the JSON API
40 41 42 43 44 |
# File 'lib/yohoushi/client.rb', line 40 def get_json(path) @res = client.get("#{@base_uri}#{path}") handle_error(@res) JSON.parse(@res.body) end |
#last_response ⇒ Object
33 34 35 |
# File 'lib/yohoushi/client.rb', line 33 def last_response @res end |
#post_graph(path, params) ⇒ Hash
Post parameters to a graph, POST /api/graphs/:path “data”:{
"number":"1",
"llimit":"-1000000000",
"mode":"gauge",
"stype":"AREA",
"adjustval":"1",
"meta":"",
"service_name":"multiforecast",
"gmode":"gauge",
"color":"#cc6633",
"created_at":"2013/08/29 11:58:15",
"section_name":"foo%2Fbar%2Ffoo",
"ulimit":"1000000000",
"id":"2",
"graph_name":"bar",
"description":"",
"sulimit":"100000",
"unit":"","sort":"0",
"updated_at":"2013/08/29 11:58:15",
"adjust":"*",
"path":"foo/bar/foo/bar",
"type":"AREA",
"sllimit":"-100000",
"md5":"c81e728d9d4c2f636f067f89cc14862c"
87 88 89 |
# File 'lib/yohoushi/client.rb', line 87 def post_graph(path, params) post_json("/api/graphs/#{escape path}", params) end |
#post_json(path, data = {}) ⇒ Hash
POST the JSON API
50 51 52 53 54 55 |
# File 'lib/yohoushi/client.rb', line 50 def post_json(path, data = {}) pp data if @debug @res = client.post("#{@base_uri}#{path}", data) handle_error(@res) JSON.parse(@res.body) end |