change type of FcmMsg.Data to interface{}

This commit is contained in:
betrok 2016-08-25 16:51:39 +03:00
parent 8a865d6a2d
commit 2fe514a20e
2 changed files with 24 additions and 28 deletions

20
fcm.go
View File

@ -11,17 +11,17 @@ import (
const (
// fcm_server_url fcm server url
fcm_server_url = "https://fcm.googleapis.com/fcm/send"
fcm_server_url = "https://fcm.googleapis.com/fcm/send"
// MAX_TTL the default ttl for a notification
MAX_TTL = 2419200
MAX_TTL = 2419200
// Priority_HIGH notification priority
Priority_HIGH = "high"
Priority_HIGH = "high"
// Priority_NORMAL notification priority
Priority_NORMAL = "normal"
Priority_NORMAL = "normal"
// retry_after_header header name
retry_after_header = "Retry-After"
// error_key readable error caching !
error_key = "error"
error_key = "error"
)
var (
@ -43,7 +43,7 @@ type FcmClient struct {
// FcmMsg represents fcm request message
type FcmMsg struct {
Data map[string]string `json:"data,omitempty"`
Data interface{} `json:"data,omitempty"`
To string `json:"to,omitempty"`
RegistrationIds []string `json:"registration_ids,omitempty"`
CollapseKey string `json:"collapse_key,omitempty"`
@ -87,7 +87,6 @@ type NotificationPayload struct {
TitleLocArgs string `json:"title_loc_args,omitempty"`
}
// NewFcmClient init and create fcm client
func NewFcmClient(apiKey string) *FcmClient {
fcmc := new(FcmClient)
@ -105,7 +104,7 @@ func (this *FcmClient) NewFcmTopicMsg(to string, body map[string]string) *FcmCli
}
// NewFcmMsgTo sets the targeted token/topic and the data payload
func (this *FcmClient) NewFcmMsgTo(to string, body map[string]string) *FcmClient {
func (this *FcmClient) NewFcmMsgTo(to string, body interface{}) *FcmClient {
this.Message.To = to
this.Message.Data = body
@ -113,7 +112,7 @@ func (this *FcmClient) NewFcmMsgTo(to string, body map[string]string) *FcmClient
}
// SetMsgData sets data payload
func (this *FcmClient) SetMsgData(body map[string]string) *FcmClient {
func (this *FcmClient) SetMsgData(body interface{}) *FcmClient {
this.Message.Data = body
@ -122,7 +121,7 @@ func (this *FcmClient) SetMsgData(body map[string]string) *FcmClient {
}
// NewFcmRegIdsMsg gets a list of devices with data payload
func (this *FcmClient) NewFcmRegIdsMsg(list []string, body map[string]string) *FcmClient {
func (this *FcmClient) NewFcmRegIdsMsg(list []string, body interface{}) *FcmClient {
this.newDevicesList(list)
this.Message.Data = body
@ -220,6 +219,7 @@ func (this *FcmMsg) toJsonByte() ([]byte, error) {
return json.Marshal(this)
}
// parseStatusBody parse FCM response body
func (this *FcmResponseStatus) parseStatusBody(body []byte) error {

View File

@ -11,37 +11,37 @@ import (
)
const (
// instance_id_info_with_details_srv_url
// instance_id_info_with_details_srv_url
instance_id_info_with_details_srv_url = "https://iid.googleapis.com/iid/info/%s?details=true"
// instance_id_info_no_details_srv_url
instance_id_info_no_details_srv_url = "https://iid.googleapis.com/iid/info/%s"
// instance_id_info_no_details_srv_url
instance_id_info_no_details_srv_url = "https://iid.googleapis.com/iid/info/%s"
// subscribe_instanceid_to_topic_srv_url
// subscribe_instanceid_to_topic_srv_url
subscribe_instanceid_to_topic_srv_url = "https://iid.googleapis.com/iid/v1/%s/rel/topics/%s"
// batch_add_srv_url
// batch_add_srv_url
batch_add_srv_url = "https://iid.googleapis.com/iid/v1:batchAdd"
// batch_rem_srv_url
// batch_rem_srv_url
batch_rem_srv_url = "https://iid.googleapis.com/iid/v1:batchRemove"
// apns_batch_import_srv_url
// apns_batch_import_srv_url
apns_batch_import_srv_url = "https://iid.googleapis.com/iid/v1:batchImport"
// apns_token_key
// apns_token_key
apns_token_key = "apns_token"
// status_key
status_key = "status"
// reg_token_key
reg_token_key = "registration_token"
// status_key
status_key = "status"
// reg_token_key
reg_token_key = "registration_token"
// topics
// topics
topics = "/topics/"
)
var (
// batchErrors response errors
// batchErrors response errors
batchErrors = map[string]bool{
"NOT_FOUND": true,
"INVALID_ARGUMENT": true,
@ -71,7 +71,6 @@ type SubscribeResponse struct {
StatusCode int
}
// BatchRequest add/remove request
type BatchRequest struct {
To string `json:"to,omitempty"`
@ -86,7 +85,6 @@ type BatchResponse struct {
StatusCode int
}
// ApnsBatchRequest apns import request
type ApnsBatchRequest struct {
App string `json:"application,omitempty"`
@ -94,7 +92,6 @@ type ApnsBatchRequest struct {
ApnsTokens []string `json:"apns_tokens,omitempty"`
}
// ApnsBatchResponse apns import response
type ApnsBatchResponse struct {
Results []map[string]string `json:"results,omitempty"`
@ -103,7 +100,6 @@ type ApnsBatchResponse struct {
StatusCode int
}
// GetInfo gets the instance id info
func (this *FcmClient) GetInfo(withDetails bool, instanceIdToken string) (*InstanceIdInfoResponse, error) {