Browse Source

SendNote can now send to specific device only

Piotr Czajkowski 3 years ago
parent
commit
68fb4e837e
3 changed files with 13 additions and 11 deletions
  1. 4 3
      bullet.go
  2. 2 2
      bullet_test.go
  3. 7 6
      push.go

+ 4 - 3
bullet.go

@@ -88,9 +88,9 @@ func (b Bullet) send(push pushInterface) error {
 	return nil
 }
 
-//SendNote sends push note with given title and text
-func (b Bullet) SendNote(title, text string) error {
-	note := newNotePush(title, text)
+//SendNote sends push note with given title and text, use empty string as deviceID to send to all
+func (b Bullet) SendNote(title, text, deviceID string) error {
+	note := newNotePush(title, text, deviceID)
 	err := b.send(note)
 
 	return err
@@ -184,6 +184,7 @@ func (b Bullet) SendFile(title, text, file string) error {
 	return err
 }
 
+// ListDevices returns Devices structure which contains slice of devices
 func (b Bullet) ListDevices() (*Devices, error) {
 	request, err := http.NewRequest(http.MethodGet, b.baseURL+"/devices", nil)
 	if err != nil {

+ 2 - 2
bullet_test.go

@@ -35,7 +35,7 @@ func TestSendNote(t *testing.T) {
 
 	b := Bullet{token: "", baseURL: server.URL}
 
-	err := b.SendNote("test", "test")
+	err := b.SendNote("test", "test", "")
 	if err != nil {
 		t.Error(err)
 	}
@@ -48,7 +48,7 @@ func TestSendNoteFail(t *testing.T) {
 
 	b := Bullet{token: "", baseURL: server.URL}
 
-	err := b.SendNote("test", "test")
+	err := b.SendNote("test", "test", "")
 	if err == nil {
 		t.Error("There should be error")
 	}

+ 7 - 6
push.go

@@ -5,18 +5,19 @@ import (
 )
 
 type pushStruct struct {
-	Type  string `json:"type"`
-	Title string `json:"title"`
-	Body  string `json:"body"`
-	Url   string `json:"url"`
+	Type     string `json:"type"`
+	Title    string `json:"title"`
+	Body     string `json:"body"`
+	Url      string `json:"url"`
+	DeviceID string `json:"device_iden"`
 }
 
 func (p pushStruct) getReader() (*bytes.Buffer, error) {
 	return getReader(p)
 }
 
-func newNotePush(title, text string) pushStruct {
-	push := pushStruct{Type: "note", Title: title, Body: text}
+func newNotePush(title, text, deviceID string) pushStruct {
+	push := pushStruct{Type: "note", Title: title, Body: text, DeviceID: deviceID}
 	return push
 }