From 1344888148d6b5c04d88edbe42de965035ed4d11 Mon Sep 17 00:00:00 2001 From: Adri Van Houdt Date: Mon, 21 Sep 2015 11:18:57 +0200 Subject: [PATCH] added notification ability fixes #9 --- README.md | 3 ++- message.go | 5 +++-- 2 files changed, 5 insertions(+), 3 deletions(-) diff --git a/README.md b/README.md index 89886a3..bce6b1b 100644 --- a/README.md +++ b/README.md @@ -38,8 +38,9 @@ import ( func main() { // Create the message to be sent. data := map[string]interface{}{"score": "5x1", "time": "15:10"} + notification := map[string]interface{}{"title": "Notification Title", "message": "This is the body of the notification"} regIDs := []string{"4", "8", "15", "16", "23", "42"} - msg := gcm.NewMessage(data, regIDs...) + msg := gcm.NewMessage(data, regIDs..., notification) // Create a Sender to send the message. sender := &gcm.Sender{ApiKey: "sample_api_key"} diff --git a/message.go b/message.go index b63c018..9e98921 100644 --- a/message.go +++ b/message.go @@ -8,6 +8,7 @@ type Message struct { RegistrationIDs []string `json:"registration_ids"` CollapseKey string `json:"collapse_key,omitempty"` Data map[string]interface{} `json:"data,omitempty"` + Notification map[string]interface{} `json:"notification,omitempty"` DelayWhileIdle bool `json:"delay_while_idle,omitempty"` TimeToLive int `json:"time_to_live,omitempty"` RestrictedPackageName string `json:"restricted_package_name,omitempty"` @@ -16,6 +17,6 @@ type Message struct { // NewMessage returns a new Message with the specified payload // and registration IDs. -func NewMessage(data map[string]interface{}, regIDs ...string) *Message { - return &Message{RegistrationIDs: regIDs, Data: data} +func NewMessage(data map[string]interface{}, regIDs ...string, notification map[string]interface{}) *Message { + return &Message{RegistrationIDs: regIDs, Data: data, Notification: notification} }