mirror of
https://github.com/cgrates/cgrates.git
synced 2026-02-11 18:16:24 +05:00
add_account and status
This commit is contained in:
86
console/add_account.go
Normal file
86
console/add_account.go
Normal file
@@ -0,0 +1,86 @@
|
||||
/*
|
||||
Rating system designed to be used in VoIP Carriers World
|
||||
Copyright (C) 2013 ITsysCOM
|
||||
|
||||
This program is free software: you can redistribute it and/or modify
|
||||
it under the terms of the GNU General Public License as published by
|
||||
the Free Software Foundation, either version 3 of the License, or
|
||||
(at your option) any later version.
|
||||
|
||||
This program is distributed in the hope that it will be useful,
|
||||
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
GNU General Public License for more details.
|
||||
|
||||
You should have received a copy of the GNU General Public License
|
||||
along with this program. If not, see <http://www.gnu.org/licenses/>
|
||||
*/
|
||||
|
||||
package console
|
||||
|
||||
import (
|
||||
"encoding/json"
|
||||
"fmt"
|
||||
"reflect"
|
||||
|
||||
"github.com/cgrates/cgrates/apier"
|
||||
"github.com/cgrates/cgrates/engine"
|
||||
)
|
||||
|
||||
func init() {
|
||||
commands["add_account"] = &CmdAddAccount{
|
||||
rpcMethod: "ApierV1.SetAccount",
|
||||
}
|
||||
}
|
||||
|
||||
// Commander implementation
|
||||
type CmdAddAccount struct {
|
||||
rpcMethod string
|
||||
rpcParams *apier.AttrSetAccount
|
||||
rpcResult string
|
||||
}
|
||||
|
||||
func (self *CmdAddAccount) Usage() string {
|
||||
jsn, _ := json.Marshal(engine.CallDescriptor{Direction: "*out"})
|
||||
return "\n\tUsage: add_account " + FromJSON(jsn, self.ClientArgs()) + "\n"
|
||||
}
|
||||
|
||||
// Parses command line args and builds CmdBalance value
|
||||
func (self *CmdAddAccount) FromArgs(args string, verbose bool) error {
|
||||
if len(args) == 0 {
|
||||
return fmt.Errorf(self.Usage())
|
||||
}
|
||||
// defaults
|
||||
self.rpcParams = &apier.AttrSetAccount{Direction: "*out"}
|
||||
|
||||
if err := json.Unmarshal(ToJSON(args), &self.rpcParams); err != nil {
|
||||
return err
|
||||
}
|
||||
if verbose {
|
||||
jsn, _ := json.Marshal(self.rpcParams)
|
||||
fmt.Println("add_account ", FromJSON(jsn, self.ClientArgs()))
|
||||
}
|
||||
return nil
|
||||
}
|
||||
|
||||
func (self *CmdAddAccount) RpcMethod() string {
|
||||
return self.rpcMethod
|
||||
}
|
||||
|
||||
func (self *CmdAddAccount) RpcParams() interface{} {
|
||||
return self.rpcParams
|
||||
}
|
||||
|
||||
func (self *CmdAddAccount) RpcResult() interface{} {
|
||||
return &self.rpcResult
|
||||
}
|
||||
|
||||
func (self *CmdAddAccount) ClientArgs() (args []string) {
|
||||
val := reflect.ValueOf(apier.AttrSetAccount{}).Elem()
|
||||
|
||||
for i := 0; i < val.NumField(); i++ {
|
||||
typeField := val.Type().Field(i)
|
||||
args = append(args, typeField.Name)
|
||||
}
|
||||
return
|
||||
}
|
||||
@@ -57,16 +57,24 @@ func getAvailabelCommandsErr() error {
|
||||
|
||||
// Process args and return right command Value or error
|
||||
func GetCommandValue(command string, verbose bool) (Commander, error) {
|
||||
|
||||
firstSpace := strings.Index(command, " ")
|
||||
if firstSpace < 0 {
|
||||
if len(command) == 0 {
|
||||
return nil, getAvailabelCommandsErr()
|
||||
}
|
||||
cmdVal, exists := commands[command[:firstSpace]]
|
||||
firstSpace := strings.Index(command, " ")
|
||||
var cmdName string
|
||||
var cmdArgs string
|
||||
if firstSpace <= 0 {
|
||||
cmdName = command[:len(command)]
|
||||
cmdArgs = ""
|
||||
} else {
|
||||
cmdName = command[:firstSpace]
|
||||
cmdArgs = command[firstSpace+1:]
|
||||
}
|
||||
cmdVal, exists := commands[cmdName]
|
||||
if !exists {
|
||||
return nil, getAvailabelCommandsErr()
|
||||
}
|
||||
if err := cmdVal.FromArgs(command[firstSpace+1:], verbose); err != nil {
|
||||
if err := cmdVal.FromArgs(cmdArgs, verbose); err != nil {
|
||||
return nil, err
|
||||
}
|
||||
return cmdVal, nil
|
||||
|
||||
54
console/status.go
Normal file
54
console/status.go
Normal file
@@ -0,0 +1,54 @@
|
||||
/*
|
||||
Rating system designed to be used in VoIP Carriers World
|
||||
Copyright (C) 2013 ITsysCOM
|
||||
|
||||
This program is free software: you can redistribute it and/or modify
|
||||
it under the terms of the GNU General Public License as published by
|
||||
the Free Software Foundation, either version 3 of the License, or
|
||||
(at your option) any later version.
|
||||
|
||||
This program is distributed in the hope that it will be useful,
|
||||
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
GNU General Public License for more details.
|
||||
|
||||
You should have received a copy of the GNU General Public License
|
||||
along with this program. If not, see <http://www.gnu.org/licenses/>
|
||||
*/
|
||||
|
||||
package console
|
||||
|
||||
func init() {
|
||||
commands["status"] = &CmdStatus{rpcMethod: "Responder.Status"}
|
||||
}
|
||||
|
||||
type CmdStatus struct {
|
||||
rpcMethod string
|
||||
rpcParams string
|
||||
rpcResult string
|
||||
}
|
||||
|
||||
func (self *CmdStatus) Usage() string {
|
||||
return "\n\tUsage: status \n"
|
||||
}
|
||||
|
||||
// Parses command line args and builds CmdBalance value
|
||||
func (self *CmdStatus) FromArgs(args string, verbose bool) error {
|
||||
return nil
|
||||
}
|
||||
|
||||
func (self *CmdStatus) RpcMethod() string {
|
||||
return self.rpcMethod
|
||||
}
|
||||
|
||||
func (self *CmdStatus) RpcParams() interface{} {
|
||||
return &self.rpcParams
|
||||
}
|
||||
|
||||
func (self *CmdStatus) RpcResult() interface{} {
|
||||
return &self.rpcResult
|
||||
}
|
||||
|
||||
func (self *CmdStatus) ClientArgs() (args []string) {
|
||||
return
|
||||
}
|
||||
Reference in New Issue
Block a user