Browse Source

Able to send link

Piotr Czajkowski 3 years ago
parent
commit
474dc9f076
2 changed files with 25 additions and 4 deletions
  1. 18 4
      bullet.go
  2. 7 0
      push.go

+ 18 - 4
bullet.go

@@ -25,10 +25,8 @@ func (b Bullet) newRequest(body io.Reader) (*http.Request, error) {
 	return request, nil
 }
 
-//Send push note with given title and text
-func (b Bullet) SendNote(title, text string) error {
-	note := NewNotePush(title, text)
-	reader, errReader := note.GetReader()
+func (b Bullet) send(push Push) error {
+	reader, errReader := push.GetReader()
 	if errReader != nil {
 		return errReader
 	}
@@ -58,3 +56,19 @@ func (b Bullet) SendNote(title, text string) error {
 
 	return nil
 }
+
+//Send push note with given title and text
+func (b Bullet) SendNote(title, text string) error {
+	note := NewNotePush(title, text)
+	err := b.send(note)
+
+	return err
+}
+
+//Send push link with given title, text and link
+func (b Bullet) SendLink(title, text, link string) error {
+	linkPush := NewLinkPush(title, text, link)
+	err := b.send(linkPush)
+
+	return err
+}

+ 7 - 0
push.go

@@ -9,6 +9,7 @@ type Push struct {
 	Type  string `json:"type"`
 	Title string `json:"title"`
 	Body  string `json:"body"`
+	Url   string `json:"url"`
 }
 
 //GetReader
@@ -27,3 +28,9 @@ func NewNotePush(title, text string) Push {
 	push := Push{Type: "note", Title: title, Body: text}
 	return push
 }
+
+//NewLinkPush
+func NewLinkPush(title, text, link string) Push {
+	push := Push{Type: "note", Title: title, Body: text, Url: link}
+	return push
+}