cms

package module
v0.0.0-...-6263d09 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Dec 28, 2017 License: MIT Imports: 13 Imported by: 0

README

cloud-messaging

Common interfaces to Cloud Messaging Services API.

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func MakeBatch

func MakeBatch(pipe <-chan Recipient, buffer []Recipient) (int, bool)

MakeBatch groups recipients from a channel into chunk and puths them into slice. It returns size of batch and status of fetching from channel.

func Notify

func Notify(c CMS, message *Message, pipe <-chan Recipient) error

Notify sends push notification to recipients that are recieved through the channel. It use given CMS as a client and the same message for all recipeints.

Types

type APN

type APN struct {
	// contains filtered or unexported fields
}

APN represent Apple Notification Service client.

func NewAPNClient

func NewAPNClient(errs chan<- Response, certPath, topic string) (*APN, error)

NewAPNClient contructs an instance of APNS client.

func (*APN) Close

func (a *APN) Close() error

Close closes client.

func (*APN) NotifyMany

func (a *APN) NotifyMany(message *Message, recs []Recipient) error

NotifyMany notifies a chunk of recipients with the same message.

func (*APN) NotifyOne

func (a *APN) NotifyOne(message *Message, rec *Recipient) error

NotifyOne notifies a recipient.

type APNConfig

type APNConfig struct {
	Cert  string
	Topic string
}

APNConig stores settings for APNS client.

type CMS

type CMS interface {
	// Close closes CMS client.
	Close() error

	// NotifyOne notifies only one recipient.
	NotifyOne(*Message, *Recipient) error

	// NotifeMany notifies multiple recipients.
	NotifyMany(*Message, []Recipient) error
}

CMS generalize notion of Cloud Message Service client like APNS or GCM.

type CMSConfig

type CMSConfig struct {
	APN APNConfig
	FCM FCMConfig
	GCM GCMConfig
	WNS WNSConfig
}

CMSConfig collect settings for all supported messaging services.

type CMSFactory

type CMSFactory struct {
	// contains filtered or unexported fields
}

CMSFactory contains common configuration for any CMS client and produce client by its name.

func NewCMSFactory

func NewCMSFactory(cfg *CMSConfig, errs chan<- Response) (*CMSFactory, error)

NewCMSFactory creates new instance of factory.

func (CMSFactory) Produce

func (f CMSFactory) Produce(name string, responses chan<- Response) (CMS, error)

Produce makes new instance of CMS client object by its name or target platform. Avaliable names are `apn` or `ios` for APNS, `fcm` or `android` for FCM, `gcm` for GCM and `wns` or `windows` for WNS.

type FCM

type FCM struct {
	// contains filtered or unexported fields
}

FCM represent Firebase Cloud Messaging service client.

func NewFCMClient

func NewFCMClient(errs chan<- Response, apiKey string) (*FCM, error)

NewFCMClient contructs an instance of FCM client.

func (*FCM) Close

func (f *FCM) Close() error

Close closes client.

func (*FCM) NotifyMany

func (f *FCM) NotifyMany(message *Message, recs []Recipient) error

NotifyMany notifies a chunk of recipients with the same message.

func (*FCM) NotifyOne

func (f *FCM) NotifyOne(message *Message, rec *Recipient) error

NotifyOne notifies a recipient.

type FCMConfig

type FCMConfig struct {
	APIKey string `toml:"api_key"`
}

FCMConfig stores settings for FCM client.

type GCM

type GCM struct {
	// contains filtered or unexported fields
}

GCM represent Google Cloud Messaging service client.

func NewGCMClient

func NewGCMClient(errs chan<- Response, apiKey, senderId string) (*GCM, error)

NewGCMClient contructs an instance of GCM client.

func (*GCM) Close

func (g *GCM) Close() error

Close closes client.

func (*GCM) NotifyMany

func (g *GCM) NotifyMany(message *Message, recs []Recipient) error

NotifyMany notifies a chunk of recipients with the same message.

func (*GCM) NotifyOne

func (g *GCM) NotifyOne(message *Message, rec *Recipient) error

NotifyOne notifies a recipient.

type GCMConfig

type GCMConfig struct {
	APIKey   string `toml:"api_key"`
	SenderID string `toml:"sender_id"`
}

GCMConfig stores settings for GCM client.

type Message

type Message struct {
	Title    string
	Body     string
	Deeplink string
}

Message contains push notification payload.

func MessageFromFile

func MessageFromFile(source string) (*Message, error)

MessageFromFile fills notification payload from json file.

type Recipient

type Recipient struct {
	Id    uuid.UUID
	Token string
}

Recipient identifies recipient by its UUID and push token string.

type Recipients

type Recipients struct {
	// contains filtered or unexported fields
}

Recipients represents object to iterates over lines of csv file with recipients identifiers like id or token.

func RecipientsFromFile

func RecipientsFromFile(path string) (*Recipients, error)

RecipientsFromFile create instance of Recipients structure from csv file by its filename.

func (*Recipients) Next

func (r *Recipients) Next() (*Recipient, error)

Next does step of iteration and returns next recipient.

type Response

type Response struct {
	Id         uuid.UUID
	Ok         bool
	Reason     string
	StatusCode int
	Token      string
}

Response contains status information of sent notification.

type Responses

type Responses struct {
	Success   uint
	Failure   uint
	Responses []Response
}

Responses contains chunk of response for batch processing.

type WNSConfig

type WNSConfig struct {
}

WNSConfig stores settings for WNS client.

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL