pushover

package
v0.0.0-...-d0539ee Latest Latest
Warning

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

Go to latest
Published: Sep 13, 2015 License: GPL-3.0 Imports: 12 Imported by: 2

README

PushOver Go Library

Documentation

Index

Constants

View Source
const (
	BaseUrl   = "https://api.pushover.net/1"
	ClientUrl = "https://client.pushover.net"
)
View Source
const (
	LowestPriority  = -2 // lowest priority, no notification
	LowPriority     = -1 // low priority, no sound and vibration
	NormalPriority  = 0  // normal priority, default
	HighPriority    = 1  // high priority, always with sound and vibration
	HighestPriority = 2  // emergency priority, requires acknowledge
)

Message priority

View Source
const (
	PushoverSound     = "pushover"
	BikeSound         = "bike"
	BugleSound        = "bugle"
	CashregisterSound = "cashregister"
	ClassicalSound    = "classical"
	CosmicSound       = "cosmic"
	FallingSound      = "falling"
	GamelanSound      = "gamelan"
	IncomingSound     = "incoming"
	IntermissionSound = "intermission"
	MagicSound        = "magic"
	MechanicalSound   = "mechanical"
	PianobarSound     = "pianobar"
	SirenSound        = "siren"
	SpacealarmSound   = "spacealarm"
	TugboatSound      = "tugboat"
	AlienSound        = "alien"
	ClimbSound        = "climb"
	PersistentSound   = "persistent"
	EchoSound         = "echo"
	UpdownSound       = "updown"
	NoneSound         = "none"
)

Message sound Should be used for speciying sounds before sending messages

View Source
const (
	UserKeyLimit  = 30
	AppTokenLimit = 30

	MessageTitleLimit = 100
	MessageLimit      = 512

	UrlTitleLimit = 100
	UrlLimit      = 512

	DeviceNameLimit = 25
	DeviceUUIDLimit = 36

	ReceiptLimit = 30
)

Pushover api limits

Variables

View Source
var (
	ErrMsgNoEnc     = errors.New("Message is not encrypted")
	ErrSecretBox    = errors.New("Failed to open Secretbox")
	ErrHMAC         = errors.New("Unable to generate HMAC")
	ErrVerifyHMAC   = errors.New("Unable to verify HMAC")
	ErrEncodeBase64 = errors.New("Unable to encode to base64")
)

Errors

View Source
var (
	ErrNotLicensed    = errors.New("Device is not licensed")
	ErrFetchSound     = errors.New("Unable to fetch sound file")
	ErrFetchInvalid   = errors.New("Invalid sound name specified")
	ErrFetchImage     = errors.New("Unable to fetch image")
	ErrLoginFailed    = errors.New("Failed to login")
	ErrDeviceRegister = errors.New("Device register failed")
	ErrPullMsg        = errors.New("Unable to fetch new messages")
	ErrMarkRead       = errors.New("Markread messages failed")
	ErrPushMsg        = errors.New("Unable to push message")
	ErrReceipt        = errors.New("Unable to get receipt")
	ErrDeviceAuth     = errors.New("Device not authenticated")
	ErrUserPassword   = errors.New("User Password not specified")
	ErrUserName       = errors.New("UserName not specified")
	ErrMessageLimit   = errors.New("Message is longer than the limit")
)

Errors

View Source
var (
	ErrVerifyDeviceName = errors.New("DeviceName must contain at least one character and may only contain letters, numbers, dashes, and underscores")
	ErrVerifyUserKey    = fmt.Errorf("User and group identifiers must be at least %d characters long, case-sensitive, and may only contain letters and numbers\n", UserKeyLimit)
	ErrVerifyAppToken   = fmt.Errorf("Application tokens are case-sensitive and must be at least %d characters long, and may only contain letters and numbers\n", AppTokenLimit)
	ErrVerifyReceipt    = fmt.Errorf("Receipt must be at least %s and is case-sensitive", ReceiptLimit)

	ErrMsgLimit   = fmt.Errorf("Message specified is not specified or is over the %d char limit\n", MessageLimit)
	ErrTitleLimit = fmt.Errorf("Title specified is over the %d char limit\n", MessageTitleLimit)
	ErrUrlTLimit  = fmt.Errorf("Url Title specified is over the %d char limit\n", UrlTitleLimit)
	ErrUrlLimit   = fmt.Errorf("The url is over the %d char limit\n", UrlLimit)
	ErrPriority   = errors.New("A priority higher than 1 needs an expiry parm")
)

Errors

View Source
var (

	// Valid encrypted message.
	ValidEncMsg = regexp.MustCompile("@Enc@.?")
)

Some regular expressions

Functions

func VerifyAppToken

func VerifyAppToken(token string) (err error)

func VerifyDeviceName

func VerifyDeviceName(name string) (err error)

func VerifyPushMessage

func VerifyPushMessage(msg PushMessage) (err error)

