expo

package
Version: v0.0.0-...-0e9a686 Latest Latest
Warning

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

Go to latest
Published: May 31, 2021 License: MIT Imports: 8 Imported by: 0

Documentation

Index

Constants

View Source
const (
	// DefaultPriority is the standard priority used in PushMessage
	DefaultPriority = "default"
	// NormalPriority is a priority used in PushMessage
	NormalPriority = "normal"
	// HighPriority is a priority used in PushMessage
	HighPriority = "high"
)
View Source
const (
	// DefaultHost is the default Expo host
	DefaultHost = "https://exp.host"
	// DefaultBaseAPIURL is the default path for API requests
	DefaultBaseAPIURL = "/--/api/v2"
)
View Source
const ErrorDeviceNotRegistered = "DeviceNotRegistered"

ErrorDeviceNotRegistered indicates the token is invalid

View Source
const ErrorMessageRateExceeded = "MessageRateExceeded"

ErrorMessageRateExceeded indicates messages have been sent too frequently

View Source
const ErrorMessageTooBig = "MessageTooBig"

ErrorMessageTooBig indicates the message went over payload size of 4096 bytes

View Source
const SuccessStatus = "ok"

SuccessStatus is the status returned from Expo on a success

Variables

View Source
var DefaultHTTPClient = &http.Client{}

DefaultHTTPClient is the default *http.Client for making API requests

View Source
var ErrMalformedToken = errors.New("Token should start with ExponentPushToken")

ErrMalformedToken is returned if a token does not start with 'ExponentPushToken'

Functions

This section is empty.

Types

type ClientConfig

type ClientConfig struct {
	Host       string
	APIURL     string
	HTTPClient *http.Client
}

ClientConfig specifies params that can optionally be specified for alternate Expo config and path setup when sending API requests

type DeviceNotRegisteredError

type DeviceNotRegisteredError struct {
	PushResponseError
}

DeviceNotRegisteredError is raised when the push token is invalid To handle this error, you should stop sending messages to this token.

type ExponentPushToken

type ExponentPushToken string

ExponentPushToken is a valid Expo push token

func NewExponentPushToken

func NewExponentPushToken(token string) (ExponentPushToken, error)

NewExponentPushToken returns a token and may return an error if the input token is invalid

type MessageRateExceededError

type MessageRateExceededError struct {
	PushResponseError
}

MessageRateExceededError is raised when you are sending messages too frequently to a device You should implement exponential backoff and slowly retry sending messages.

type MessageTooBigError

type MessageTooBigError struct {
	PushResponseError
}

MessageTooBigError is raised when the notification was too large. On Android and iOS, the total payload must be at most 4096 bytes.

type PushClient

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

PushClient is an object used for making push notification requests

func NewPushClient

func NewPushClient(config *ClientConfig) *PushClient

NewPushClient creates a new Exponent push client See full API docs at https://docs.getexponent.com/versions/v13.0.0/guides/push-notifications.html#http-2-api

func (*PushClient) Publish

func (c *PushClient) Publish(message *PushMessage) (PushResponse, error)

Publish sends a single push notification @param push_message: A PushMessage object @return an array of PushResponse objects which contains the results. @return error if any requests failed

func (*PushClient) PublishMultiple

func (c *PushClient) PublishMultiple(messages []PushMessage) ([]PushResponse, error)

PublishMultiple sends multiple push notifications at once @param push_messages: An array of PushMessage objects. @return an array of PushResponse objects which contains the results. @return error if the request failed

type PushMessage

type PushMessage struct {
	To         []ExponentPushToken `json:"to"`
	Body       string              `json:"body"`
	Data       map[string]string   `json:"data,omitempty"`
	Sound      string              `json:"sound,omitempty"`
	Title      string              `json:"title,omitempty"`
	TTLSeconds int                 `json:"ttl,omitempty"`
	Expiration int64               `json:"expiration,omitempty"`
	Priority   string              `json:"priority,omitempty"`
	Badge      int                 `json:"badge,omitempty"`
	ChannelID  string              `json:"channelId,omitempty"`
}

PushMessage is an object that describes a push notification request. Fields:

	To: an ExponentPushToken
	Data: A dict of extra data to pass inside of the push notification.
	      The total notification payload must be at most 4096 bytes.
	Title: The title to display in the notification. On iOS, this is
	       displayed only on Apple Watch.
	Body: The message to display in the notification.
	Sound: A sound to play when the recipient receives this
	       notification. Specify "default" to play the device's default
	       notification sound, or omit this field to play no sound.
	TTLSeconds: The number of seconds for which the message may be kept around
	     for redelivery if it hasn't been delivered yet. Defaults to 0.
	Expiration: UNIX timestamp for when this message expires. It has
	        the same effect as ttl, and is just an absolute timestamp
	        instead of a relative one.
	Priority: Delivery priority of the message. Use the *Priority constants
         specified above.
	Badge: An integer representing the unread notification count. This
	       currently only affects iOS. Specify 0 to clear the badge count.
	ChannelID: ID of the Notification Channel through which to display this
        notification on Android devices.

type PushResponse

type PushResponse struct {
	PushMessage PushMessage
	Status      string            `json:"status"`
	Message     string            `json:"message"`
	Details     map[string]string `json:"details"`
}

PushResponse is a wrapper class for a push notification response. A successful single push notification:

{'status': 'ok'}

An invalid push token

{'status': 'error',
 'message': '"adsf" is not a registered push notification recipient'}

func (*PushResponse) ValidateResponse

func (r *PushResponse) ValidateResponse() error

ValidateResponse returns an error if the response indicates that one occurred. Clients should handle these errors, since these require custom handling to properly resolve.

type PushResponseError

type PushResponseError struct {
	Response *PushResponse
}

PushResponseError is a base class for all push reponse errors

func (*PushResponseError) Error

func (e *PushResponseError) Error() string

type PushServerError

type PushServerError struct {
	Message      string
	Response     *http.Response
	ResponseData *Response
	Errors       []map[string]string
}

PushServerError is raised when the push token server is not behaving as expected For example, invalid push notification arguments result in a different style of error. Instead of a "data" array containing errors per notification, an "error" array is returned. {"errors": [

{"code": "API_ERROR",
 "message": "child \"to\" fails because [\"to\" must be a string]. \"value\" must be an array."
}

]}

func NewPushServerError

func NewPushServerError(message string, response *http.Response,
	responseData *Response,
	errors []map[string]string) *PushServerError

NewPushServerError creates a new PushServerError object

func (*PushServerError) Error

func (e *PushServerError) Error() string

type Response

type Response struct {
	Data   []PushResponse      `json:"data"`
	Errors []map[string]string `json:"errors"`
}

Response is the HTTP response returned from an Expo publish HTTP request

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
t or T : Toggle theme light dark auto
y or Y : Canonical URL