mirror of
https://github.com/cgrates/cgrates.git
synced 2026-02-11 18:16:24 +05:00
working on apier
This commit is contained in:
@@ -57,55 +57,56 @@ func (self *Apier) GetDestination(tag string, reply *rater.Destination) error {
|
||||
func (self *Apier) SetDestination(dest *rater.Destination, reply *rater.Destination) error {
|
||||
if err := self.StorDb.SetDestination(dest); err != nil {
|
||||
return err
|
||||
}
|
||||
}
|
||||
return nil
|
||||
}
|
||||
|
||||
/*
|
||||
func (self *Apier) GetMoneyBalance(arg CallDescriptor, reply *CallCost) (err error) {
|
||||
err = rs.getBalance(&arg, CREDIT, reply)
|
||||
type AttrBalance struct {
|
||||
Account string
|
||||
Direction string
|
||||
}
|
||||
|
||||
func (self *Apier) GetMoneyBalance(attr *AttrBalance, reply *float64) (err error) {
|
||||
err = self.getBalance(attr, rater.CREDIT, reply)
|
||||
return err
|
||||
}
|
||||
|
||||
func (self *Apier) GetSMSBalance(arg CallDescriptor, reply *CallCost) (err error) {
|
||||
err = rs.getBalance(&arg, SMS, reply)
|
||||
func (self *Apier) GetSMSBalance(attr *AttrBalance, reply *float64) (err error) {
|
||||
err = self.getBalance(attr, rater.SMS, reply)
|
||||
return err
|
||||
}
|
||||
|
||||
func (self *Apier) GetInternetBalance(arg CallDescriptor, reply *CallCost) (err error) {
|
||||
err = rs.getBalance(&arg, TRAFFIC, reply)
|
||||
func (self *Apier) GetInternetBalance(attr *AttrBalance, reply *float64) (err error) {
|
||||
err = self.getBalance(attr, rater.TRAFFIC, reply)
|
||||
return err
|
||||
}
|
||||
|
||||
func (self *Apier) GetInternetTimeBalance(arg CallDescriptor, reply *CallCost) (err error) {
|
||||
err = rs.getBalance(&arg, TRAFFIC_TIME, reply)
|
||||
func (self *Apier) GetInternetTimeBalance(attr *AttrBalance, reply *float64) (err error) {
|
||||
err = self.getBalance(attr, rater.TRAFFIC_TIME, reply)
|
||||
return err
|
||||
}
|
||||
|
||||
func (self *Apier) GetMinutesBalance(arg CallDescriptor, reply *CallCost) (err error) {
|
||||
err = rs.getBalance(&arg, MINUTES, reply)
|
||||
func (self *Apier) GetMinutesBalance(attr *AttrBalance, reply *float64) (err error) {
|
||||
err = self.getBalance(attr, rater.MINUTES, reply)
|
||||
return err
|
||||
}
|
||||
|
||||
// Get balance
|
||||
func (rs *Responder) getBalance(arg *CallDescriptor, balanceId string, reply *CallCost) (err error) {
|
||||
if rs.Bal != nil {
|
||||
return errors.New("No balancer supported for this command right now")
|
||||
}
|
||||
ubKey := arg.Direction + ":" + arg.Tenant + ":" + arg.Account
|
||||
userBalance, err := storageGetter.GetUserBalance(ubKey)
|
||||
func (self *Apier) getBalance(attr *AttrBalance, balanceId string, reply *float64) (err error) {
|
||||
userBalance, err := self.StorDb.GetUserBalance(attr.Account)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
if balance, balExists := userBalance.BalanceMap[balanceId+arg.Direction]; !balExists {
|
||||
if balance, balExists := userBalance.BalanceMap[balanceId+attr.Direction]; !balExists {
|
||||
// No match, balanceId not found
|
||||
return errors.New("-BALANCE_NOT_FOUND")
|
||||
return errors.New(utils.ERR_NOT_FOUND)
|
||||
} else {
|
||||
reply.Tenant = arg.Tenant
|
||||
reply.Account = arg.Account
|
||||
reply.Direction = arg.Direction
|
||||
reply.Cost = balance
|
||||
*reply = balance
|
||||
}
|
||||
return nil
|
||||
}
|
||||
*/
|
||||
|
||||
func (self *Apier) AddTimedAction(attr *AttrBalance, reply *float64) (err error) {
|
||||
err = self.getBalance(attr, rater.MINUTES, reply)
|
||||
return err
|
||||
}
|
||||
|
||||
@@ -40,8 +40,8 @@ type ActionTiming struct {
|
||||
Weight float64
|
||||
ActionsId string
|
||||
actions Actions
|
||||
stCache time.Time
|
||||
actionsTag, timingsTag string // used only for loading
|
||||
stCache time.Time // cached time of the next start
|
||||
actionsTag, timingsTag string // used only for loading
|
||||
}
|
||||
|
||||
type ActionTimings []*ActionTiming
|
||||
@@ -235,8 +235,8 @@ func (at *ActionTiming) Execute() (err error) {
|
||||
// returns true if the *asap string was found
|
||||
func (at *ActionTiming) CheckForASAP() bool {
|
||||
if at.Timing.StartTime == ASAP {
|
||||
oneMinute, _ := time.ParseDuration(ASAP_DELAY)
|
||||
timeTokens := strings.Split(time.Now().Add(oneMinute).Format(time.Stamp), " ")
|
||||
delay, _ := time.ParseDuration(ASAP_DELAY)
|
||||
timeTokens := strings.Split(time.Now().Add(delay).Format(time.Stamp), " ")
|
||||
at.Timing.StartTime = timeTokens[len(timeTokens)-1]
|
||||
return true
|
||||
}
|
||||
|
||||
BIN
rater/rater.test
BIN
rater/rater.test
Binary file not shown.
@@ -44,12 +44,12 @@ const (
|
||||
Structure containing information about user's credit (minutes, cents, sms...).'
|
||||
*/
|
||||
type UserBalance struct {
|
||||
Id string
|
||||
Type string // prepaid-postpaid
|
||||
BalanceMap map[string]float64
|
||||
MinuteBuckets []*MinuteBucket
|
||||
UnitCounters []*UnitsCounter
|
||||
ActionTriggers ActionTriggerPriotityList
|
||||
Id string
|
||||
Type string // prepaid-postpaid
|
||||
BalanceMap map[string]float64
|
||||
MinuteBuckets []*MinuteBucket
|
||||
UnitCounters []*UnitsCounter
|
||||
ActionTriggers ActionTriggerPriotityList
|
||||
}
|
||||
|
||||
/*
|
||||
|
||||
@@ -73,7 +73,7 @@ func (s *Scheduler) LoadActionTimings(storage rater.DataStorage) {
|
||||
for key, ats := range actionTimings {
|
||||
toBeSaved := false
|
||||
isAsap := false
|
||||
newAts := make([]*rater.ActionTiming, 0)
|
||||
newAts := make([]*rater.ActionTiming, 0) // will remove the one time runs from the database
|
||||
for _, at := range ats {
|
||||
isAsap = at.CheckForASAP()
|
||||
toBeSaved = toBeSaved || isAsap
|
||||
|
||||
@@ -1,17 +1,16 @@
|
||||
package utils
|
||||
|
||||
const (
|
||||
LOCALHOST = "127.0.0.1"
|
||||
FSCDR_FILE_CSV = "freeswitch_file_csv"
|
||||
FSCDR_HTTP_JSON = "freeswitch_http_json"
|
||||
NOT_IMPLEMENTED = "not implemented"
|
||||
PREPAID = "prepaid"
|
||||
POSTPAID = "postpaid"
|
||||
PSEUDOPREPAID = "pseudoprepaid"
|
||||
RATED = "rated"
|
||||
ERR_NOT_IMPLEMENTED = "NOT_IMPLEMENTED"
|
||||
ERR_SERVER_ERROR = "SERVER_ERROR"
|
||||
ERR_NOT_FOUND = "NOT_FOUND"
|
||||
LOCALHOST = "127.0.0.1"
|
||||
FSCDR_FILE_CSV = "freeswitch_file_csv"
|
||||
FSCDR_HTTP_JSON = "freeswitch_http_json"
|
||||
NOT_IMPLEMENTED = "not implemented"
|
||||
PREPAID = "prepaid"
|
||||
POSTPAID = "postpaid"
|
||||
PSEUDOPREPAID = "pseudoprepaid"
|
||||
RATED = "rated"
|
||||
ERR_NOT_IMPLEMENTED = "NOT_IMPLEMENTED"
|
||||
ERR_SERVER_ERROR = "SERVER_ERROR"
|
||||
ERR_NOT_FOUND = "NOT_FOUND"
|
||||
ERR_MANDATORY_IE_MISSING = "MANDATORY_IE_MISSING"
|
||||
)
|
||||
|
||||
|
||||
Reference in New Issue
Block a user