apnian

package module
v1.0.4 Latest Latest
Warning

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

Go to latest
Published: Jan 19, 2020 License: MIT Imports: 8 Imported by: 0

README

Apnian

Build Status Coverage Status Go Report Card License Release

About

Apnian is a wrapper around the sideshow/apns2 Apple Push Notification Service library. APNs allows you to send messages to your Apple devices such as an iPhone or Apple Watch.

Usage

Step 1

Create an Apnian config file and place in of of the following four places: ., .., $HOME, or $GOPATH\config.

Here's an example called apnian.yaml:

P8KeyName: YourP8KeyFileName.p8
Topic: TheBundleIdentifierYourSendingNotificationsTo
APNSKeyID: YourAPNSKeyID
TeamID: YourTeamID
Step 2

Place your Apple provided p8 file under $GOPATH/keys

Step 3

Call Apnian from your code:

package main

import (
    "fmt"
    "github.com/electronicpanopticon/apnian.go"
    "log"
)

func main() {
    apn, err := apnian.New("apnian")
    deviceID := "123456"
    apsMessage := apnian.GenerateAPS("Bawk! Bawk! Bawk! 🐔", "default", "https://electronicpanopticon.com")
    response, err := apn.Push(deviceID, apsMessage)
    if err != nil {
        log.Fatal(err)
    }
    fmt.Printf("%v %v %v\n", response.StatusCode, response.ApnsID, response.Reason)
}
Step 5

Profit!

TODO

  • More expressive APS messages

Libraries

Reference

TODO

Via Appia

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type APS

type APS struct {
	APS Payload `json:"aps"`
}

func GenerateAPS

func GenerateAPS(alert string, sound string, linkUrl string) *APS

func (APS) ToJsonBytes

func (aps APS) ToJsonBytes() []byte

type Apnian

type Apnian struct {
	P8KeyName  string
	Topic      string
	APNSKeyID  string
	TeamID     string
	Configurer *ApnianConfigurer
	Client     *apns2.Client
}

func New

func New(configName string) (*Apnian, error)

New returns an Apnian filed with the values in its config file. Locations it looks for are:

.
..
$GOPATH/config
$HOME

func (Apnian) AuthKey

func (apnian Apnian) AuthKey() (*ecdsa.PrivateKey, error)

AuthKey returns the ECDSA private key specified in the Apnian file.

func (Apnian) AuthKeyPath

func (apnian Apnian) AuthKeyPath() string

AuthKeyPath returns the path to the ECDSA private key specified in the Apnian file.

func (Apnian) Notification

func (apnian Apnian) Notification(deviceID string, payload *APS) *apns2.Notification

func (Apnian) Push

func (apnian Apnian) Push(deviceID string, payload *APS) (*apns2.Response, error)

func (Apnian) Token

func (apnian Apnian) Token() (*token.Token, error)

Token represents an Apple Provider Authentication Token (JSON Web Token) configured with the values from the Apnian file.

type ApnianConfigurer

type ApnianConfigurer struct {
	ConfigName string
	Root       string
}

type Payload

type Payload struct {
	Alert   string `json:"alert"`
	Sound   string `json:"sound"`
	LinkUrl string `json:"link_url"`
}

Jump to

Keyboard shortcuts

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