Documentation
¶
Overview ¶
Package pushover provides a wrapper around the Pushover API
Index ¶
- Constants
- Variables
- func Int(i int) *int
- func String(s string) *string
- type Errors
- type Glance
- type Group
- type GroupDetailsResponse
- type GroupsListResponse
- type Limit
- type Message
- type Pushover
- func (p *Pushover) AddUserToGroup(groupKey, userKey string, device string, memo string) (*Response, error)
- func (p *Pushover) CancelEmergencyNotification(receipt string) (*Response, error)
- func (p *Pushover) CreateGroup(name string) (*Response, error)
- func (p *Pushover) DisableUserInGroup(groupKey, userKey string, device string) (*Response, error)
- func (p *Pushover) EnableUserInGroup(groupKey, userKey string, device string) (*Response, error)
- func (p *Pushover) GetGroup(groupKey string) (*GroupDetailsResponse, error)
- func (p *Pushover) GetReceiptDetails(receipt string) (*ReceiptDetails, error)
- func (p *Pushover) GetRecipientDetails(recipient *Recipient) (*RecipientDetails, error)
- func (p *Pushover) ListGroups() (*GroupsListResponse, error)
- func (p *Pushover) RemoveUserFromGroup(groupKey, userKey string, device string) (*Response, error)
- func (p *Pushover) RenameGroup(groupKey string, name string) (*Response, error)
- func (p *Pushover) SendGlanceUpdate(msg *Glance, rec *Recipient) (*Response, error)
- func (p *Pushover) SendMessage(message *Message, recipient *Recipient) (*Response, error)
- type ReceiptDetails
- type Recipient
- type RecipientDetails
- type Response
Constants ¶
const ( // GlancesAllDevices can be passed as a device name to send a glances-message to all devices GlancesAllDevices = "" // GlancesMessageMaxTitleLength is the max title length in a pushover glance update GlancesMessageMaxTitleLength = 100 // GlancesMessageMaxTextLength is the max text length in a pushover glance update GlancesMessageMaxTextLength = 100 // GlancesMessageMaxSubtextLength is the max subtext length in a pushover glance update GlancesMessageMaxSubtextLength = 100 )
const ( // MessageMaxLength is the max message number of characters. MessageMaxLength = 1024 // MessageTitleMaxLength is the max title number of characters. MessageTitleMaxLength = 250 // MessageURLMaxLength is the max URL number of characters. MessageURLMaxLength = 512 // MessageURLTitleMaxLength is the max URL title number of characters. MessageURLTitleMaxLength = 100 // MessageMaxAttachmentByte is the max attachment size in byte. MessageMaxAttachmentByte = 2621440 )
API limitations.
const ( PriorityLowest = -2 PriorityLow = -1 PriorityNormal = 0 PriorityHigh = 1 PriorityEmergency = 2 )
Message priorities
const ( SoundPushover = "pushover" SoundBike = "bike" SoundBugle = "bugle" SoundCashRegister = "cashregister" SoundClassical = "classical" SoundCosmic = "cosmic" SoundFalling = "falling" SoundGamelan = "gamelan" SoundIncoming = "incoming" SoundIntermission = "intermission" SoundMagic = "magic" SoundMechanical = "mechanical" SoundPianobar = "pianobar" SoundSiren = "siren" SoundSpaceAlarm = "spacealarm" SoundTugBoat = "tugboat" SoundAlien = "alien" SoundClimb = "climb" SoundPersistent = "persistent" SoundEcho = "echo" SoundUpDown = "updown" SoundVibrate = "vibrate" SoundNone = "none" )
Sounds
Variables ¶
var ( ErrHTTPPushover = errors.New("pushover: http error") ErrEmptyToken = errors.New("pushover: empty API token") ErrEmptyURL = errors.New("pushover: empty URL, URLTitle needs an URL") ErrEmptyRecipientToken = errors.New("pushover: empty recipient token") ErrInvalidRecipientToken = errors.New("pushover: invalid recipient token") ErrInvalidHeaders = errors.New("pushover: invalid headers in server response") ErrInvalidPriority = errors.New("pushover: invalid priority") ErrInvalidToken = errors.New("pushover: invalid API token") ErrMessageEmpty = errors.New("pushover: message empty") ErrMessageTitleTooLong = errors.New("pushover: message title too long") ErrMessageTooLong = errors.New("pushover: message too long") ErrMessageAttachmentTooLarge = errors.New("pushover: message attachment is too large") ErrMessageURLTitleTooLong = errors.New("pushover: message URL title too long") ErrMessageURLTooLong = errors.New("pushover: message URL too long") ErrMissingAttachment = errors.New("pushover: missing attachment") ErrMissingEmergencyParameter = errors.New("pushover: missing emergency parameter") ErrInvalidDeviceName = errors.New("pushover: invalid device name") ErrEmptyReceipt = errors.New("pushover: empty receipt") ErrGlancesMissingData = errors.New("pushover: glance update data missing") ErrGlancesTitleTooLong = errors.New("pushover: glance title too long") ErrGlancesTextTooLong = errors.New("pushover: glance text too long") ErrGlancesSubtextTooLong = errors.New("pushover: glance subtext too long") ErrGlancesInvalidPercent = errors.New("pushover: glance percent must be in range of 0-100") )
Pushover custom errors.
var APIEndpoint = "https://api.pushover.net/1"
APIEndpoint is the API base URL for any request.
Functions ¶
Types ¶
type Glance ¶ added in v1.2.0
type Glance struct {
// Title(max 100): a description of the data being shown, such as "Widgets Sold"
Title *string
// Text(max 100): the main line of data, used on most screens
Text *string
// Subtext(max 100): a second line of data
Subtext *string
// Count(can be negative): shown on smaller screens; useful for simple counts
Count *int
// Percent(0-100): shown on some screens as a progress bar/circle
Percent *int
DeviceName string
}
Glance represents a pushover glances update request.
type Group ¶ added in v1.4.0
Group represents a Pushover Delivery Group. ref: https://pushover.net/api/groups
type GroupDetailsResponse ¶ added in v1.4.0
type GroupDetailsResponse struct {
Status int `json:"status"`
RequestID string `json:"request"`
Name string `json:"name"`
Users []struct {
User string `json:"user"`
Device *string `json:"device"`
Memo string `json:"memo"`
Disabled bool `json:"disabled"`
} `json:"users"`
}
GroupDetailsResponse contains the details of a group that was requested.
type GroupsListResponse ¶ added in v1.4.0
type GroupsListResponse struct {
Status int `json:"status"`
RequestID string `json:"request"`
Errors Errors `json:"errors"`
Groups []Group `json:"groups"`
}
GroupsListResponse is the response from a group list request.
type Limit ¶
type Limit struct {
// Total number of messages you can send during a month.
Total int
// Remaining number of messages you can send until the next reset.
Remaining int
// NextReset is the time when all the app counters will be reseted.
NextReset time.Time
}
Limit represents the limitation of the application. This information is fetched when posting a new message.
Headers example: X-Limit-App-Limit: 7500 X-Limit-App-Remaining: 7496 X-Limit-App-Reset: 1393653600
type Message ¶
type Message struct {
// Required
Message string
// Optional
Title string
Priority int
URL string
URLTitle string
Timestamp int64
Retry time.Duration
Expire time.Duration
CallbackURL string
DeviceName string
Sound string
HTML bool
Monospace bool
TTL time.Duration
// contains filtered or unexported fields
}
Message represents a pushover message.
func NewMessageWithTitle ¶
NewMessageWithTitle returns a simple new message with a title.
type Pushover ¶
type Pushover struct {
// contains filtered or unexported fields
}
Pushover is the representation of an app using the pushover API.
func (*Pushover) AddUserToGroup ¶ added in v1.4.0
func (p *Pushover) AddUserToGroup(groupKey, userKey string, device string, memo string) (*Response, error)
AddUserToGroup adds a user with userKey to the group with groupKey. If device or memo are provided, they are associated with the subscription. ref: https://pushover.net/api/groups#add_user
func (*Pushover) CancelEmergencyNotification ¶
CancelEmergencyNotification helps stop a notification retry in case of a notification with an Emergency priority before reaching the expiration time. It requires the response receipt in order to stop the right notification.
func (*Pushover) CreateGroup ¶ added in v1.4.0
CreateGroup creates a new pushover group with the given name. The Group ID is returned as Response.Group. ref: https://pushover.net/api/groups#create
func (*Pushover) DisableUserInGroup ¶ added in v1.4.0
DisableUserInGroup disables a user with userKey in the group with groupKey. If device is provided, only the given device is disabled in the group. ref: https://pushover.net/api/groups#disable_user
func (*Pushover) EnableUserInGroup ¶ added in v1.4.0
EnableUserInGroup enables a user with userKey in the group with groupKey. If device is provided, only the given device is enabled in the group. ref: https://pushover.net/api/groups#enable_user
func (*Pushover) GetGroup ¶ added in v1.4.0
func (p *Pushover) GetGroup(groupKey string) (*GroupDetailsResponse, error)
GetGroup retrieves information about a given groupKey. ref: https://pushover.net/api/groups#show
func (*Pushover) GetReceiptDetails ¶
func (p *Pushover) GetReceiptDetails(receipt string) (*ReceiptDetails, error)
GetReceiptDetails return detailed information about a receipt. This is used used to check the acknowledged status of an Emergency notification.
func (*Pushover) GetRecipientDetails ¶
func (p *Pushover) GetRecipientDetails(recipient *Recipient) (*RecipientDetails, error)
GetRecipientDetails allows to check if a recipient exists, if it's a group and the devices associated to this recipient. The Errors field of the RecipientDetails object will contain an error if the recipient is not valid in the Pushover API.
func (*Pushover) ListGroups ¶ added in v1.4.0
func (p *Pushover) ListGroups() (*GroupsListResponse, error)
ListGroups retrieves a list of groups. ref: https://pushover.net/api/groups#list
func (*Pushover) RemoveUserFromGroup ¶ added in v1.4.0
RemoveUserFromGroup removes a user with userKey from the group with groupKey. If device is provided, only the given device is removed from the group. ref: https://pushover.net/api/groups#remove_user
func (*Pushover) RenameGroup ¶ added in v1.4.0
RenameGroup renames the group with groupKey to the provided name. ref: https://pushover.net/api/groups#rename
func (*Pushover) SendGlanceUpdate ¶ added in v1.2.0
SendGlanceUpdate is used to send glance updates to a recipient. It can be used to display widgets on a smart watch
type ReceiptDetails ¶
type ReceiptDetails struct {
Status int
Acknowledged bool
AcknowledgedBy string
Expired bool
CalledBack bool
ID string
AcknowledgedAt *time.Time
LastDeliveredAt *time.Time
ExpiresAt *time.Time
CalledBackAt *time.Time
}
ReceiptDetails represents the receipt informations in case of emergency priority.
func (*ReceiptDetails) UnmarshalJSON ¶
func (r *ReceiptDetails) UnmarshalJSON(data []byte) error
UnmarshalJSON is a custom unmarshal function to handle timestamps and boolean as int and convert them to the right type.
type Recipient ¶
type Recipient struct {
// contains filtered or unexported fields
}
Recipient represents a recipient to notify.
func NewRecipient ¶
NewRecipient is the representation of the recipient to notify. A recipient may be a Group ID.
type RecipientDetails ¶
type RecipientDetails struct {
Status int `json:"status"`
Group int `json:"group"`
Devices []string `json:"devices"`
RequestID string `json:"request"`
Errors Errors `json:"errors"`
}
RecipientDetails represents the receipt informations in case of emergency priority.