poclient

package module
v0.0.0-...-9d02d3d Latest Latest
Warning

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

Go to latest
Published: Apr 25, 2022 License: MIT Imports: 9 Imported by: 1

README

go-pushover-openclient

A library implementing the Pushover Open Client API to receive Pushover notifications

Documentation: https://godoc.org/github.com/jangxx/go-poclient

Documentation

Index

Constants

View Source
const LIBRARY_NAME string = "go-poclient"
View Source
const LIBRARY_VERSION string = "1.2.0"

Variables

This section is empty.

Functions

This section is empty.

Types

type Client

type Client struct {
	Messages chan Message
	// contains filtered or unexported fields
}

Client represents the main Pushover Client. The Messages channel works in conjunction with ListenForNotifications, which pushes incoming Messages into this channel.

func New

func New() *Client

New creates a new POClient with default values

func (*Client) CloseWebsocket

func (p *Client) CloseWebsocket()

CloseWebsocket forcefully closes a open websocket connection, if one exists This also causes a running ListenForNotifications to return an error, which you can use to reconnect

func (Client) DeleteMessagesByID

func (p Client) DeleteMessagesByID(highestID int) error

DeleteMessagesByID marks all messages below the given relative ID as read which means they will not be transmitted again by the API https://pushover.net/api/client#delete

func (Client) DeleteOldMessages

func (p Client) DeleteOldMessages(messages []Message) error

DeleteOldMessages finds the hightest relative ID and calls DeleteMessagesByID This action is permanent, so you need to save the messages if you want to keep them

func (Client) Device

func (p Client) Device() string

Device returns the device ID

func (Client) GetMessages

func (p Client) GetMessages() ([]Message, error)

GetMessages retrieves all new messages from the API. Usually you call DeleteOldMessages right afterwards to clear all pending notifications

func (*Client) GetStatus

func (p *Client) GetStatus() (bool, bool)

GetStatus returns the login and registration status

func (*Client) ListenForNotifications

func (p *Client) ListenForNotifications() error

ListenForNotifications connects to the WebSocket endpoint and waits for incoming notifications This function is designed to run in a goroutine If no keep-alive packet is received for one minute, the function exits with a timeout error (net.Error). Note: This function clears all notifications after receiving them, so you should pull messages from the Messages channel and save them if you want to keep them

func (*Client) Login

func (p *Client) Login(email string, password string) error

Login retrieves user id and user secret. After successfully logging, you should retrieve the user id and secret by calling User() and store them somewhere safe.

func (*Client) Login2FA

func (p *Client) Login2FA(email string, password string, twofacode string) error

func (*Client) RegisterDevice

func (p *Client) RegisterDevice(name string) error

RegisterDevice registers a new device after logging in. The name parameter is a human readable short name (up to 25 characters long) for the device. After successfully registering the device you should retrieve the device_id by calling Device() and store it in a safe place.

func (*Client) RestoreDevice

func (p *Client) RestoreDevice(devid string)

RestoreDevice sets device ID from a previous device registration

func (*Client) RestoreLogin

func (p *Client) RestoreLogin(secret string, userid string)

RestoreLogin sets user ID and secret to access the API from a previous login

func (Client) SendRequest

func (p Client) SendRequest(endpoint string, data url.Values) (*http.Response, error)

func (*Client) SetAppInfo

func (p *Client) SetAppInfo(appName string, appVersion string)

SetAppInfo sets information about the calling app, which is sent with every request so that pushover can identify the applications using their API

func (Client) User

func (p Client) User() (userID string, secret string)

User returns user id and user secret

type ErrorFrameError

type ErrorFrameError struct{}

func (*ErrorFrameError) Error

func (e *ErrorFrameError) Error() string

type Message

type Message struct {
	RelativeID   int                `json:"id"`
	UniqueID     int                `json:"umid"`
	Title        string             `json:"title"`
	Text         string             `json:"message"`
	AppName      string             `json:"app"`
	AppID        int                `json:"aid"`
	IconID       string             `json:"icon"`
	Timestamp    int64              `json:"date"`
	Date         time.Time          `json:"-"`
	Priority     int                `json:"priority"`
	Sound        string             `json:"sound"`
	URL          string             `json:"url"`
	URLTitle     string             `json:"url_title"`
	Acknowledged convertibleBoolean `json:"acked"`
	ReceiptCode  string             `json:"receipt"`
	ContainsHTML convertibleBoolean `json:"html"`
}

Message represents a message loaded from the API The fields are documented here: https://pushover.net/api/client#download

type Missing2FAError

type Missing2FAError struct{}

func (*Missing2FAError) Error

func (e *Missing2FAError) Error() string

Jump to

Keyboard shortcuts

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