pushbullet

package module
v0.0.0-...-67759df Latest Latest
Warning

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

Go to latest
Published: Dec 6, 2017 License: MIT Imports: 7 Imported by: 39

README

go-pushbullet

Build Coverage API Documentation MIT License

Simple Go client for Pushbullet, a webservice to push links, notes and more to your Android devices.

Documentation available under: http://godoc.org/github.com/xconstruct/go-pushbullet

Install
go get "github.com/xconstruct/go-pushbullet"
Example
pb := pushbullet.New("YOUR_API_KEY")
devs, err := pb.Devices()
if err != nil {
	panic(err)
}

err = pb.PushNote(devs[0].Iden, "Hello!", "Hi from go-pushbullet!")
if err != nil {
	panic(err)
}


user, err := pb.Me()
if err != nil {
	panic(err)
}

err = pb.PushSMS(user.Iden, devs[0].Iden, "<TARGET_PHONE_NUMBER>", "Sms text")
if err != nil {
	panic(err)
}

You can also retrieve a pushbullet device by nickname, and call the same methods as you would with the pushbullet client

dev, err := pb.Device("My Phone")
if err != nil {
	panic(err)
}

err = dev.PushNote("Hello!", "Straight to device with just a title and body")
if err != nil {
	panic(err)
}

Channels are also supported in a similar manner

subs, err := pb.Subscriptions()
if err != nil {
	panic(err)
}

err = pb.PushNoteToChannel(subs[0].Channel.Tag, "Hello!", "Hi from go-pushbullet!")
if err != nil {
	panic(err)
}

sub, err := pb.Subscription("MyChannelTag")
if err != nil {
	panic(err)
}

err = sub.PushNote("Hello!", "Straight to Channel with just a title and body")
if err != nil {
	panic(err)
}

Documentation

Overview

Package pushbullet provides simple access to the v2 API of http://pushbullet.com.

Example client:

pb := pushbullet.New("YOUR_API_KEY")
devices, err := pb.Devices()
...
err = pb.PushNote(devices[0].Iden, "Hello!", "Hi from go-pushbullet!")

The API is document at https://docs.pushbullet.com/http/ . At the moment, it only supports querying devices and sending notifications.

Index

Constants

This section is empty.

Variables

View Source
var EndpointURL = "https://api.pushbullet.com/v2"

EndpointURL sets the default URL for the Pushbullet API

View Source
var ErrDeviceNotFound = errors.New("Device not found")

ErrDeviceNotFound is raised when device nickname is not found on pusbullet server

Functions

This section is empty.

Types

type Channel

type Channel struct {
	Iden        string `json:"iden"`
	Tag         string `json:"tag"`
	Name        string `json:"name"`
	Description string `json:"description"`
	ImageUrl    string `json:"image_url"`
	WebsiteUrl  string `json:"website_url"`
}

Channel object contains specific information about the pushbullet Channel

type Client

type Client struct {
	Key    string
	Client *http.Client
	Endpoint
}

A Client connects to PushBullet with an API Key.

func New

func New(apikey string) *Client

New creates a new client with your personal API key.

func NewWithClient

func NewWithClient(apikey string, client *http.Client) *Client

NewWithClient creates a new client with your personal API key and the given http Client

func (*Client) Device

func (c *Client) Device(nickname string) (*Device, error)

Device fetches an device with a given nickname from PushBullet.

func (*Client) Devices

func (c *Client) Devices() ([]*Device, error)

Devices fetches a list of devices from PushBullet.

func (*Client) Me

func (c *Client) Me() (*User, error)

Me returns the user object for the pushbullet user

func (*Client) Push

func (c *Client) Push(endPoint string, data interface{}) error

Push pushes the data to a specific device registered with PushBullet. The 'data' parameter is marshaled to JSON and sent as the request body. Most users should call one of PusNote, PushLink, PushAddress, or PushList.

func (c *Client) PushLink(iden, title, u, body string) error

PushLink pushes a link with a title and url to a specific PushBullet device.

func (*Client) PushLinkToChannel

func (c *Client) PushLinkToChannel(tag, title, u, body string) error

PushLinkToChannel pushes a link with a title and url to a specific PushBullet device.

func (*Client) PushNote

func (c *Client) PushNote(iden string, title, body string) error

PushNote pushes a note with title and body to a specific PushBullet device.

func (*Client) PushNoteToChannel

func (c *Client) PushNoteToChannel(tag string, title, body string) error

