apns

package
v0.0.7 Latest Latest
Warning

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

Go to latest
Published: Dec 16, 2021 License: MIT Imports: 15 Imported by: 0

Documentation

Index

Constants

View Source
const (
	DevelopmentGateway = apns2.HostDevelopment
	ProductionGateway  = apns2.HostProduction
)

Variables

This section is empty.

Functions

This section is empty.

Types

type APS

type APS struct {
	// Alert dictionary.
	Alert Alert `json:"alert,omitempty"`

	// Badge to display on the app icon.
	Badge int `json:"badge,omitempty"`

	// Sound is the name of a sound file to play as an alert.
	Sound string `json:"sound,omitempty"`

	// Content available apps launched in the background or resumed.
	ContentAvailable int `json:"content-available,omitempty"`

	// Category identifier for custom actions in iOS 8 or newer.
	Category string `json:"category,omitempty"`

	// ThreadID presents the app-specific identifier for grouping notifications.
	ThreadID string `json:"thread-id,omitempty"`

	// MutableContent presents the flag that lets user’s device know
	// that it should run the corresponding service app extension (if the value equals 1).
	MutableContent int `json:"mutable-content,omitempty"`
}

APS is Apple's reserved payload. easyjson:json

func (APS) MarshalEasyJSON

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

MarshalEasyJSON supports easyjson.Marshaler interface

func (APS) MarshalJSON

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

MarshalJSON supports json.Marshaler interface

func (*APS) UnmarshalEasyJSON

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

UnmarshalEasyJSON supports easyjson.Unmarshaler interface

func (*APS) UnmarshalJSON

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

UnmarshalJSON supports json.Unmarshaler interface

type Alert

type Alert struct {
	Title        string   `json:"title,omitempty"`
	Body         string   `json:"body,omitempty"`
	TitleLocKey  string   `json:"title-loc-key,omitempty"`
	TitleLocArgs []string `json:"title-loc-args,omitempty"`
	ActionLocKey string   `json:"action-loc-key,omitempty"`
	LocKey       string   `json:"loc-key,omitempty"`
	LocArgs      []string `json:"loc-args,omitempty"`
	LaunchImage  string   `json:"launch-image,omitempty"`
}

Alert represents alert dictionary. easyjson:json

func (Alert) MarshalEasyJSON

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

MarshalEasyJSON supports easyjson.Marshaler interface

func (Alert) MarshalJSON

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

MarshalJSON supports json.Marshaler interface

func (*Alert) UnmarshalEasyJSON

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

UnmarshalEasyJSON supports easyjson.Unmarshaler interface

func (*Alert) UnmarshalJSON

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

UnmarshalJSON supports json.Unmarshaler interface

type Client

type Client interface {
	Send(ctx context.Context, n *Notification) error
}

Client describes methods used to send apns notifications.

type ClientMock

type ClientMock struct {
	SendMock mClientMockSend
	// contains filtered or unexported fields
}

ClientMock implements Client

func NewClientMock

func NewClientMock(t minimock.Tester) *ClientMock

NewClientMock returns a mock for Client

func (*ClientMock) MinimockFinish

func (m *ClientMock) MinimockFinish()

MinimockFinish checks that all mocked methods have been called the expected number of times

func (*ClientMock) MinimockSendDone

func (m *ClientMock) MinimockSendDone() bool

MinimockSendDone returns true if the count of the Send invocations corresponds the number of defined expectations

func (*ClientMock) MinimockSendInspect

func (m *ClientMock) MinimockSendInspect()

MinimockSendInspect logs each unmet expectation

func (*ClientMock) MinimockWait

func (m *ClientMock) MinimockWait(timeout mm_time.Duration)

MinimockWait waits for all mocked methods to be called the expected number of times

func (*ClientMock) Send

func (mmSend *ClientMock) Send(ctx context.Context, n *Notification) (err error)

Send implements Client

func (*ClientMock) SendAfterCounter

func (mmSend *ClientMock) SendAfterCounter() uint64

SendAfterCounter returns a count of finished ClientMock.Send invocations

func (*ClientMock) SendBeforeCounter

