mirror of
https://github.com/cgrates/cgrates.git
synced 2026-02-12 10:36:24 +05:00
87 lines
3.8 KiB
ReStructuredText
87 lines
3.8 KiB
ReStructuredText
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
|
|
Creates a CallCost structure with the cost information calculated for the received CallDescriptor.
|
|
|
|
DebitBalance
|
|
Interface method used to add/substract an amount of cents from user's money budget.
|
|
The amount filed has to be filled in call descriptor.
|
|
|
|
DebitSMS
|
|
Interface method used to add/substract an amount of units from user's SMS budget.
|
|
The amount filed has to be filled in call descriptor.
|
|
|
|
DebitSeconds
|
|
Interface method used to add/substract an amount of seconds from user's minutes budget.
|
|
The amount filed has to be filled in call descriptor.
|
|
|
|
GetMaxSessionTime
|
|
Returns the approximate max allowed session for user budget. It will try the max amount received in the call descriptor
|
|
and will decrease it by 10% for nine times. So if the user has little credit it will still allow 10% of the initial amount.
|
|
If the user has no credit then it will return 0.
|
|
|
|
AddVolumeDiscountSeconds
|
|
Interface method used to add an amount to the accumulated placed call seconds to be used for volume discount.
|
|
The amount filed has to be filled in call descriptor.
|
|
|
|
ResetVolumeDiscountSeconds
|
|
Resets the accumulated volume discount seconds (to zero).
|
|
|
|
AddRecievedCallSeconds
|
|
Adds the specified amount of seconds to the received call seconds. When the threshold specified in the user's tariff plan is reached then the received call budget is reseted and the bonus specified in the tariff plan is applied.
|
|
The amount filed has to be filled in call descriptor.
|
|
|
|
ResetUserBudget
|
|
Resets user budgets value to the amounts specified in the tariff plan.
|
|
|
|
HTTP
|
|
----
|
|
|
|
getcost
|
|
:Example: curl "http://127.0.0.1:8000/getcost?cstmid=vdf&subj=rif&dest=0257"
|
|
debitbalance
|
|
:Example: curl "http://127.0.0.1:8000/debitbalance?cstmid=vdf&subj=rif&dest=0257@amount=100"
|
|
debitsms
|
|
:Example: curl "http://127.0.0.1:8000/debitsms?cstmid=vdf&subj=rif&dest=0257@amount=100"
|
|
debitseconds
|
|
:Example: curl "http://127.0.0.1:8000/debitseconds?cstmid=vdf&subj=rif&dest=0257@amount=100"
|
|
getmaxsessiontime
|
|
:Example: curl "http://127.0.0.1:8000/getmaxsessiontime?cstmid=vdf&subj=rif&dest=0257@amount=100"
|
|
addvolumediscountseconds
|
|
:Example: curl "http://127.0.0.1:8000/addvolumediscountseconds?cstmid=vdf&subj=rif&dest=0257@amount=100"
|
|
resetvolumediscountseconds
|
|
:Example: curl "http://127.0.0.1:8000/resetvolumediscountseconds?cstmid=vdf&subj=rif&dest=0257"
|
|
addrecievedcallseconds
|
|
:Example: curl "http://127.0.0.1:8000/addrecievedcallseconds?cstmid=vdf&subj=rif&dest=0257@amount=100"
|
|
resetuserbudget
|
|
:Example: curl "http://127.0.0.1:8000/resetuserbudget?cstmid=vdf&subj=rif&dest=0257"
|