apns

package
v0.0.0-...-1f9e68f Latest Latest
Warning

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

Go to latest
Published: Jun 7, 2016 License: Apache-2.0 Imports: 16 Imported by: 0

Documentation

Index

Constants

View Source
const (
	InstanceStateRegistered = iota + 1
	InstanceStateUnregistered
)

Variables

View Source
var (
	ErrElementNotFound = errors.New("Storage: element not found")
)
View Source
var TFAppA = App{
	ID:       "appIdA",
	BundleID: "bundleIdA",
}
View Source
var TFAppB = App{
	ID:       "appIdB",
	BundleID: "bundleIdB",
}
View Source
var TFAppC = App{
	ID:       "appIdC",
	BundleID: "bundleIdC",
}
View Source
var TFInsAA = Instance{
	ID:    "instanceAA",
	State: InstanceStateRegistered,
	App:   &TFAppA,
	Token: "TokenAA",
}
View Source
var TFInsAB = Instance{
	ID:    "instanceAB",
	State: InstanceStateRegistered,
	App:   &TFAppA,
	Token: "TokenAB",
}
View Source
var TFInsAC = Instance{
	ID:    "instanceAC",
	State: InstanceStateRegistered,
	App:   &TFAppA,
	Token: "TokenAC",
}
View Source
var TFInsAD = Instance{
	ID:    "instanceAD",
	State: InstanceStateRegistered,
	App:   &TFAppA,
	Token: "TokenAD",
}
View Source
var TFInsAZ = Instance{
	ID:       "instanceAZ",
	State:    InstanceStateUnregistered,
	App:      &TFAppA,
	Token:    "TokenAZ",
	LastSeen: time.Date(2016, 1, 2, 20, 27, 33, 456, time.UTC).Unix(),
}
View Source
var TFInsBA = Instance{
	ID:    "instanceBA",
	State: InstanceStateRegistered,
	App:   &TFAppB,
	Token: "TokenBA",
}
View Source
var TFInsBB = Instance{
	ID:    "instanceBB",
	State: InstanceStateRegistered,
	App:   &TFAppB,
	Token: "TokenBB",
}
View Source
var TFInsBC = Instance{
	ID:    "instanceBC",
	State: InstanceStateRegistered,
	App:   &TFAppB,
	Token: "TokenBC",
}

Functions

This section is empty.

Types

type AlreadyMappedError

type AlreadyMappedError struct {
	Collisions map[Token]*Instance
}

func (AlreadyMappedError) Error

func (AlreadyMappedError) Error() string

type App

type App struct {
	// ID is and internal id for the app
	ID string

	// Certificate is a SSL certification used to negotiate TLS connection.
	// It's not exported currently as support for certs is missing.
	Certificate tls.Certificate `json:"-"`

	// BundleID represents app in iTunes.
	// It's used to select app when APNS connection is established by matching "apns-topic" or certificate subject.
	BundleID string
}

App is a single application in iTunes.

type ErrorResponse

type ErrorResponse struct {
	// Status is an HTTP status code of the response.
	//
	// Possible values as per APNS documentation:
	// 200  Success - no response other than StatusOK is produced
	// 400  Bad request
	// 403  There was an error with the certificate.
	// 405  The request used a bad :method value. Only POST requests are supported.
	// 410  The device token is no longer active for the topic.
	// 413  The notification payload was too large.
	// 429  The server received too many requests for the same device token.
	// 500  Internal server error
	// 503  The server is shutting down and unavailable.
	Status int `json:"-"`

	// Reason is indicating the reason for the failure.
	Reason ResultReason `json:"reason"`

	// If the value of StatusCode is 410, this is the last time at which APNs
	// confirmed that the device token was no longer valid for the topic.
	Timestamp int64 `json:"timestamp,omitempty"`
}

Response represent a response from APNS to the single RemoteNotification.

type Generator

type Generator struct {
	AppTotal            int
	InstancesPerApp     int
	UnregisteredPercent float64
}

func NewGenerator

func NewGenerator(at, ipa int, up float64) *Generator

func (*Generator) Generate

func (g *Generator) Generate(s Storer)

type Handler

type Handler struct {
	Storage Storage
}

func NewHandler

func NewHandler(storage Storage) *Handler

func (*Handler) ServeHTTP

func (h *Handler) ServeHTTP(w http.ResponseWriter, r *http.Request)

type ImportFailureReason