func (mmSend *ClientMock) SendBeforeCounter() uint64

SendBeforeCounter returns a count of ClientMock.Send invocations

type ClientMockSendExpectation

type ClientMockSendExpectation struct {
	Counter uint64
	// contains filtered or unexported fields
}

ClientMockSendExpectation specifies expectation struct of the Client.Send

func (*ClientMockSendExpectation) Then

Then sets up Client.Send return parameters for the expectation previously defined by the When method

type ClientMockSendParams

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

ClientMockSendParams contains parameters of the Client.Send

type ClientMockSendResults

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

ClientMockSendResults contains results of the Client.Send

type ClientOption

type ClientOption func(c *SimpleClient) error

ClientOption defines athe APNS SimpleClient option.

func WithGateway

func WithGateway(endpoint string) ClientOption

WithGateway specifies custom APN endpoint. Useful for test propose.

func WithHTTPClient

func WithHTTPClient(httpClient *http.Client) ClientOption

WithHTTPClient sets custom HTTP SimpleClient.

func WithJWTAuthorization

func WithJWTAuthorization(cfg JWTConfig) ClientOption

WithJWTAuthorization enables JWT authorization for apns requests.

func WithTimeout

func WithTimeout(t time.Duration) ClientOption

WithTimeout sets HTTP SimpleClient timeout.

type Error

type Error string
const (
	ErrExpiredToken   Error = "ExpiredProviderToken"
	ErrBadDeviceToken Error = "BadDeviceToken"
	ErrUnregistered   Error = "Unregistered"
)

func (Error) Error

func (e Error) Error() string

type ErrorReason

type ErrorReason string

ErrorReason API error reasons https://developer.apple.com/documentation/usernotifications/setting_up_a_remote_notification_server/handling_notification_responses_from_apns

const (
	ReasonExpiredProviderToken ErrorReason = "ExpiredProviderToken"
	ReasonBadDeviceToken       ErrorReason = "BadDeviceToken"
	ReasonCodeUnregistered     ErrorReason = "Unregistered"
)

type JWTConfig

type JWTConfig struct {
	AuthKey []byte
	KeyID   string
	TeamID  string
}

JWTConfig a set of data required for JWT authorization.

type Notification

type Notification struct {
	// An optional canonical UUID that identifies the notification. The
	// canonical form is 32 lowercase hexadecimal digits, displayed in five
	// groups separated by hyphens in the form 8-4-4-4-12. An example UUID is as
	// follows:
	//
	//  123e4567-e89b-12d3-a456-42665544000
	//
	// If you don't set this, a new UUID is created by APNs and returned in the
	// response.
	ApnsID string

	// A string which allows multiple notifications with the same collapse
	// identifier to be displayed to the user as a single notification. The
	// value should not exceed 64 bytes.
	CollapseID string

	// A string containing hexadecimal bytes of the device token for the target
	// device.
	DeviceToken string

	// The topic of the remote notification, which is typically the bundle ApnsID
	// for your app. The certificate you create in the Apple Developer Member
	// Center must include the capability for this topic. If your certificate
	// includes multiple topics, you must specify a value for this header. If
	// you omit this header and your APNs certificate does not specify multiple
	// topics, the APNs server uses the certificate’s Subject as the default
	// topic.
	Topic string

	// An optional time at which the notification is no longer valid and can be
	// discarded by APNs. If this value is in the past, APNs treats the
	// notification as if it expires immediately and does not store the
	// notification or attempt to redeliver it. If this value is left as the
	// default (ie, Expiration.IsZero()) an expiration header will not added to
	// the http request.
	Expiration time.Time

	// The priority of the notification. Specify ether apns.PriorityHigh (10) or
	// apns.PriorityLow (5) If you don't set this, the APNs server will set the
	// priority to 10.
	Priority int

	// A byte array containing the JSON-encoded payload of this push notification.
	// Refer to "The Remote Notification Payload" section in the Apple Local and
	// Remote Notification Programming Guide for more info.
	Payload Payload

	// The pushtype of the push notification. If this values is left as the
	// default an apns-push-type header with value 'alert' will be added to the
	// http request.
	PushType PushType
}

