Skip to content

Commit 1b173fa

Browse files
committed
refactor send_v1 method to use for_uri method
1 parent f217a4c commit 1b173fa

File tree

1 file changed

+7
-7
lines changed

1 file changed

+7
-7
lines changed

lib/fcm.rb

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -50,16 +50,16 @@ def initialize(api_key, json_key_path = "", project_name = "", client_options =
5050
# { "token": "4sdsx",, "to" : "notification": {}.. }
5151
# )
5252
def send_notification_v1(message)
53-
return if @project_base_uri.empty?
53+
return if @project_name.empty?
5454

5555
post_body = { 'message': message }
56-
57-
response = Faraday.post("#{@project_base_uri}/messages:send") do |req|
58-
req.headers["Content-Type"] = "application/json"
59-
req.headers["Authorization"] = "Bearer #{jwt_token}"
60-
req.body = post_body.to_json
56+
extra_headers = {
57+
"Authorization" => "Bearer #{jwt_token}"
58+
}
59+
for_uri(BASE_URI_V1, extra_headers) do |connection|
60+
response = connection.post("#{@project_name}/messages:send", post_body.to_json)
61+
build_response(response)
6162
end
62-
build_response(response)
6363
end
6464

6565
alias send_v1 send_notification_v1

0 commit comments

Comments
 (0)