type ImportFailureReason string
const (
	FailUnknownApp ImportFailureReason = "unknownApp"
)

type ImportInstanceFailureReason

type ImportInstanceFailureReason struct {
	ID     string
	AppID  string
	Reason ImportFailureReason
}

type ImportInstancesReport

type ImportInstancesReport struct {
	Succeeded int
	Failed    int
	Failures  []ImportInstanceFailureReason
}

type ImporterStorage

type ImporterStorage interface {
	AppLoad(id string) (*App, error)
	AppSave(o *App) error
	InstanceSave(o *Instance) error
}

type Instance

type Instance struct {
	ID    string
	State InstanceState
	App   *App
	Token Token

	// LastSeen is timestamp when device was last seen.
	// Used when device is unregistered.
	LastSeen int64 `json:",omitempty"`
}

type InstanceExported

type InstanceExported struct {
	Instance

	AppID string
	App   omit `json:"App,omitempty"`
}

type InstanceState

type InstanceState int

type JSONExporter

type JSONExporter struct {
	AppWriter      io.Writer
	InstanceWriter io.Writer

	AppEncoder      *json.Encoder
	InstanceEncoder *json.Encoder
}

JSONExporter exports data in JSON format. Implements android.Storer interface for generator.

func NewJSONExporter

func NewJSONExporter(appWriter, instanceWriter io.Writer) *JSONExporter

func (*JSONExporter) AppSave

func (e *JSONExporter) AppSave(o *App) error

func (*JSONExporter) InstanceSave

func (e *JSONExporter) InstanceSave(o *Instance) error

type JSONImporter

type JSONImporter struct {
	Storage ImporterStorage
	Mapper  Mapper
}

func NewJSONImporter

func NewJSONImporter(s ImporterStorage, m Mapper) *JSONImporter

func (*JSONImporter) ImportApps

func (i *JSONImporter) ImportApps(r io.Reader)

func (*JSONImporter) ImportInstances

func (i *JSONImporter) ImportInstances(r io.Reader) ImportInstancesReport

type Mapper

type Mapper interface {
	Add(i *Instance) error
}

type MemoryMapper

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

func NewMemoryMapper

func NewMemoryMapper() *MemoryMapper

func (*MemoryMapper) Add

func (m *MemoryMapper) Add(i *Instance) error

type MemoryStorage

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

func NewMemoryStorage

func NewMemoryStorage() *MemoryStorage

func (*MemoryStorage) AppFind

func (s *MemoryStorage) AppFind(apiKey string) (*App, error)

func (*MemoryStorage) AppLoad

func (s *MemoryStorage) AppLoad(id string) (*App, error)

func (*MemoryStorage) AppSave

func (s *MemoryStorage) AppSave(o *App) error

func (*MemoryStorage) InstanceFind

func (s *MemoryStorage) InstanceFind(appID string, token Token) (*Instance, error)

func (*MemoryStorage) InstanceLoad

func (s *MemoryStorage) InstanceLoad(aID, iID string) (*Instance, error)

func (*MemoryStorage) InstanceSave

func (s *MemoryStorage) InstanceSave(o *Instance) error

func (*MemoryStorage) InstancesTotal

func (s *MemoryStorage) InstancesTotal() int

type MessagePriority

type MessagePriority int
const (
	PriorityHigh MessagePriority = 10
	PriorityLow  MessagePriority = 5
)

type NotificationPayload

type NotificationPayload struct {
	Aps struct {
		// Alert triggers system alert or banner.
		// Can be either string or dictionary (defined in NotificationPayloadApsAlert).
		Alert            interface{} `json:"alert"`
		Badge            int         `json:"badge"`
		Sound            string      `json:"sound"`
		ContentAvailable int         `json:"content-available"`
	} `json:"aps"`
}

NotificationPayload is a payload of the remote notification. As defined in tables 5-1 and 5-2 in APNS documentation ("The Remote Notification Payload" section)

type NotificationPayloadApsAlert

type NotificationPayloadApsAlert struct {
	Title string `json:"title"`
	Body  string `json:"body"`
}

NotificationPayloadApsAlert is verbose structure for alert section See Table 5-2 in APNS docs.

type RemoteNotification

