pushbots

package module
v0.0.0-...-a2fdbda Latest Latest
Warning

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

Go to latest
Published: Jan 2, 2014 License: BSD-3-Clause Imports: 6 Imported by: ? modules, 0 packages

The first number is the count of modules that contain a package that imports this one. The module count is a better indicator of popularity than the package count. A module with 100 importing packages is counted only once instead of 100 times, reflecting the fact that the choice to use the package was likely made only once, not 100 times.
A '?' means that the value hasn't been computed yet.

README

Build Status

A pushbots API wrapper for go

A unofficial implementation around Pushbots service for sending push notifications (ios, android) in golang.

Documentation

http://godoc.org/github.com/FunOrDieLTD/go-pushbots

Setup

  1. Sign up with pushbots at https://pushbots.com

Installation

go get github.com/FunOrDieLTD/go-pushbots

Examples

Registering a IOS device
	var appId string = "your app id"
	var secret string = "your secret"

	pushBots := pushbots.NewPushBots(appId, secret, true) // true enables debugging
	deviceToken = "Your device token"

	err := pushBots.RegisterDevice(deviceToken, pushbots.PlatformIos, "", "", []string{}, []string{}, "") // Registers an ios device using only it's token
	if err != nil {
		log.Fatal(err)
	}

Tagging a device
	var appId string = "your app id"
	var secret string = "your secret"

	pushBots := pushbots.NewPushBots(appId, secret, true) // true enables debugging
	deviceToken = "Your device token"
	tag := "your_new_tag"

	err := pushBots.TagDevice(deviceToken, pushbots.PlatformIos, "", tag)

	if err != nil {
		log.Fatal(err)
	}

Sending a push to a single device
	var appId string = "your app id"
	var secret string = "your secret"

	deviceToken := "Your device token"
	msg := "Your message"
	sound := "your_sound"
	badge := "0"
	payload := map[string]interface{}{
		"your": "custom data here",
	}

	pushBots := pushbots.NewPushBots(appId, secret, true) // true enables debugging

	err := pushBots.SendPushToDevice(pushbots.PlatformIos, deviceToken, msg, sound, badge, payload)

	if err != nil {
		log.Fatal(err)
	}

Broadcasting a push to all devices
	var appId string = "your app id"
	var secret string = "your secret"

	msg := "Your message"
	sound := "your_sound"
	badge := "0"

	payload := map[string]interface{}{
		"your": "custom data here",
	}

	pushBots := pushbots.NewPushBots(appId, secret, true)

	err := pushBots.Broadcast(pushbots.PlatformAll, msg, sound, badge, payload)

	if err != nil {
		log.Fatal(err)
	}

Documentation

Overview

