Skip to content

Commit

Permalink
add other FCM features
Browse files Browse the repository at this point in the history
  • Loading branch information
chemidy committed Jul 9, 2017
1 parent 6e43140 commit 82a959c
Showing 1 changed file with 79 additions and 32 deletions.
111 changes: 79 additions & 32 deletions fcm.go
Original file line number Diff line number Diff line change
Expand Up @@ -22,13 +22,90 @@ func newFCM(app *App) *FCM {
}
}

// SendToDevice Send Message to individual devices
// SendToDevice Send Message to individual device
// see https://firebase.google.com/docs/cloud-messaging/admin/send-messages#send_to_individual_devices
func (fcm *FCM) SendToDevice(registrationToken string, payload Message) (*Response, error) {

// assign recipient with registrationToken
// assign recipient
payload.To = registrationToken

// flush other recipients
payload.RegistrationIDs = nil
payload.Condition = ""

// send request to Firebase
return fcm.sendFirebaseRequest(payload)
}

// SendToDevices Send multicast Message to devices
// see https://firebase.google.com/docs/cloud-messaging/admin/send-messages#send_to_individual_devices
func (fcm *FCM) SendToDevices(registrationTokens []string, payload Message) (*Response, error) {

// assign recipient
payload.RegistrationIDs = registrationTokens

// flush other recipients
payload.To = ""
payload.Condition = ""

// send request to Firebase
return fcm.sendFirebaseRequest(payload)
}

// SendToDeviceGroup Send Message to a device group
// see https://firebase.google.com/docs/cloud-messaging/admin/send-messages#send_to_a_device_group
func (fcm *FCM) SendToDeviceGroup(notificationKey string, payload Message) (*Response, error) {
return fcm.SendToDevice(notificationKey, payload)
}

// SendToTopic TODO NOT IMPLEMENTED
// see https://firebase.google.com/docs/cloud-messaging/admin/send-messages#send_to_a_topic
func (fcm *FCM) SendToTopic(notificationKey string, payload Message) (*Response, error) {
return fcm.SendToDevice(fmt.Sprint("/topic/", notificationKey), payload)
}

// SendToCondition Send a message to devices subscribed to the combination of topics
// specified by the provided condition.
// see https://firebase.google.com/docs/cloud-messaging/admin/send-messages#send_to_a_condition
func (fcm *FCM) SendToCondition(condition string, payload Message) (*Response, error) {

// assign recipient
payload.Condition = condition

// flush other recipients
payload.To = ""
payload.RegistrationIDs = nil

// send request to Firebase
return fcm.sendFirebaseRequest(payload)
}

// SubscribeDeviceToTopic TODO NOT IMPLEMENTED
// see https://firebase.google.com/docs/cloud-messaging/admin/manage-topic-subscriptions#subscribe_to_a_topic
func (fcm *FCM) SubscribeDeviceToTopic(registrationToken string, topic string) (*Response, error) {
return nil, ErrNotImplemented
}

// SubscribeDevicesToTopic TODO NOT IMPLEMENTED
// see https://firebase.google.com/docs/cloud-messaging/admin/manage-topic-subscriptions#subscribe_to_a_topic
func (fcm *FCM) SubscribeDevicesToTopic(registrationTokens []string, topic string) (*Response, error) {
return nil, ErrNotImplemented
}

// UnSubscribeDeviceFromTopic TODO NOT IMPLEMENTED
// see https://firebase.google.com/docs/cloud-messaging/admin/manage-topic-subscriptions#unsubscribe_from_a_topic
func (fcm *FCM) UnSubscribeDeviceFromTopic(registrationToken string, topic string) (*Response, error) {
return nil, ErrNotImplemented
}

// UnSubscribeDevicesFromTopic TODO NOT IMPLEMENTED
// see https://firebase.google.com/docs/cloud-messaging/admin/manage-topic-subscriptions#unsubscribe_from_a_topic
func (fcm *FCM) UnSubscribeDevicesFromTopic(registrationTokens []string, topic string) (*Response, error) {
return nil, ErrNotImplemented
}

func (fcm *FCM) sendFirebaseRequest(payload Message) (*Response, error) {

// validate Message
if err := payload.Validate(); err != nil {
return nil, err
Expand Down Expand Up @@ -85,33 +162,3 @@ func (fcm *FCM) SendToDevice(registrationToken string, payload Message) (*Respon

return response, nil
}

// SendToDeviceGroup Send Message to a device group
// see https://firebase.google.com/docs/cloud-messaging/admin/send-messages#send_to_a_device_group
func (fcm *FCM) SendToDeviceGroup(notificationKey string, payload Message) (*Response, error) {
return nil, ErrNotImplemented
}

// SendToTopic TODO NOT IMPLEMENTED
// see https://firebase.google.com/docs/cloud-messaging/admin/send-messages#send_to_a_topic
func (fcm *FCM) SendToTopic(notificationKey string, payload Message) (*Response, error) {
return nil, ErrNotImplemented
}

// SendToCondition TODO NOT IMPLEMENTED
// see https://firebase.google.com/docs/cloud-messaging/admin/send-messages#send_to_a_condition
func (fcm *FCM) SendToCondition(condition string, payload Message) (*Response, error) {
return nil, ErrNotImplemented
}

// SubscribeDeviceToTopic TODO NOT IMPLEMENTED
// see https://firebase.google.com/docs/cloud-messaging/admin/manage-topic-subscriptions#subscribe_to_a_topic
func (fcm *FCM) SubscribeDeviceToTopic(registrationToken string, topic string) (*Response, error) {
return nil, ErrNotImplemented
}

// SubscribeDevicesToTopic TODO NOT IMPLEMENTED
// see https://firebase.google.com/docs/cloud-messaging/admin/manage-topic-subscriptions#subscribe_to_a_topic
func (fcm *FCM) SubscribeDevicesToTopic(registrationTokens []string, topic string) (*Response, error) {
return nil, ErrNotImplemented
}

0 comments on commit 82a959c

Please sign in to comment.