api

package
v0.9.0 Latest Latest
Warning

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

Go to latest
Published: Dec 10, 2025 License: MIT Imports: 10 Imported by: 2

Documentation

Overview

Package api defines a consistent Go API for enqueueing or sending APNs pushes to multiple enrollment IDs.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type APIResult

type APIResult struct {
	// Status is the per-enrollment ID results of push or enqueue APIs.
	// Map key is the enrollment ID.
	Status map[string]EnrollmentResult `json:"status,omitempty"`

	// NoPush signifies if APNs pushes were not enabled for this API call.
	NoPush bool `json:"no_push,omitempty"`

	// PushError is present if there was an error sending the APNs push notifications.
	PushError *Error `json:"push_error,omitempty"`

	// EnqueueError is present if there was an error enqueuing the command.
	EnqueueError *Error `json:"command_error,omitempty"`

	CommandUUID string `json:"command_uuid,omitempty"` // CommandUUID of the enqueued command.
	RequestType string `json:"request_type,omitempty"` // RequestType of the enqueued command.
}

APIResult is the result of push or enqueue APIs.

func (*APIResult) Error

func (r *APIResult) Error() error

Error distills the APIResult errors to a simple error or returns nil. If there are more than one error for an enrollment ID the last error is returned. Error tries to preserve at least one "real" error by way of wrapping.

type EnrollmentResult

type EnrollmentResult struct {
	// PushError is present if there was an error sending the APNs push notification.
	PushError *Error `json:"push_error,omitempty"`

	// PushID is the "apns-id" of a successful APNs push notification.
	PushID string `json:"push_result,omitempty"`

	// EnqueueError is present if there was an error enqueuing the command.
	EnqueueError *Error `json:"command_error,omitempty"`
}

EnrollmentResults are the per-enrollment ID results of push or enqueue APIs.

type Error

type Error struct {
	Err error
}

Error wraps errors for marshalling and unmarshalling.

func NewError

func NewError(err error) *Error

NewError contains err in a marshalling and unmarhalling wrapper.

func (*Error) Error

func (e *Error) Error() string

Error returns the error string.

func (*Error) MarshalJSON

func (e *Error) MarshalJSON() ([]byte, error)

MarshalJSON renders the contained error as a JSON string.

func (*Error) UnmarshalJSON

func (e *Error) UnmarshalJSON(b []byte) error

UnmarshalJSON overwrites the contained error with a new plain string error.

func (*Error) Unwrap

func (e *Error) Unwrap() error

Unwrap returns the contained error.

func (*Error) Valid

func (e *Error) Valid() bool

Valid returns true if e and our error are not nil.

type PushEnqueuer

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

PushEnqueuer can enqueue commands and send APNs pushes.

func NewPushEnqueuer

func NewPushEnqueuer(store storage.CommandEnqueuer, pusher push.Pusher, opts ...PushEnqueuerOption) (*PushEnqueuer, error)

NewPushEnqueuer creates a new push enqueuer.

func (*PushEnqueuer) EnqueueWithPush

func (pe *PushEnqueuer) EnqueueWithPush(ctx context.Context, command *mdm.Command, ids []string, noPush bool) (*APIResult, int, error)

EnqueueWithPush enqueues command and can send APNs pushes to ids. A command cannot be nil while noPush is true. The return integer is an indicator of errors with the actual errors contained within the API result. A 500 value indicates only errors (with no successes). A 207 value indicates some sucesses and some failures. A 200 value indicates no errors (with only successes). Any other value is undefined.

func (*PushEnqueuer) Push

func (pe *PushEnqueuer) Push(ctx context.Context, ids []string) (*APIResult, int, error)

Push sends APNs notifications to ids.

func (*PushEnqueuer) RawCommandEnqueueWithPush

func (pe *PushEnqueuer) RawCommandEnqueueWithPush(ctx context.Context, rawCommand []byte, ids []string, noPush bool) (*APIResult, int, error)

RawCommandEnqueueWithPush enqueues rawCommand and can send APNs pushes to ids. See [EnqueueWithPush] for calling semantics.

type PushEnqueuerOption

type PushEnqueuerOption func(*PushEnqueuer) error

PushEnqueuerOptions configures the push enqueuer.

func WithLogger

func WithLogger(logger log.Logger) PushEnqueuerOption

WithLogger configures a logger on a push enqueuer.

func WithNoPush

func WithNoPush() PushEnqueuerOption

WithNoPush disables push attempts.

Jump to

Keyboard shortcuts

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