コード例 #1
0
ファイル: callback.go プロジェクト: natebrennand/twiliogo
// Parse the form encoded callback into a Callback struct
func (cb *Callback) Parse(req *http.Request) error {
	numMediaString := req.PostFormValue("NumMedia")
	numMedia, err := strconv.Atoi(numMediaString)
	if err != nil && numMediaString != "" {
		return fmt.Errorf("Error parsing NumMedia => %s", err.Error())
	}

	// creates an array of MediaReference Contents (typically empty)
	mediaArray := make([]MediaReference, numMedia)
	for i := 0; i < numMedia; i++ {
		mediaArray[i] = MediaReference{
			ContentType: req.PostFormValue(fmt.Sprintf("MediaContentType%d", i)),
			URL:         req.PostFormValue(fmt.Sprintf("MediaURL%d", i)),
		}
	}

	*cb = Callback{
		MessageSid:      req.PostFormValue("MessageSid"),
		SmsSid:          req.PostFormValue("SmsSid"),
		Body:            req.PostFormValue("Body"),
		NumMedia:        numMedia,
		MessageStatus:   req.PostFormValue("MessageStatus"),
		ErrorCode:       req.PostFormValue("ErrorCode"),
		MediaList:       mediaArray,
		StandardRequest: common.ParseStandardRequest(req),
	}
	return nil
}
コード例 #2
0
ファイル: callback.go プロジェクト: natebrennand/twiliogo
// Parse creates a Callback struct from a form
func (cb *Callback) Parse(req *http.Request) error {
	callDurString := req.PostFormValue("CallDuration")

	var err error
	var callDur = 0
	var recDur = 0

	if callDurString != "" {
		callDur, err = strconv.Atoi(callDurString)
		if err != nil {
			return fmt.Errorf("Error parsing CallDuration => %s", err.Error())
		}
	}

	recDurString := req.PostFormValue("RecordingDuration")
	if recDurString != "" {
		recDur, err = strconv.Atoi(recDurString)
		if err != nil {
			return fmt.Errorf("Error parsing RecordingDuration => %s", err.Error())
		}
	}

	// Construct callback
	*cb = Callback{
		CallDuration:      callDur,
		RecordingURL:      req.PostFormValue("RecordingURL"),
		RecordingSid:      req.PostFormValue("RecordingSid"),
		RecordingDuration: recDur,
		CallSid:           req.PostFormValue("CallSid"),
		CallStatus:        req.PostFormValue("CallStatus"),
		APIVersion:        req.PostFormValue("APIVersion"),
		Direction:         req.PostFormValue("Direction"),
		ForwardedFrom:     req.PostFormValue("ForwardedFrom"),
		CallerName:        req.PostFormValue("CallerName"),
		StandardRequest:   common.ParseStandardRequest(req),
	}
	return nil
}