From 94addca3e5f44e083cdbdf4cb72451587dde84a8 Mon Sep 17 00:00:00 2001 From: Radu Ioan Fericean Date: Thu, 26 Sep 2013 13:08:03 +0300 Subject: [PATCH] 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 --- engine/action.go | 16 ++++++++++++++++ 1 file changed, 16 insertions(+) diff --git a/engine/action.go b/engine/action.go index 9c4810da1..cad58c4d6 100644 --- a/engine/action.go +++ b/engine/action.go @@ -19,7 +19,10 @@ along with this program. If not, see 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