Skip to content

Commit

Permalink
added notification ability fixes alexjlockwood#9
Browse files Browse the repository at this point in the history
  • Loading branch information
AdriVanHoudt committed Sep 21, 2015
1 parent 3cef374 commit 1344888
Show file tree
Hide file tree
Showing 2 changed files with 5 additions and 3 deletions.
3 changes: 2 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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"}
Expand Down
5 changes: 3 additions & 2 deletions message.go
Original file line number Diff line number Diff line change
Expand Up @@ -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"`
Expand All @@ -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}
}

3 comments on commit 1344888

@omerkirk
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The "notification" feature seems to support a fixed number of keys. This implementation treats it as a free key value object. I think a seperate object like gcm.Message would be a better fit with the appropriate json tags.

@AdriVanHoudt
Copy link
Owner Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

hmm true it supports body, title, icon all as strings, looks like even the readme is wrong ^^ will update

@AdriVanHoudt
Copy link
Owner Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@omerkirk updated, can you have a look?

Please sign in to comment.