Skip to content

Commit

Permalink
Fixes to support batch message sending.
Browse files Browse the repository at this point in the history
  • Loading branch information
tzaid committed Oct 19, 2023
1 parent da127cc commit 0411042
Show file tree
Hide file tree
Showing 8 changed files with 18 additions and 16 deletions.
1 change: 1 addition & 0 deletions .ruby-version
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
3.2.2
2 changes: 1 addition & 1 deletion firebase-admin-sdk.gemspec
Original file line number Diff line number Diff line change
Expand Up @@ -32,5 +32,5 @@ Gem::Specification.new do |spec|
spec.add_development_dependency "fakefs"
spec.add_development_dependency "climate_control"
spec.add_development_dependency "standard"
spec.add_development_dependency "activesupport"
spec.add_development_dependency "activesupport", "~> 7.0.8"
end
2 changes: 2 additions & 0 deletions lib/firebase-admin-sdk.rb
Original file line number Diff line number Diff line change
Expand Up @@ -34,4 +34,6 @@
require_relative "firebase/admin/messaging/multicast_message"
require_relative "firebase/admin/messaging/error_info"
require_relative "firebase/admin/messaging/topic_management_response"
require_relative "firebase/admin/messaging/send_response"
require_relative "firebase/admin/messaging/batch_response"
require_relative "firebase/admin/messaging/client"
8 changes: 4 additions & 4 deletions lib/firebase/admin/messaging/aps.rb
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ module Admin
module Messaging
# Aps dictionary to be included in an APNS payload.
class APS
# @return [APSAlert, String, nil]
# @return [Firebase::Admin::Messaging::APSAlert, String, nil]
# Alert to be included in the message.
attr_accessor :alert

Expand All @@ -12,7 +12,7 @@ class APS
# remain unchanged.
attr_accessor :badge

# @return [String, CriticalSound, nil]
# @return [Firebase::Admin::Messaging::CriticalSound, String, nil]
# Sound to be played with the message.
attr_accessor :sound

Expand All @@ -39,12 +39,12 @@ class APS

# Initializes an {APS}.
#
# @param [APSAlert, String, nil] alert
# @param [Firebase::Admin::Messaging::APSAlert, String, nil] alert
# Alert to be included in the message (optional).
# @param [Integer, nil] badge
# Badge to be displayed with the message (optional).
# Set to 0 to remove the badge. When not specified, the badge will remain unchanged.
# @param [String, CriticalSound, nil] sound
# @param [Firebase::Admin::Messaging::CriticalSound, String, nil] sound
# Sound to be played with the message (optional).
# @param [Boolean, nil] content_available
# Specifies whether to configure a background update notification (optional).
Expand Down
6 changes: 3 additions & 3 deletions lib/firebase/admin/messaging/batch_response.rb
Original file line number Diff line number Diff line change
Expand Up @@ -5,15 +5,15 @@ module Messaging
class BatchResponse
# The list of responses (possibly empty).
# @return [Array<SendResponse>]
attr_reader responses
attr_reader :responses

# The number of successful messages.
# @return [Integer]
attr_reader success_count
attr_reader :success_count

# The number of failed messages.
# @return [Integer]
attr_reader failure_count
attr_reader :failure_count

# A response received from a batch request.
#
Expand Down
4 changes: 2 additions & 2 deletions lib/firebase/admin/messaging/client.rb
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,7 @@ def send_all(messages, dry_run: false)
options = {skip_serialization: true}
messages.each do |message|
body = encode_message(message, dry_run: dry_run)
service.send_message(@project_id, body, options: options) do |res, err|
service.send_message(@project_path, body, options: options) do |res, err|
wrapped_err = parse_fcm_error(err) unless err.nil?
responses << SendResponse.new(message_id: res&.name, error: wrapped_err)
end
Expand Down Expand Up @@ -181,7 +181,7 @@ def encode_message(message, dry_run:)
FCM_HOST = "https://fcm.googleapis.com"
FCM_HEADERS = {"X-GOOG-API-FORMAT-VERSION": "2"}
IID_HOST = "https://iid.googleapis.com"
IID_HEADERS = {"access_token_auth": "true"}
IID_HEADERS = {access_token_auth: "true"}

FCM_ERROR_TYPES = {
"APNS_AUTH_ERROR" => ThirdPartyAuthError,
Expand Down
9 changes: 4 additions & 5 deletions lib/firebase/admin/messaging/utils.rb
Original file line number Diff line number Diff line change
Expand Up @@ -61,11 +61,10 @@ def check_color(label, value, allow_alpha: false, required: false)
return nil unless value || required
raise ArgumentError, "#{label} is required" unless value
raise ArgumentError, "#{label} must be a string" unless value.is_a?(String)
unless /\A#[0-9a-fA-F]{6}\Z/.match?(value) || (/\A#[0-9a-fA-F]{8}\Z/.match?(value) && allow_alpha)
raise ArgumentError, "#{label} must be in the form #RRGGBB" unless allow_alpha
raise ArgumentError, "#{label} must be in the form #RRGGBB or #RRGGBBAA"
end
value
return value if /\A#[0-9a-fA-F]{6}\Z/.match?(value)
return value if /\A#[0-9a-fA-F]{8}\Z/.match?(value) && allow_alpha
raise ArgumentError, "#{label} must be in the form #RRGGBB" unless allow_alpha
raise ArgumentError, "#{label} must be in the form #RRGGBB or #RRGGBBAA"
end

def to_seconds_string(seconds)
Expand Down
2 changes: 1 addition & 1 deletion lib/firebase/admin/version.rb
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,6 @@

module Firebase
module Admin
VERSION = "0.2.0"
VERSION = "0.3.0"
end
end

0 comments on commit 0411042

Please sign in to comment.