working client and example
Signed-off-by: Amrit Panesar <amrit@station-app.com>
This commit is contained in:
1 parent
4407e5ab6d
commit
b958e57979
2 files changed
+71
-1
No files matched your search
@@ -0,0 +1,57 @@
|
||||
package main
|
||||
|
||||
import (
|
||||
"fmt"
|
||||
"log"
|
||||
"strconv"
|
||||
|
||||
client "github.com/Neo-Desktop/go-pushover-client"
|
||||
)
|
||||
|
||||
var (
|
||||
key string
|
||||
device string
|
||||
message string
|
||||
priority string
|
||||
err error
|
||||
i int64
|
||||
)
|
||||
|
||||
func main() {
|
||||
fmt.Printf("%s\n:", "Please enter your application key")
|
||||
|
||||
_, err = fmt.Scanln(&key)
|
||||
if err != nil {
|
||||
log.Fatal(err)
|
||||
}
|
||||
|
||||
pushover := client.New(key)
|
||||
|
||||
fmt.Printf("\n%s\n:", "Please enter a device token")
|
||||
_, err = fmt.Scanln(&device)
|
||||
if err != nil {
|
||||
log.Fatal(err)
|
||||
}
|
||||
|
||||
fmt.Printf("\n%s\n:", "Please enter a message to send")
|
||||
_, err = fmt.Scanln(&message)
|
||||
if err != nil {
|
||||
log.Fatal(err)
|
||||
}
|
||||
|
||||
fmt.Printf("\n%s\n:", "Please enter a priority to send this message")
|
||||
_, err = fmt.Scanln(&priority)
|
||||
if err != nil {
|
||||
log.Fatal(err)
|
||||
}
|
||||
|
||||
i, err = strconv.ParseInt(priority, 10, 64)
|
||||
if i > 2 || i < -2 {
|
||||
log.Println("Proiority should be between -2 and 2")
|
||||
log.Fatal("Message aborted")
|
||||
}
|
||||
|
||||
pushover.Send(device, message, priority)
|
||||
log.Println("Message sent")
|
||||
|
||||
}
|
||||
@@ -1,6 +1,7 @@
|
||||
package go_pushover_client
|
||||
|
||||
import (
|
||||
"log"
|
||||
"net/http"
|
||||
"net/url"
|
||||
)
|
||||
@@ -18,13 +19,25 @@ func (p *PushoverClient) new(token string) {
|
||||
}
|
||||
|
||||
func (p *PushoverClient) Send(to string, message string, priority string) {
|
||||
|
||||
payload := url.Values{
|
||||
"token": {p.ApplicationToken},
|
||||
"user": {to},
|
||||
"message": {message},
|
||||
"priority": {priority},
|
||||
}
|
||||
http.PostForm(pushoverURL, payload)
|
||||
|
||||
resp, err := http.PostForm(pushoverURL, payload)
|
||||
if err != nil {
|
||||
log.Fatal(err)
|
||||
}
|
||||
|
||||
responseBytes := make([]byte, 1024)
|
||||
n, err := resp.Body.Read(responseBytes)
|
||||
|
||||
responseString := string(responseBytes[:n])
|
||||
|
||||
log.Println(responseString)
|
||||
}
|
||||
|
||||
func New(token string) *PushoverClient {
|
||||
|
||||
Reference in new issue
Block a user