apnsapi

package module
v0.0.0-...-097d8a1 Latest Latest
Warning

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

Go to latest
Published: Apr 6, 2017 License: MIT Imports: 12 Imported by: 0

README

wercker status

apnsapi

Simple apns api (http/2) client for golang.

USAGE

It provides only client, so should setup http/2 client, apns payload yourself.

token := "..."
client := apnsapi.NewClient(apnsapi.ProductionServer, &http.Client{...})
header := &apnsapi.Header{ApnsTopic: "..."}
payload := `{ "aps" : { "alert" : "hi" } }`
if _, err = client.Do(token, header, []byte{payload}); err != nil {
    ...
}

_example/main.go is sample implantation and used like this.

APNs Provider Certificates
$ go run _example/main.go --p12 /path/to/file.p12 --topic $topic --token $token
Provider Authentication Tokens
$ go run _example/main.go --key /path/to/file.p8 --kid $keyIdentifier --teamId $teamID --topic $topic --token $token

SEE ALSO

LICENSE

MIT

Documentation

Index

Constants

View Source
const (
	DevelopmentServer = "https://api.development.push.apple.com"
	ProductionServer  = "https://api.push.apple.com"
)
View Source
const (
	ErrBadCollapseId               = "BadCollapseId"
	ErrBadDeviceToken              = "BadDeviceToken"
	ErrBadExpirationDate           = "BadExpirationDate"
	ErrBadMessageId                = "BadMessageId"
	ErrBadPriority                 = "BadPriority"
	ErrBadTopic                    = "BadTopic"
	ErrDeviceTokenNotForTopic      = "DeviceTokenNotForTopic"
	ErrDuplicateHeaders            = "DuplicateHeaders"
	ErrIdleTimeout                 = "IdleTimeout"
	ErrMissingDeviceToken          = "MissingDeviceToken"
	ErrMissingTopic                = "MissingTopic"
	ErrPayloadEmpty                = "PayloadEmpty"
	ErrTopicDisallowed             = "TopicDisallowed"
	ErrBadCertificate              = "BadCertificate"
	ErrBadCertificateEnvironment   = "BadCertificateEnvironment"
	ErrExpiredProviderToken        = "ExpiredProviderToken"
	ErrForbidden                   = "Forbidden"
	ErrInvalidProviderToken        = "InvalidProviderToken"
	ErrMissingProviderToken        = "MissingProviderToken"
	ErrBadPath                     = "BadPath"
	ErrMethodNotAllowed            = "MethodNotAllowed"
	ErrUnregistered                = "Unregistered"
	ErrPayloadTooLarge             = "PayloadTooLarge"
	ErrTooManyProviderTokenUpdates = "TooManyProviderTokenUpdates"
	ErrTooManyRequests             = "TooManyRequests"
	ErrInternalServerError         = "InternalServerError"
	ErrServiceUnavailable          = "ServiceUnavailable"
	ErrShutdown                    = "Shutdown"
)

Variables

This section is empty.

Functions

func CreateToken

func CreateToken(key *ecdsa.PrivateKey, kid string, teamID string) (string, error)

Types

type Client

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

func NewClient

func NewClient(host string, client *http.Client) *Client

func (*Client) Do

func (c *Client) Do(token string, header *Header, payload []byte) (*Response, error)

func (*Client) NewRquest

func (c *Client) NewRquest(token string, header *Header, payload io.Reader) (*http.Request, error)

type ErrorResponse

type ErrorResponse struct {
	Reason    string `json:"reason"`
	Timestamp int    `json:"timestamp"`
}

func (*ErrorResponse) Error

func (e *ErrorResponse) Error() string
type Header struct {
	ApnsID         string
	ApnsExpiration string
	ApnsPriority   string
	ApnsTopic      string
	Authorization  string
}

type Response

type Response struct {
	ApnsID     string
	StatusCode int
}

Directories

Path Synopsis

Jump to

Keyboard shortcuts

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