pushnotifier

package module
v1.0.0 Latest Latest
Warning

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

Go to latest
Published: Sep 28, 2022 License: MIT Imports: 12 Imported by: 0

README

PushNotifier (V2) for Go

Go Tests

A go module to easily interact with the service of PushNotifier in your go projects.

You can find the documentation on pkgo.dev

About

Using this go module you can easily send:

  • messages
  • URLs
  • images

For more information visit pushnotifier.de

Installation

  • Install module via go get
$ go get github.com/mavjs/pushnotifier

This package also provides a rudimentary command line application called: pnctl. To install:

$ go get github.com/mavjs/pushnotifier/cmd/pnctl

Usage

Main package
import (
    "github.com/mavjs/pushnotifier"
)

pn := pushnotifier.NewClient(nil, "dev.myapps.pn", "BBCCVV1122...", "ZZXX11ff...")
Sending Notification Messages
// Sends a notification with text "hello world" to all registered devices silently.
// Meaning it will not create a notification sound/vibration.
pn.SendText("hello world", nil, true)

// Sends a notification with text "dlrow olleh" to selected devices.
// Meaning it will create a notification sound and or vibration.
pn.SendText("dlrow olleh", []string{"abcd", "efgh"}, false)

// Sends a notification with url "http://example.com"
pn.SendURL("http://example.com", []string{"abcd", "efgh"}, false)

// Sends a notification with text "hello world" and url "http://example.com"
// Upon clicking the notification this will open the default browser to the provided URL.
pn.SendNotification("hello world", "http://example.com", []string{"abcd", "efgh"}, false)

// Sends a notification with an images
pn.SendImage("path/to/image.png", []string{"abcd", "efgh"}, false)
Get Basic Information
pn.GetDevices()

[GetDevices] Registered devices for user obtained
Devices: [abcd efgh ijkl]
Refresh App Token
pn.RefreshToken()

[RefreshToken] App Token for user obtained
Command Line Application - pnctl
$ pnctl help

pnctl - a commandline application that can be used to send different types of notifications to your registered devices.
You can send text and or url, or image as notifications.

Usage:
  pnctl [command]

Available Commands:
  completion  Generate the autocompletion script for the specified shell
  getdevices  Get connected devices
  help        Help about any command
  register    Registers API authentication details
  send        Sends different types of content to registered devices.

Flags:
      --config string   config file (default is /home/user/.config/pushnotifier/pushnotifier.yaml)
  -h, --help            help for pnctl

Use "pnctl [command] --help" for more information about a command.

Documentation

Overview

Package pushnotifier provides primitives for interactiving with the pushnotifier.de API endpoints.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type Client

type Client struct {
	APIToken       string
	BaseURL        *url.URL
	PackageName    string
	UserName       string
	AppToken       string
	AppTokenExpiry int64
	Devices        []string
	// contains filtered or unexported fields
}

Client represents a client interface to the pushnotifier.de API endpoint and the necessary tokens for interaction.

func NewClient

func NewClient(httpClient *http.Client, packageName, token, appToken string) *Client

A NewClient creates a new PushNotifier API client. It expects 3 arguments 1) a `http.Client` 2) an API token 3) a package name

Currently, the 1st argument will default to `http.DefaultClient` if no arguments are given. For more information on pushnotifier.de: https://api.pushnotifier.de/v2/doc/

func (*Client) GetDevices

func (c *Client) GetDevices() error

GetDevices get all devices a user has registered and that are available for sending.

func (*Client) Login

func (c *Client) Login(username, password string) error

Login is used to login on behalf of a user. Logging in means to obtain a so-called "Appp Token" which is used to identify your requests.

func (*Client) RefreshToken

func (c *Client) RefreshToken() error

RefreshToken is used to refresh your obtain App Token.

func (*Client) SendImage

func (c *Client) SendImage(contentFile string, devices []string, silent bool) error

SendImage sends a notification to all registered clients with an Image.

func (*Client) SendNotification

func (c *Client) SendNotification(content, contentURL string, devices []string, silent bool) error

SendNotification sends a notification to all registered clients with content or URL.

func (*Client) SendText

func (c *Client) SendText(content string, devices []string, silent bool) error

SendText sends a notification to all registered clients with a simple text.

func (*Client) SendURL

func (c *Client) SendURL(contentURL string, devices []string, silent bool) error

SendURL sends a notification to all registered clients with a URL.

type Device

type Device struct {
	ID    string `json:"id"`
	Title string `json:"title"`
	Model string `json:"model"`
	Image string `json:"image"`
}

type User

type User struct {
	UserName  string `json:"username"`
	Avatar    string `json:"avatar"`
	AppToken  string `json:"app_token"`
	ExpiresAt int64  `json:"expires_at"`
}

Directories

Path Synopsis
cmd
pkg

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL
JackTT - Gopher 🇻🇳