Пример #1
0
// Sends a Pushbullet-Push containing the given data to the saved API-key.
func sendPush(apiKey string, name string, url string, newStatus string, oldStatus string) {
	logging.MustGetLogger("").Debug("Sending Push about \"" + url + "\"...")

	pb := pushbullet.New(apiKey)

	push := requests.NewLink()
	push.Title = GetConfiguration().Application.Title + " - Status Change"
	push.Body = name + " went from \"" + oldStatus + "\" to \"" + newStatus + "\"."
	push.Url = url

	_, err := pb.PostPushesLink(push)
	if err != nil {
		logging.MustGetLogger("").Error("Unable to send Push: ", err)
	}
}
// send push(link) to channel
func SendLinkToChannel(channelTag string, title string, message string, url string) bool {
	token, err := readAccessToken()
	if err != nil {
		return false
	}

	pb := pushbullet.New(token)

	link := requests.NewLink()
	if channelTag != "" {
		link.Push.ChannelTag = channelTag // set channel tag when provided
	}
	link.Title = title
	link.Body = message
	link.Url = url

	if _, err := pb.PostPushesLink(link); err != nil {
		fmt.Println("Push failed:", err)
		return false
	}
	return true
}
Пример #3
0
func push() {
	fargs := flag.Args()

	jsonArgs, err := hex.DecodeString(fargs[0])
	if err != nil {
		panic(err)
	}

	args := &pushArgs{}
	err = json.Unmarshal([]byte(jsonArgs), &args)
	if err != nil {
		panic(err)
	}

	urlRegexp, _ := regexp.Compile("(?i:https?://)")

	if urlRegexp.Match([]byte(args.Body)) {
		l := requests.NewLink()
		l.DeviceIden = args.Iden
		l.Title = args.Title
		l.Body = ""
		l.Url = args.Body

		_, err = pb.PostPushesLink(l)
	} else {
		n := requests.NewNote()
		n.DeviceIden = args.Iden
		n.Title = args.Title
		n.Body = args.Body

		_, err = pb.PostPushesNote(n)
	}

	if err != nil {
		panic(err)
	}
}