mirror of
https://github.com/cgrates/cgrates.git
synced 2026-02-12 02:26:26 +05:00
implemented call url action
it will send a POST request to the action ExtraParameters string url with the json encoded user balance as the body
This commit is contained in:
@@ -19,7 +19,10 @@ along with this program. If not, see <http://www.gnu.org/licenses/>
|
||||
package engine
|
||||
|
||||
import (
|
||||
"bytes"
|
||||
"encoding/json"
|
||||
"fmt"
|
||||
"net/http"
|
||||
"sort"
|
||||
)
|
||||
|
||||
@@ -31,6 +34,7 @@ type Action struct {
|
||||
ActionType string
|
||||
BalanceId string
|
||||
Direction string
|
||||
ExtraParameters string
|
||||
ExpirationString string
|
||||
Weight float64
|
||||
Balance *Balance
|
||||
@@ -48,6 +52,7 @@ const (
|
||||
DEBIT = "*debit"
|
||||
RESET_COUNTER = "*reset_counter"
|
||||
RESET_COUNTERS = "*reset_counters"
|
||||
CALL_URL = "*call_url"
|
||||
UNLIMITED = "*unlimited"
|
||||
)
|
||||
|
||||
@@ -77,6 +82,8 @@ func getActionFunc(typ string) (actionTypeFunc, bool) {
|
||||
return resetCounterAction, true
|
||||
case RESET_COUNTERS:
|
||||
return resetCountersAction, true
|
||||
case CALL_URL:
|
||||
return callUrl, true
|
||||
}
|
||||
return nil, false
|
||||
}
|
||||
@@ -170,6 +177,15 @@ func genericReset(ub *UserBalance) {
|
||||
ub.resetActionTriggers(nil)
|
||||
}
|
||||
|
||||
func callUrl(ub *UserBalance, a *Action) error {
|
||||
body, err := json.Marshal(ub)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
_, err = http.Post(a.ExtraParameters, "application/json", bytes.NewBuffer(body))
|
||||
return err
|
||||
}
|
||||
|
||||
// Structure to store actions according to weight
|
||||
type Actions []*Action
|
||||
|
||||
|
||||
Reference in New Issue
Block a user