PushNoteToChannel pushes a note with title and body to a specific PushBullet channel.

func (*Client) PushSMS

func (c *Client) PushSMS(userIden, deviceIden, phoneNumber, message string) error

PushSMS sends an SMS message with pushbullet

func (*Client) Subscription

func (c *Client) Subscription(tag string) (*Subscription, error)

Subscription fetches an subscription with a given channel tag from PushBullet.

func (*Client) Subscriptions

func (c *Client) Subscriptions() ([]*Subscription, error)

type Device

type Device struct {
	Iden              string  `json:"iden"`
	Active            bool    `json:"active"`
	Created           float32 `json:"created"`
	Modified          float32 `json:"modified"`
	Icon              string  `json:"icon"`
	Nickname          string  `json:"nickname"`
	GeneratedNickname bool    `json:"generated_nickname"`
	Manufacturer      string  `json:"manufacturer"`
	Model             string  `json:"model"`
	AppVersion        int     `json:"app_version"`
	Fingerprint       string  `json:"fingerprint"`
	KeyFingerprint    string  `json:"key_fingerprint"`
	PushToken         string  `json:"push_token"`
	HasSms            bool    `json:"has_sms"`
	Client            *Client `json:"-"`
}

A Device is a PushBullet device

func (d *Device) PushLink(title, u, body string) error

PushLink sends a link to the specific device with the given title and url

func (*Device) PushNote

func (d *Device) PushNote(title, body string) error

PushNote sends a note to the specific device with the given title and body

func (*Device) PushSMS

func (d *Device) PushSMS(deviceIden, phoneNumber, message string) error

PushSMS sends an SMS to the specific user from the device with the given title and url

type Endpoint

type Endpoint struct {
	URL string
}

Endpoint allows manipulation of pushbullet API endpoint for testing

type Ephemeral

type Ephemeral struct {
	Type string        `json:"type"`
	Push EphemeralPush `json:"push"`
}

Ephemeral constructs the Ephemeral object for pushing which requires the EphemeralPush object

type EphemeralPush

type EphemeralPush struct {
	Type             string `json:"type"`
	PackageName      string `json:"package_name"`
	SourceUserIden   string `json:"source_user_iden"`
	TargetDeviceIden string `json:"target_device_iden"`
	ConversationIden string `json:"conversation_iden"`
	Message          string `json:"message"`
}

EphemeralPush exposes the required fields of the Pushbullet ephemeral object

type ErrResponse

type ErrResponse struct {
	Type    string `json:"type"`
	Message string `json:"message"`
	Cat     string `json:"cat"`
}

ErrResponse is an error returned by the PushBullet API

func (*ErrResponse) Error

func (e *ErrResponse) Error() string
type Link struct {
	Iden  string `json:"device_iden,omitempty"`
	Tag   string `json:"channel_tag,omitempty"`
	Type  string `json:"type"`
	Title string `json:"title"`
	URL   string `json:"url"`
	Body  string `json:"body,omitempty"`
}

Link exposes the required and optional fields of the Pushbullet push type=link

type Note

type Note struct {
	Iden  string `json:"device_iden,omitempty"`
	Tag   string `json:"channel_tag,omitempty"`
	Type  string `json:"type"`
	Title string `json:"title"`
	Body  string `json:"body"`
}

Note exposes the required and optional fields of the Pushbullet push type=note

type Subscription

type Subscription struct {
	Iden     string   `json:"iden"`
	Active   bool     `json:"active"`
	Created  float32  `json:"created"`
	Modified float32  `json:"modified"`
	Muted    string   `json:"muted"`
	Channel  *Channel `json:"channel"`
	Client   *Client  `json:"-"`
}

Subscription object allows interaction with pushbullet channels

func (s *Subscription) PushLink(title, u, body string) error

PushNote sends a link to the specific Channel with the given title, url and body

func (*Subscription) PushNote

func (s *Subscription) PushNote(title, body string) error

PushNote sends a note to the specific Channel with the given title and body

type User

type User struct {
	Iden            string      `json:"iden"`
	Email           string      `json:"email"`
	EmailNormalized string      `json:"email_normalized"`
	Created         float64     `json:"created"`
	Modified        float64     `json:"modified"`
	Name            string      `json:"name"`
	ImageUrl        string      `json:"image_url"`
	Preferences     interface{} `json:"preferences"`
}

User represents the User object for pushbullet

Directories

Path Synopsis

Jump to

Keyboard shortcuts

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