コード例 #1
0
ファイル: validator.go プロジェクト: dieucao/notifications
func (v *Validator) Validate(params *notify.NotifyParams) bool {
	v.ValidateCall.Receives.Params = params
	params.Errors = append(params.Errors, v.ValidateCall.ErrorsToApply...)

	return v.ValidateCall.Returns.Valid
}
コード例 #2
0
package notify_test

import (
	"github.com/cloudfoundry-incubator/notifications/v1/web/notify"

	. "github.com/onsi/ginkgo"
	. "github.com/onsi/gomega"
)

var _ = Describe("Validator", func() {
	Describe("EmailValidator", func() {
		var (
			params    *notify.NotifyParams
			validator notify.EmailValidator
		)

		BeforeEach(func() {
			params = &notify.NotifyParams{
				Text: "my silly text",
				To:   "*****@*****.**",
			}
			validator = notify.EmailValidator{}
		})

		Describe("Validate", func() {
			It("validates the email fields on Notify", func() {
				Expect(validator.Validate(params)).To(BeTrue())
				Expect(len(params.Errors)).To(Equal(0))

				params.To = ""
コード例 #3
0
ファイル: determiner.go プロジェクト: dieucao/notifications
func (d Determiner) Determine(conn services.ConnectionInterface, uaaHost string, job gobble.Job) error {
	var campaignJob queue.CampaignJob

	err := job.Unmarshal(&campaignJob)
	if err != nil {
		return err
	}

	var audience string
	for key, _ := range campaignJob.Campaign.SendTo {
		audience = key
	}

	params := notify.NotifyParams{
		ReplyTo: campaignJob.Campaign.ReplyTo,
		Subject: campaignJob.Campaign.Subject,
		Text:    campaignJob.Campaign.Text,
		RawHTML: campaignJob.Campaign.HTML,
	}
	if audience == "email" {
		params.To = campaignJob.Campaign.SendTo[audience]
	}

	params.FormatEmailAndExtractHTML()

	strategy, err := d.findStrategy(audience)
	if err != nil {
		return err
	}

	var guid string
	if audience != "email" {
		guid = campaignJob.Campaign.SendTo[audience]
	}

	_, err = strategy.Dispatch(services.Dispatch{
		JobType:    "v2",
		UAAHost:    uaaHost,
		GUID:       guid,
		Connection: conn,
		TemplateID: campaignJob.Campaign.TemplateID,
		CampaignID: campaignJob.Campaign.ID,
		Client: services.DispatchClient{
			ID: campaignJob.Campaign.ClientID,
		},
		Message: services.DispatchMessage{
			To:      params.To,
			ReplyTo: params.ReplyTo,
			Subject: params.Subject,
			Text:    params.Text,
			HTML: services.HTML{
				BodyContent:    params.ParsedHTML.BodyContent,
				BodyAttributes: params.ParsedHTML.BodyAttributes,
				Head:           params.ParsedHTML.Head,
				Doctype:        params.ParsedHTML.Doctype,
			},
		},
	})
	if err != nil {
		return err
	}

	return nil
}