From 9b9ce2d0a5b7eb0d15280cffa6e78f79befa4dd3 Mon Sep 17 00:00:00 2001 From: Radu Ioan Fericean Date: Tue, 20 Mar 2012 15:24:53 +0200 Subject: [PATCH] working on installation tutorial --- docs/apicalls.rst | 28 +++++++++++++++++++++++++++- docs/tutorial.rst | 11 ++++++++++- 2 files changed, 37 insertions(+), 2 deletions(-) diff --git a/docs/apicalls.rst b/docs/apicalls.rst index cf448a297..537ebe74d 100644 --- a/docs/apicalls.rst +++ b/docs/apicalls.rst @@ -1,6 +1,32 @@ Api Calls -========= +======== +As stated before the balancer (or the rater directly) can be accesed via json rpc. +The smallest python snippet to acces the CGRateS balancer is this: + +:: + + cd = {"Tor":0, + "CstmId": "vdf", + "Subject": "rif", + "DestinationPrefix": "0256", + "TimeStart": "2012-02-02T17:30:00Z", + "TimeEnd": "2012-02-02T18:30:00Z"} + + s = socket.create_connection(("127.0.0.1", 2001)) + s.sendall(json.dumps(({"id": 1, "method": "Responder.Get", "params": [cd]}))) + print s.recv(4096) + +This also gives you a pretty good idea of how JSON-RPC works. You can find details in the specification_. A call to a JSON-RPC server simply sends a block of data through a socket. The data is formatted as a JSON structure, and a call consists of an id (so you can sort out the results when they come back), the name of the method to execute on the server, and params, an array of parameters which can itself consist of complex JSON objects. The dumps() call converts the Python structure into JSON. + +.. _specification: http://json-rpc.org/wiki/specification + +In the stress folder you can find a better example of python client using a class that reduces tha ctual call code to:: + + rpc =JSONClient(("127.0.0.1", 2001)) + result = rpc.call("Responder.Get", cd) + print result + JSON RPC -------- GetCost diff --git a/docs/tutorial.rst b/docs/tutorial.rst index e75f3192e..5e4075ab2 100644 --- a/docs/tutorial.rst +++ b/docs/tutorial.rst @@ -57,7 +57,16 @@ Instalation **Using packages** **Using source** -.. _running: +After the go environment is installed_ and setup_ just issue the following command: +:: + + go get github.com/rif/cgrates + +After that navigate + +.. _installed: http://golang.org/doc/install +.. _setup: http://golang.org/doc/code.html + Running -------