func VerifyReceipt

func VerifyReceipt(receipt string) (err error)

func VerifyUserKey

func VerifyUserKey(key string) (err error)

Types

type Client

type Client struct {
	Dial func(network, addr string) (net.Conn, error)

	UserName     string // Username
	UserPassword string // User password

	DeviceName string // Device name
	DeviceUUID string // Device UUID

	Key string // Key to use for message encryption and decryption

	Login            Login
	RegisterResponse RegisterResponse
	MessagesResponse MessagesResponse
	MarkReadResponse MarkReadResponse

	AppToken string // Application Token
	UserKey  string // User Key

	Accounting struct {
		AppLimit     string
		AppRemaining string
		AppReset     string
	}

	PushResponse PushResponse
	// contains filtered or unexported fields
}

func (*Client) FetchImage

func (c *Client) FetchImage(icon string) (body []byte, err error)

Pass the icon id to fetch the apropiate image

func (*Client) FetchMessages

func (c *Client) FetchMessages() (fetched int, err error)

func (*Client) FetchSound

func (c *Client) FetchSound(sound string) (body []byte, err error)

Pass the sound name to fetch the apropiate sound

func (*Client) GetReceipt

func (c *Client) GetReceipt(receipt string) (err error)

func (*Client) LoginDevice

func (c *Client) LoginDevice() (err error)

func (*Client) MarkRead

func (c *Client) MarkRead(id int) (err error)

func (*Client) MarkReadHighest

func (c *Client) MarkReadHighest() (err error)

func (*Client) Push

func (c *Client) Push(message string) (err error)

func (*Client) PushMessage

func (c *Client) PushMessage(msg PushMessage, encrypt bool) (err error)

func (*Client) RegisterDevice

func (c *Client) RegisterDevice() (err error)

type Login

type Login struct {
	Status  int    `json: "status"`
	Secret  string `json: "secret"`
	Request string `json: "request"`
	ID      string `json: "id"`
}

type MarkReadResponse

type MarkReadResponse struct {
	Status  int    `json: "status"`
	Request string `json: "request"`
}

type MessagesResponse

type MessagesResponse struct {
	Messages []PullMessage `json: "messages"`
	User     User          `json: "user"`

	Status  int    `json: "status"`
	Request string `json: "request"`
}

type PullMessage

type PullMessage struct {
	ID       int    `json: "id"`
	Umid     int    `json: "umid"`
	Title    string `json: "title"`
	Message  string `json: "message"`
	App      string `json: "app"`
	Aid      int    `json: "aid"`
	Icon     string `json: "icon"`
	Date     int64  `json: "date"`
	Priority int    `json: "priority"`
	Sound    string `json: "sound"`
	Url      string `json: "url"`
	UrlTitle string `json: "url_title"`
	Acked    int    `json: "acked"`
	Receipt  int    `json: "receipt"`
}

Pull Message structure

type PushMessage

type PushMessage struct {
	Device    string // Device name to send to specific devices instead of all
	Title     string // Title of message
	Message   string // Message to send
	Priority  int    // Defaults to 0 although expire needs to be specified when higher than 1
	Url       string // Url to be sent with message
	UrlTitle  string // Url title
	Timestamp int64  // Timestamp which should be a unixstamp
	Sound     string // Sound to be played on client device

	// Emergency notifications
	Expire   int
	Retry    int
	Callback string
}

Push message structure

type PushRespErr

type PushRespErr struct {
	Query string // Query made to the API
	Err   error  // Error message
}

Push Response error structure

func (*PushRespErr) Error

func (e *PushRespErr) Error() string

type PushResponse

type PushResponse struct {
	Receipt string `json: "receipt"`

	Status  int      `json: "status"`
	Request string   `json: "request"`
	Errors  []string `json: "errors"`
}

type Receipt

type Receipt struct {
	Acknowledged    int   `json: "acknowledged"`
	AcknowledgedAt  int   `json: "acknowledged_at"`
	LastDeliveredAt int   `json: "last_delivered_at"`
	Expired         int   `json: "expired"`
	ExpiresAt       int64 `json: "expires_at"`
	CalledBack      int   `json: "called_back"`
	CalledBackAt    int64 `json: "called_back_at"`

	Status  int    `json: "status"`
	Request string `json: "request"`
}

type RegisterResponse

type RegisterResponse struct {
	Status  int    `json: "status"`
	Request string `json: "request"`
	ID      string `json: "id"`
}

type User

type User struct {
	QuietHours        bool `json: "quiet_hours"`
	IsAndroidLicensed bool `json: "is_android_licensed"` // Was the app bought on android?
	IsIOSLicensed     bool `json: "is_ios_licensed"`     // Was the app bought on IOS
	IsDesktopLicensed bool `json: "is_desktop_licensed"` // Was the app bought on the Pushover store
}

Directories

Path Synopsis
examples

Jump to

Keyboard shortcuts

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