示例#1
0
func main() {
	var cfg Config
	usr, _ := user.Current()
	dir := usr.HomeDir
	cfg_file := path.Join(dir, ".config", "golang-utils", "user.cfg")
	log.Println("Read configuration file: ", cfg_file)
	err := gcfg.ReadFileInto(&cfg, cfg_file)
	if err != nil {
		log.Fatalf("Failed to parse configuration file: %s", err)
	}
	token := cfg.Pushme.Token
	log.Println("Token: ", token)
	flag.Parse()
	// create a client for pushbullet
	pb := pushbullet.New(token)

	// create a 'note' push
	n := requests.NewNote()
	n.Title = flag.Args()[0]
	n.Body = flag.Args()[1]

	// send the note
	if _, err := pb.PostPushesNote(n); err != nil {
		log.Fatalln("Error: %s\n", err)
	}
}
// send push(note) to channel
func SendNoteToChannel(channelTag string, title string, message string) bool {
	token, err := readAccessToken()
	if err != nil {
		return false
	}

	pb := pushbullet.New(token)

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

	if _, err := pb.PostPushesNote(note); 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)
	}
}