Skip to content

Commit

Permalink
Merge branch 'betrok-master'
Browse files Browse the repository at this point in the history
  • Loading branch information
NaySoftware committed Aug 25, 2016
2 parents 8a865d6 + 2fe514a commit 96710d6
Show file tree
Hide file tree
Showing 2 changed files with 24 additions and 28 deletions.
20 changes: 10 additions & 10 deletions fcm.go
Original file line number Diff line number Diff line change
Expand Up @@ -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 (
Expand All @@ -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"`
Expand Down Expand Up @@ -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)
Expand All @@ -105,15 +104,15 @@ 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

return this
}

// SetMsgData sets data payload
func (this *FcmClient) SetMsgData(body map[string]string) *FcmClient {
func (this *FcmClient) SetMsgData(body interface{}) *FcmClient {

this.Message.Data = body

Expand All @@ -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

Expand Down Expand Up @@ -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 {

Expand Down
32 changes: 14 additions & 18 deletions instanceid.go
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down Expand Up @@ -71,7 +71,6 @@ type SubscribeResponse struct {
StatusCode int
}


// BatchRequest add/remove request
type BatchRequest struct {
To string `json:"to,omitempty"`
Expand All @@ -86,15 +85,13 @@ type BatchResponse struct {
StatusCode int
}


// ApnsBatchRequest apns import request
type ApnsBatchRequest struct {
App string `json:"application,omitempty"`
Sandbox bool `json:"sandbox,omitempty"`
ApnsTokens []string `json:"apns_tokens,omitempty"`
}


// ApnsBatchResponse apns import response
type ApnsBatchResponse struct {
Results []map[string]string `json:"results,omitempty"`
Expand All @@ -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) {

Expand Down

0 comments on commit 96710d6

Please sign in to comment.