mirror of
https://github.com/cgrates/cgrates.git
synced 2026-02-11 18:16:24 +05:00
added execute action
This commit is contained in:
@@ -130,9 +130,10 @@ func (self *ApierV1) ExecuteAction(attr *AttrExecuteAction, reply *float64) erro
|
||||
}
|
||||
|
||||
if err := at.Execute(); err != nil {
|
||||
*reply = -1
|
||||
return err
|
||||
}
|
||||
// what to put in replay
|
||||
*reply = 0
|
||||
return nil
|
||||
}
|
||||
|
||||
|
||||
@@ -20,7 +20,7 @@ type CmdAddBalance struct {
|
||||
|
||||
// name should be exec's name
|
||||
func (self *CmdAddBalance) Usage(name string) string {
|
||||
return fmt.Sprintf("\n\tUsage: cgr-console [cfg_opts...{-h}] get_balance <tenant> <user> <value> [<balanceid=monetary|sms|internet|internet_time|minutes> [<direction>]]")
|
||||
return fmt.Sprintf("\n\tUsage: cgr-console [cfg_opts...{-h}] get_balance <tenant> <account> <value> [<balanceid=monetary|sms|internet|internet_time|minutes> [<direction>]]")
|
||||
}
|
||||
|
||||
// set param defaults
|
||||
|
||||
57
console/execute_action.go
Normal file
57
console/execute_action.go
Normal file
@@ -0,0 +1,57 @@
|
||||
package console
|
||||
|
||||
import (
|
||||
"fmt"
|
||||
"github.com/cgrates/cgrates/apier/v1"
|
||||
)
|
||||
|
||||
func init() {
|
||||
commands["add_balance"] = &CmdExecuteAction{}
|
||||
}
|
||||
|
||||
// Commander implementation
|
||||
type CmdExecuteAction struct {
|
||||
rpcMethod string
|
||||
rpcParams *apier.AttrExecuteAction
|
||||
rpcResult float64
|
||||
}
|
||||
|
||||
// name should be exec's name
|
||||
func (self *CmdExecuteAction) Usage(name string) string {
|
||||
return fmt.Sprintf("\n\tUsage: cgr-console [cfg_opts...{-h}] get_balance <tenant> <account> <value> <actionsid> [<direction>]")
|
||||
}
|
||||
|
||||
// set param defaults
|
||||
func (self *CmdExecuteAction) defaults() error {
|
||||
self.rpcMethod = "ApierV1.ExecuteAction"
|
||||
self.rpcParams = &apier.AttrExecuteAction{Direction: "*out"}
|
||||
return nil
|
||||
}
|
||||
|
||||
// Parses command line args and builds CmdBalance value
|
||||
func (self *CmdExecuteAction) FromArgs(args []string) error {
|
||||
if len(args) < 5 {
|
||||
return fmt.Errorf(self.Usage(""))
|
||||
}
|
||||
// Args look OK, set defaults before going further
|
||||
self.defaults()
|
||||
self.rpcParams.Tenant = args[2]
|
||||
self.rpcParams.Account = args[3]
|
||||
self.rpcParams.ActionsId = args[4]
|
||||
if len(args) > 5 {
|
||||
self.rpcParams.Direction = args[5]
|
||||
}
|
||||
return nil
|
||||
}
|
||||
|
||||
func (self *CmdExecuteAction) RpcMethod() string {
|
||||
return self.rpcMethod
|
||||
}
|
||||
|
||||
func (self *CmdExecuteAction) RpcParams() interface{} {
|
||||
return self.rpcParams
|
||||
}
|
||||
|
||||
func (self *CmdExecuteAction) RpcResult() interface{} {
|
||||
return &self.rpcResult
|
||||
}
|
||||
@@ -19,7 +19,7 @@ type CmdGetBalance struct {
|
||||
|
||||
// name should be exec's name
|
||||
func (self *CmdGetBalance) Usage(name string) string {
|
||||
return fmt.Sprintf("\n\tUsage: cgr-console [cfg_opts...{-h}] get_balance <tenant> <user> [<balanceid=monetary|sms|internet|internet_time|minutes> [<direction>]]")
|
||||
return fmt.Sprintf("\n\tUsage: cgr-console [cfg_opts...{-h}] get_balance <tenant> <account> [<balanceid=monetary|sms|internet|internet_time|minutes> [<direction>]]")
|
||||
}
|
||||
|
||||
// set param defaults
|
||||
|
||||
Reference in New Issue
Block a user