Package pushbots is an unoficiall API wrapper around pushbots (http://www.pushbots.com) REST api

Documentation about the API can be found at https://pushbots.com/developer/rest
Use it to send push notifications for both android and ios for fun and profit

Index

Examples

Constants

View Source
const (
	PlatformIos     = "0"
	PlatformAndroid = "1"
	PlatformAll     = "3"
)

Constants for the different platforms supported

Variables

This section is empty.

Functions

This section is empty.

Types

type PushBots

type PushBots struct {
	AppId  string
	Secret string
	Debug  bool
	// contains filtered or unexported fields
}

Holds the appid and app secret for use in requests

func NewPushBots

func NewPushBots(appId string, secret string, debug bool) PushBots

Create a new pushbots object

func (*PushBots) AddNotificationType

func (pushbots *PushBots) AddNotificationType(token, platform, alias, notificationType string) error

Adds a notification type to a device

func (*PushBots) ApplyEndpointOverride

func (pushBots *PushBots) ApplyEndpointOverride(endpointOverride string)

Override the base endpoint used to construct the API urls

func (*PushBots) Badge

func (pushbots *PushBots) Badge(token, platform string, badgeCount int) error

Set the badgecount for a device

func (*PushBots) Batch

func (pushbots *PushBots) Batch(platform, msg, sound, badge string, tags, exceptTags, notificationTypes, exceptNotificationTypes []string,
	alias, exceptAlias string, payload map[string]interface{}) error

Batch push notifications to matching devices

func (*PushBots) Broadcast

func (pushbots *PushBots) Broadcast(platform string, msg, sound, badge string, payload map[string]interface{}) error

Send a broadcast to multiple devices

Example
package main

import (
	"github.com/FunOrDieLTD/go-pushbots"
	"log"
)

func main() {
	var appId string = "your app id"
	var secret string = "your secret"

	msg := "Your message"
	sound := "your_sound"
	badge := "0"

	payload := map[string]interface{}{
		"your": "custom data here",
	}

	pushBots := pushbots.NewPushBots(appId, secret, true)

	err := pushBots.Broadcast(pushbots.PlatformAll, msg, sound, badge, payload)

	if err != nil {
		log.Fatal(err)
	}
}

func (*PushBots) Geo

func (pushbots *PushBots) Geo(token, platform, lat, lng string) error

Add geo information to a device

func (*PushBots) RecordAnalytics

func (pushbots *PushBots) RecordAnalytics(token, platform, stats string) error

Record analytics for a device

func (*PushBots) RegisterDevice

func (pushbots *PushBots) RegisterDevice(token, platform, lat, lng string, notificationTypes, tags []string, alias string) error

Register a device with PushBots

Example
package main

import (
	"github.com/FunOrDieLTD/go-pushbots"
	"log"
)

func main() {
	var appId string = "your app id"
	var secret string = "your secret"

	deviceToken := "Your device token"
	pushBots := pushbots.NewPushBots(appId, secret, true) // true enables debugging
	deviceToken = "Your device token"

	err := pushBots.RegisterDevice(deviceToken, pushbots.PlatformIos, "", "", []string{}, []string{}, "") // Registers an ios device using only it's token
	if err != nil {
		log.Fatal(err)
	}
}

func (*PushBots) RemoveNotificationType

func (pushbots *PushBots) RemoveNotificationType(token, platform, alias, notificationType string) error

Removes a notification type from a device

func (*PushBots) SendPushToDevice

func (pushbots *PushBots) SendPushToDevice(platform, token, msg, sound, badge string, payload map[string]interface{}) error

Send a push to one device

Example
package main

import (
	"github.com/FunOrDieLTD/go-pushbots"
	"log"
)

func main() {
	var appId string = "your app id"
	var secret string = "your secret"

	deviceToken := "Your device token"
	msg := "Your message"
	sound := "your_sound"
	badge := "0"
	payload := map[string]interface{}{
		"your": "custom data here",
	}

	pushBots := pushbots.NewPushBots(appId, secret, true) // true enables debugging

	err := pushBots.SendPushToDevice(pushbots.PlatformIos, deviceToken, msg, sound, badge, payload)

	if err != nil {
		log.Fatal(err)
	}
}

func (*PushBots) TagDevice

func (pushbots *PushBots) TagDevice(token, platform, alias, tag string) error

Add a tag to a device

Example
package main

import (
	"github.com/FunOrDieLTD/go-pushbots"
	"log"
)

func main() {
	var appId string = "your app id"
	var secret string = "your secret"

	deviceToken := "Your device token"
	pushBots := pushbots.NewPushBots(appId, secret, true) // true enables debugging
	deviceToken = "Your device token"
	tag := "your_new_tag"

	err := pushBots.TagDevice(deviceToken, pushbots.PlatformIos, "", tag)

	if err != nil {
		log.Fatal(err)
	}

}

func (*PushBots) UnTagDevice

func (pushbots *PushBots) UnTagDevice(token, platform, alias, tag string) error

Remove a tag from a device

func (*PushBots) UnregisterDevice

func (pushbots *PushBots) UnregisterDevice(token, platform string) error

Unregister a device

Jump to

Keyboard shortcuts

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