gcm

package
v1.0.7 Latest Latest
Warning

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

Go to latest
Published: Dec 11, 2019 License: Apache-2.0 Imports: 10 Imported by: 0

Documentation

Index

Constants

View Source
const (
	ErrorCodeMissingRegistration = "MissingRegistration"
	ErrorCodeInvalidRegistration = "InvalidRegistration"
	ErrorCodeUnavailable         = "Unavailable"
)
View Source
const ErrorCodeFailedToReadResponse = "FailedToReadResponse"

Variables

This section is empty.

Functions

This section is empty.

Types

type Client

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

Client (legacy/gcm) https://firebase.google.com/docs/cloud-messaging/http-server-ref Legacy FCM/GCM API (https://firebase.google.com/docs/cloud-messaging/migrate-v1): 1. copy server key from: https://console.firebase.google.com/project/_/settings/cloudmessaging/ 2. add to request header: Authorization:key=<server key>

func New

func New(key []byte, isSandbox bool, retries int, timeout time.Duration) (*Client, error)

func (*Client) Sandbox

func (c *Client) Sandbox() bool

func (*Client) Send

func (c *Client) Send(ctx context.Context, message *Request) (retval *Response, err error)

type Notification

type Notification struct {
	Title            string          `json:"title,omitempty"`
	Body             string          `json:"body,omitempty"`
	AndroidChannelID string          `json:"android_channel_id,omitempty"`
	Icon             string          `json:"icon,omitempty"`
	Sound            string          `json:"sound,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      json.RawMessage `json:"body_loc_args,omitempty"`
	TitleLocKey      string          `json:"title_loc_key,omitempty"`
	TitleLocArgs     json.RawMessage `json:"title_loc_args,omitempty"`
}

Table 2b: https://firebase.google.com/docs/cloud-messaging/http-server-ref#notification-payload-support

func (Notification) MarshalEasyJSON

func (v Notification) MarshalEasyJSON(w *jwriter.Writer)

MarshalEasyJSON supports easyjson.Marshaler interface

func (Notification) MarshalJSON

func (v Notification) MarshalJSON() ([]byte, error)

MarshalJSON supports json.Marshaler interface

func (*Notification) UnmarshalEasyJSON

func (v *Notification) UnmarshalEasyJSON(l *jlexer.Lexer)

UnmarshalEasyJSON supports easyjson.Unmarshaler interface

func (*Notification) UnmarshalJSON

func (v *Notification) UnmarshalJSON(data []byte) error

UnmarshalJSON supports json.Unmarshaler interface

type Request

type Request struct {
	To                    string          `json:"to"`
	RegistrationIDs       []string        `json:"registration_ids,omitempty"`
	Condition             string          `json:"condition,omitempty"`
	NotificationKey       string          `json:"notification_key,omitempty"`
	CollapseKey           string          `json:"collapse_key,omitempty"`
	Priority              string          `json:"priority,omitempty"`
	ContentAvailable      bool            `json:"content_available,omitempty"`
	MutableContent        json.RawMessage `json:"mutable_content,omitempty"`
	TimeToLive            int             `json:"time_to_live,omitempty"`
	RestrictedPackageName string          `json:"restricted_package_name,omitempty"`
	DryRun                bool            `json:"dry_run,omitempty"`
	Data                  json.RawMessage `json:"data,omitempty"`
	Notification          json.RawMessage `json:"notification,omitempty"`
}

https://firebase.google.com/docs/cloud-messaging/http-server-ref#downstream-http-messages-json

func (Request) MarshalEasyJSON

func (v Request) MarshalEasyJSON(w *jwriter.Writer)

MarshalEasyJSON supports easyjson.Marshaler interface

func (Request) MarshalJSON

func (v Request) MarshalJSON() ([]byte, error)

MarshalJSON supports json.Marshaler interface

func (*Request) SetToken

func (r *Request) SetToken(token string)

func (*Request) ShouldIgnore added in v1.0.2

func (r *Request) ShouldIgnore() bool

func (*Request) UnmarshalEasyJSON

func (v *Request) UnmarshalEasyJSON(l *jlexer.Lexer)

UnmarshalEasyJSON supports easyjson.Unmarshaler interface

func (*Request) UnmarshalJSON

func (v *Request) UnmarshalJSON(data []byte) error

UnmarshalJSON supports json.Unmarshaler interface

type Response

type Response struct {
	MulticastID int               `json:"multicast_id"`
	Success     int               `json:"success"`
	Failure     int               `json:"failure"`
	StatusCode  int               `json:"-"`
	Results     []*ResponseResult `json:"results"`
}

func (Response) MarshalEasyJSON

func (v Response) MarshalEasyJSON(w *jwriter.Writer)

MarshalEasyJSON supports easyjson.Marshaler interface

func (Response) MarshalJSON

func (v Response) MarshalJSON() ([]byte, error)

MarshalJSON supports json.Marshaler interface

func (*Response) UnmarshalEasyJSON

func (v *Response) UnmarshalEasyJSON(l *jlexer.Lexer)

UnmarshalEasyJSON supports easyjson.Unmarshaler interface

func (*Response) UnmarshalJSON

func (v *Response) UnmarshalJSON(data []byte) error

UnmarshalJSON supports json.Unmarshaler interface

type ResponseResult

type ResponseResult struct {
	MessageID      string `json:"message_id"`
	RegistrationID string `json:"registration_id"`
	// error codes:
	// https://firebase.google.com/docs/cloud-messaging/http-server-ref#table9
	Error string `json:"error"`
}

func (ResponseResult) MarshalEasyJSON

func (v ResponseResult) MarshalEasyJSON(w *jwriter.Writer)

MarshalEasyJSON supports easyjson.Marshaler interface

func (ResponseResult) MarshalJSON

func (v ResponseResult) MarshalJSON() ([]byte, error)

MarshalJSON supports json.Marshaler interface

func (*ResponseResult) UnmarshalEasyJSON

func (v *ResponseResult) UnmarshalEasyJSON(l *jlexer.Lexer)

UnmarshalEasyJSON supports easyjson.Unmarshaler interface

func (*ResponseResult) UnmarshalJSON

func (v *ResponseResult) UnmarshalJSON(data []byte) error

UnmarshalJSON supports json.Unmarshaler interface

Jump to

Keyboard shortcuts

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