fcm

package module
v0.0.0-...-151d359 Latest Latest
Warning

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

Go to latest
Published: Aug 16, 2019 License: MIT Imports: 8 Imported by: 0

README

fcm-go

FCM HTTP server protocol in go focused on integrating with existing servers/databases

Documentation

Index

Constants

This section is empty.

Variables

View Source
var (
	Logger func(format string, args ...interface{})
	Error  = errors.NewClass("fcm")
)

Functions

This section is empty.

Types

type Client

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

func NewDefaultClient

func NewDefaultClient(apiKey string, store Store) *Client

func NewFcmClient

func NewFcmClient(apiKey string, client HttpClient, store Store,
	options *ClientOptions) *Client

When options == nil, default values are used

func (*Client) Send

func (c *Client) Send(ctx context.Context, m HttpMessage) (hr *HttpResponse,
	err error)

Sends HttpMessages, retries with exponential backoff, processes replies to the Store

type ClientOptions

type ClientOptions struct {
	MinBackoff       time.Duration
	MaxBackoff       time.Duration
	MaxRetryAttempts int
}

func DefaultClientOptions

func DefaultClientOptions() *ClientOptions

type Data

type Data map[string]interface{}

The data payload of a GCM message.

type FcmClient

type FcmClient interface {
	Send(ctx context.Context, m HttpMessage) (hr *HttpResponse, err error)
}

type HttpClient

type HttpClient interface {
	Do(req *http.Request) (resp *http.Response, err error)
}

type HttpMessage

type HttpMessage struct {
	// Just use registrionIds instead of To
	RegistrationIds       []string      `json:"registration_ids,omitempty"`
	Condition             string        `json:"condition,omitempty"`
	CollapseKey           string        `json:"collapse_key,omitempty"`
	Priority              string        `json:"priority,omitempty"`
	ContentAvailable      bool          `json:"content_available,omitempty"`
	MutableContent        bool          `json:"mutable_content,omitempty"`
	TimeToLive            *uint         `json:"time_to_live,omitempty"`
	RestrictedPackageName string        `json:"restricted_package_name,omitempty"`
	DryRun                bool          `json:"dry_run,omitempty"`
	Data                  Data          `json:"data,omitempty"`
	Notification          *Notification `json:"notification,omitempty"`
}

A GCM Http message.

func NewHttpMessage

func NewHttpMessage(registrationIds []string, data Data, notif *Notification) *HttpMessage

type HttpResponse

type HttpResponse struct {
	MulticastId  int      `json:"multicast_id,omitempty"`
	Success      uint     `json:"success,omitempty"`
	Failure      uint     `json:"failure,omitempty"`
	CanonicalIds uint     `json:"canonical_ids,omitempty"`
	Results      []Result `json:"results,omitempty"`
	MessageId    int      `json:"message_id,omitempty"`
	Error        string   `json:"error,omitempty"`
}

HttpResponse is the GCM connection server response to an HTTP downstream message request.

type Notification

type Notification struct {
	Title        string `json:"title,omitempty"`
	Body         string `json:"body,omitempty"`
	Icon         string `json:"icon,omitempty"`
	Sound        string `json:"sound,omitempty"`
	Badge        string `json:"badge,omitempty"`
	Tag          string `json:"tag,omitempty"`
	Color        string `json:"color,omitempty"`
	ClickAction  string `json:"click_action,omitempty"`
	BodyLocKey   string `json:"body_loc_key,omitempty"`
	BodyLocArgs  string `json:"body_loc_args,omitempty"`
	TitleLocArgs string `json:"title_loc_args,omitempty"`
	TitleLocKey  string `json:"title_loc_key,omitempty"`
}

The notification payload of a GCM message.

type Result

type Result struct {
	MessageId      string `json:"message_id,omitempty"`
	RegistrationId string `json:"registration_id,omitempty"`
	Error          string `json:"error,omitempty"`
}

Result represents the status of a processed Http message.

type Store

type Store interface {
	// Called when a registration token should be updated
	Update(ctx context.Context, oldRegId, newRegId string) error
	// Called when a registration token should be removed because the application
	// was removed from the device, or an unrecoverable error occurred
	Delete(ctx context.Context, regId string) error
}

Directories

Path Synopsis
example

Jump to

Keyboard shortcuts

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