type Payload

type Payload struct {
	APS  APS             `json:"aps"`
	Data json.RawMessage `json:"data"`
}

Payload repsresents a data structure for APN notification. easyjson:json

func (Payload) MarshalEasyJSON

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

MarshalEasyJSON supports easyjson.Marshaler interface

func (Payload) MarshalJSON

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

MarshalJSON supports json.Marshaler interface

func (*Payload) UnmarshalEasyJSON

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

UnmarshalEasyJSON supports easyjson.Unmarshaler interface

func (*Payload) UnmarshalJSON

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

UnmarshalJSON supports json.Unmarshaler interface

type PushType

type PushType string

PushType defines the value for the apns-push-type header

const (
	// PushTypeAlert is used for notifications that trigger a user interaction —
	// for example, an alert, badge, or sound. If you set this push type, the
	// apns-topic header field must use your app’s bundle ApnsID as the topic. The
	// alert push type is required on watchOS 6 and later. It is recommended on
	// macOS, iOS, tvOS, and iPadOS.
	PushTypeAlert PushType = "alert"

	// PushTypeBackground is used for notifications that deliver content in the
	// background, and don’t trigger any user interactions. If you set this push
	// type, the apns-topic header field must use your app’s bundle ApnsID as the
	// topic. The background push type is required on watchOS 6 and later. It is
	// recommended on macOS, iOS, tvOS, and iPadOS.
	PushTypeBackground PushType = "background"

	// PushTypeVOIP is used for notifications that provide information about an
	// incoming Voice-over-IP (VoIP) call. If you set this push type, the
	// apns-topic header field must use your app’s bundle ApnsID with .voip appended
	// to the end. If you’re using certificate-based authentication, you must
	// also register the certificate for VoIP services. The voip push type is
	// not available on watchOS. It is recommended on macOS, iOS, tvOS, and
	// iPadOS.
	PushTypeVOIP PushType = "voip"

	// PushTypeComplication is used for notifications that contain update
	// information for a watchOS app’s complications. If you set this push type,
	// the apns-topic header field must use your app’s bundle ApnsID with
	// .complication appended to the end. If you’re using certificate-based
	// authentication, you must also register the certificate for WatchKit
	// services. The complication push type is recommended for watchOS and iOS.
	// It is not available on macOS, tvOS, and iPadOS.
	PushTypeComplication PushType = "complication"

	// PushTypeFileProvider is used to signal changes to a File Provider
	// extension. If you set this push type, the apns-topic header field must
	// use your app’s bundle ApnsID with .pushkit.fileprovider appended to the end.
	// The fileprovider push type is not available on watchOS. It is recommended
	// on macOS, iOS, tvOS, and iPadOS.
	PushTypeFileProvider PushType = "fileprovider"

	// PushTypeMDM is used for notifications that tell managed devices to
	// contact the MDM server. If you set this push type, you must use the topic
	// from the UID attribute in the subject of your MDM push certificate.
	PushTypeMDM PushType = "mdm"
)

type Response

type Response struct {
	Reason ErrorReason `json:"reason"`
}

easyjson:json

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 RoundTripperJWTDecorator

type RoundTripperJWTDecorator struct {
	Parent http.RoundTripper
	Token  *Token
}

RoundTripperJWTDecorator an implementation of http.RoundTripper interface with ability to specify authorization JWT token for each request.

func (*RoundTripperJWTDecorator) RoundTrip

func (d *RoundTripperJWTDecorator) RoundTrip(r *http.Request) (*http.Response, error)

type SimpleClient

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

SimpleClient represents the Apple Push Notification Service that you send notifications to.

func MustNewClient

func MustNewClient(opts ...ClientOption) *SimpleClient

MustNewClient creates new APNS client based on defined Options.

func (*SimpleClient) Send

func (c *SimpleClient) Send(ctx context.Context, n *Notification) error

Send sends Notification to the APN service.

type Token

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

func NewToken

func NewToken(keyPem []byte, keyID, teamID string) (*Token, error)

func (*Token) Bearer

func (t *Token) Bearer() (bearer string)

Jump to

Keyboard shortcuts

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