type RemoteNotification struct {
	// Token represents a recipient device token.
	Token string

	// Topic is the name to which the recipient should subscribe to.
	// Typically it's bundle ID of the app.
	Topic string

	// Expiration identifies the date when the notification is no longer valid and can be discarded.
	// It's a UNIX epoch date expressed in seconds (UTC).
	// If this value is nonzero, APNs stores the notification and tries to deliver it at least once,
	// repeating the attempt as needed if it is unable to deliver the notification the first time.
	// If the value is 0, APNs treats the notification as if it expires immediately
	// and does not store the notification or attempt to redeliver it.
	Expiration int64

	// Priority sets the priority of the push in APNS.
	// Specify one of the following values:
	// - 10: Send the push message immediately.
	//       Notifications with this priority must trigger an alert, sound, or badge on the target device.
	//       It is an error to use this priority for a push notification that contains only the content-available key.
	// -  5: Send the push message at a time that takes into account power considerations for the device.
	//       Notifications with this priority might be grouped and delivered in bursts.
	//       They are throttled, and in some cases are not delivered.
	// If you omit this header, the APNs server sets the priority to 10.
	Priority MessagePriority

	// Payload is a content which is send to the device.
	// It's described in "Remote Notification Payload" section of the APNs docs.
	// It have to be JSON encoded.
	Payload []byte
}

RemoteNotification holds a single communication to be submitted to the APNs provider.

type ResultReason

type ResultReason string
const (
	// The message payload was empty.
	ReasonPayloadEmpty ResultReason = "PayloadEmpty"
	// The message payload was too large. The maximum payload size is 4096 bytes.
	ReasonPayloadTooLarge ResultReason = "PayloadTooLarge"
	// The apns-topic was invalid.
	ReasonBadTopic ResultReason = "BadTopic"
	// Pushing to this topic is not allowed.
	ReasonTopicDisallowed ResultReason = "TopicDisallowed"
	// The apns-id value is bad.
	ReasonBadMessageID ResultReason = "BadMessageId"
	// The apns-expiration value is bad.
	ReasonBadExpirationDate ResultReason = "BadExpirationDate"
	// The apns-priority value is bad.
	ReasonBadPriority ResultReason = "BadPriority"
	// The device token is not specified in the request :path. Verify that the
	// :path header contains the device token.
	ReasonMissingDeviceToken ResultReason = "MissingDeviceToken"
	// The specified device token was bad. Verify that the request contains a valid
	// token and that the token matches the environment.
	ReasonBadDeviceToken ResultReason = "BadDeviceToken"
	// The device token does not match the specified topic.
	ReasonDeviceTokenNotForTopic ResultReason = "DeviceTokenNotForTopic"
	// The device token is inactive for the specified topic.
	ReasonUnregistered ResultReason = "Unregistered"
	// One or more headers were repeated.
	ReasonDuplicateHeaders ResultReason = "DuplicateHeaders"
	// The client certificate was for the wrong environment.
	ReasonBadCertificateEnvironment ResultReason = "BadCertificateEnvironment"
	// The certificate was bad.
	ReasonBadCertificate ResultReason = "BadCertificate"
	// The specified action is not allowed.
	ReasonForbidden ResultReason = "Forbidden"
	// The request contained a bad :path value.
	ReasonBadPath ResultReason = "BadPath"
	// The specified :method was not POST.
	ReasonMethodNotAllowed ResultReason = "MethodNotAllowed"
	// Too many requests were made consecutively to the same device token.
	ReasonTooManyRequests ResultReason = "TooManyRequests"
	// Idle time out.
	ReasonIdleTimeout ResultReason = "IdleTimeout"
	// The server is shutting down.
	ReasonShutdown ResultReason = "Shutdown"
	// An internal server error occurred.
	ReasonInternalServerError ResultReason = "InternalServerError"
	// The service is unavailable.
	ReasonServiceUnavailable ResultReason = "ServiceUnavailable"
	// The apns-topic header of the request was not specified and was required.
	// The apns-topic header is mandatory when the client is connected using a
	// certificate that supports multiple topics.
	ReasonMissingTopic ResultReason = "MissingTopic"
)

The possible Reason error codes returned from APNs. From table 6-6 in the Apple Local and Remote Notification Programming Guide. taken from sideshow/apns2 package (MIT license)

func (*ResultReason) Status

func (r *ResultReason) Status() int

type Storage

type Storage interface {
	AppFind(bundleID string) (*App, error)
	InstanceFind(appID string, token Token) (*Instance, error)
}

type Storer

type Storer interface {
	AppSave(o *App) error
	InstanceSave(o *Instance) error
}

type Token

type Token string

Jump to

Keyboard shortcuts

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