Пример #1
0
func sendNotif(listing *models.Listing, seller *models.User, pending int) {
	var apnsClient apns.Client
	if os.Getenv("ENV") == "production" {
		apnsClient, _ = apns.NewClient(apns.ProductionGateway, os.Getenv("APNS_CERT"), os.Getenv("APNS_KEY"))
	} else {
		apnsClient, _ = apns.NewClient(apns.SandboxGateway, os.Getenv("APNS_CERT"), os.Getenv("APNS_KEY"))
	}

	payload := apns.NewPayload()
	payload.APS.Badge = pending
	payload.APS.Alert.Body = fmt.Sprintf("Someone reserved your %s.", listing.Title)
	payload.APS.Sound = "default"

	for _, device := range seller.Devices {
		notif := apns.NewNotification()
		notif.Payload = payload
		notif.DeviceToken = device
		notif.Priority = apns.PriorityImmediate

		apnsClient.Send(notif)
	}
}
Пример #2
0
import (
	"bytes"
	"encoding/binary"
	. "github.com/onsi/ginkgo"
	. "github.com/onsi/gomega"
	"github.com/timehop/apns"
	"io/ioutil"
	"os"
	"time"
)

var _ = Describe("Client", func() {
	Describe(".NewConn", func() {
		Context("bad cert/key pair", func() {
			It("should error out", func() {
				_, err := apns.NewClient(apns.ProductionGateway, "missing", "missing_also")
				Expect(err).NotTo(BeNil())
			})
		})

		Context("valid cert/key pair", func() {
			It("should create a valid client", func() {
				c, err := apns.NewClient(apns.ProductionGateway, DummyCert, DummyKey)
				Expect(err).To(BeNil())
				Expect(c.Conn).NotTo(BeNil())
			})
		})
	})

	Describe(".NewConnWithFiles", func() {
		Context("missing cert/key pair", func() {