-
Notifications
You must be signed in to change notification settings - Fork 155
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
6 changed files
with
125 additions
and
100 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,58 @@ | ||
# frozen_string_literal: true | ||
|
||
module Fcm | ||
class Client | ||
# A Fcm Client class to handle notification setting methods | ||
module InstanceTopicManagement | ||
INSTANCE_ID_API = 'https://iid.googleapis.com' | ||
|
||
def manage_topics_relationship(topic, registration_ids, action) | ||
body = { to: "/topics/#{topic}", registration_tokens: registration_ids } | ||
end_point = "/iid/v1:batch#{action}" | ||
res = make_request( | ||
:post, INSTANCE_ID_API, end_point, body.to_json, authorization_headers | ||
) | ||
build_response(res, registration_ids) | ||
end | ||
|
||
def topic_subscription(topic, registration_id) | ||
end_point = "/iid/v1/#{registration_id}/rel/topics/#{topic}" | ||
res = make_request(:post, INSTANCE_ID_API, end_point, nil, authorization_headers) | ||
build_response(res) | ||
end | ||
|
||
def get_instance_id_info(iid_token, options = {}) | ||
params = options | ||
end_point = "/iid/info/#{iid_token}" | ||
res = make_request( | ||
:get, INSTANCE_ID_API, end_point, params, authorization_headers | ||
) | ||
build_response(res) | ||
end | ||
|
||
def batch_topic_subscription(topic, registration_ids) | ||
manage_topics_relationship(topic, registration_ids, 'Add') | ||
end | ||
|
||
def batch_topic_unsubscription(topic, registration_ids) | ||
manage_topics_relationship(topic, registration_ids, 'Remove') | ||
end | ||
|
||
def batch_subscribe_instance_ids_to_topic(instance_ids, topic_name) | ||
manage_topics_relationship(topic_name, instance_ids, 'Add') | ||
end | ||
|
||
def batch_unsubscribe_instance_ids_from_topic(instance_ids, topic_name) | ||
manage_topics_relationship(topic_name, instance_ids, 'Remove') | ||
end | ||
|
||
def subscribe_instance_id_to_topic(iid_token, topic_name) | ||
batch_subscribe_instance_ids_to_topic([iid_token], topic_name) | ||
end | ||
|
||
def unsubscribe_instance_id_from_topic(iid_token, topic_name) | ||
batch_unsubscribe_instance_ids_from_topic([iid_token], topic_name) | ||
end | ||
end | ||
end | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,23 @@ | ||
# frozen_string_literal: true | ||
|
||
module Fcm | ||
class ClientV1 | ||
# Handle notification delivery methods | ||
module NotificationDilivery | ||
BASE_URI_V1 = 'https://fcm.googleapis.com/v1/projects/' | ||
TOKEN_URI = 'https://www.googleapis.com/auth/firebase.messaging' | ||
|
||
def send_notification_v1(message, project_name) | ||
return if project_name.empty? | ||
|
||
post_body = { 'message': message } | ||
end_point = "#{project_name}/messages:send" | ||
|
||
res = make_request( | ||
:post, BASE_URI_V1, end_point, post_body.to_json, authorization_headers | ||
) | ||
build_response(res) | ||
end | ||
end | ||
end | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters