firebase-admin-sdk 0.1.0 → 0.1.1

Sign up to get free protection for your applications and to get access to all the features.
Files changed (34) hide show
  1. checksums.yaml +4 -4
  2. data/README.md +12 -21
  3. data/firebase-admin-sdk.gemspec +1 -0
  4. data/lib/firebase-admin-sdk.rb +21 -1
  5. data/lib/firebase/admin/app.rb +0 -6
  6. data/lib/firebase/admin/auth/client.rb +8 -0
  7. data/lib/firebase/admin/auth/token_verifier.rb +1 -1
  8. data/lib/firebase/admin/auth/user_info.rb +6 -6
  9. data/lib/firebase/admin/auth/user_manager.rb +2 -2
  10. data/lib/firebase/admin/auth/user_record.rb +5 -5
  11. data/lib/firebase/admin/config.rb +4 -2
  12. data/lib/firebase/admin/internal/http_client.rb +1 -0
  13. data/lib/firebase/admin/messaging/android_config.rb +77 -0
  14. data/lib/firebase/admin/messaging/android_fcm_options.rb +19 -0
  15. data/lib/firebase/admin/messaging/android_notification.rb +221 -0
  16. data/lib/firebase/admin/messaging/apns_config.rb +38 -0
  17. data/lib/firebase/admin/messaging/apns_fcm_options.rb +27 -0
  18. data/lib/firebase/admin/messaging/apns_payload.rb +28 -0
  19. data/lib/firebase/admin/messaging/aps.rb +82 -0
  20. data/lib/firebase/admin/messaging/aps_alert.rb +110 -0
  21. data/lib/firebase/admin/messaging/client.rb +181 -0
  22. data/lib/firebase/admin/messaging/critical_sound.rb +37 -0
  23. data/lib/firebase/admin/messaging/error.rb +36 -0
  24. data/lib/firebase/admin/messaging/error_info.rb +25 -0
  25. data/lib/firebase/admin/messaging/fcm_options.rb +19 -0
  26. data/lib/firebase/admin/messaging/light_settings.rb +34 -0
  27. data/lib/firebase/admin/messaging/message.rb +83 -0
  28. data/lib/firebase/admin/messaging/message_encoder.rb +355 -0
  29. data/lib/firebase/admin/messaging/multicast_message.rb +67 -0
  30. data/lib/firebase/admin/messaging/notification.rb +34 -0
  31. data/lib/firebase/admin/messaging/topic_management_response.rb +41 -0
  32. data/lib/firebase/admin/messaging/utils.rb +78 -0
  33. data/lib/firebase/admin/version.rb +1 -1
  34. metadata +36 -2
@@ -0,0 +1,67 @@
1
+ module Firebase
2
+ module Admin
3
+ module Messaging
4
+ # A multicast message that can be sent via Firebase Cloud Messaging.
5
+ #
6
+ # Contains payload information as well as recipient information. In particular, the message must contain exactly
7
+ # one of token, topic or condition fields.
8
+ class MulticastMessage
9
+ # @return [Hash<String, String>, nil]
10
+ # A hash of data fields (optional). All keys and values must be strings.
11
+ attr_accessor :data
12
+
13
+ # @return [Notification, nil]
14
+ # A {Notification} (optional).
15
+ attr_accessor :notification
16
+
17
+ # @return [AndroidConfig, nil]
18
+ # An {AndroidConfig} (optional).
19
+ attr_accessor :android
20
+
21
+ # @return [APNSConfig, nil]
22
+ # An {APNSConfig} (optional).
23
+ attr_accessor :apns
24
+
25
+ # @return [FCMOptions, nil]
26
+ # An {FCMOptions} (optional).
27
+ attr_accessor :fcm_options
28
+
29
+ # @return [Array<String>, nil]
30
+ # Registration token of the device to which the message should be sent (optional).
31
+ attr_accessor :tokens
32
+
33
+ # Initializes a {Message}.
34
+ #
35
+ # @param [Hash<String, String>, nil] data
36
+ # A hash of data fields (optional). All keys and values must be strings.
37
+ # @param [Notification, nil] notification
38
+ # A {Notification} (optional).
39
+ # @param [AndroidConfig, nil] android
40
+ # An {AndroidConfig} (optional).
41
+ # @param [APNSConfig, nil] apns
42
+ # An {APNSConfig} (optional).
43
+ # @param [FCMOptions, nil] fcm_options
44
+ # An {FCMOptions} (optional).
45
+ # @param [Array<String>, nil] tokens
46
+ # A registration token of the device to send the message to (optional).
47
+ def initialize(
48
+ data: nil,
49
+ notification: nil,
50
+ android: nil,
51
+ apns: nil,
52
+ fcm_options: nil,
53
+ tokens: nil
54
+ )
55
+ self.data = data
56
+ self.notification = notification
57
+ self.android = android
58
+ self.apns = apns
59
+ self.fcm_options = fcm_options
60
+ self.tokens = tokens
61
+ self.topic = topic
62
+ self.condition = condition
63
+ end
64
+ end
65
+ end
66
+ end
67
+ end
@@ -0,0 +1,34 @@
1
+ module Firebase
2
+ module Admin
3
+ module Messaging
4
+ # A notification that can be included in a message.
5
+ class Notification
6
+ # @return [String, nil]
7
+ # Title of the notification.
8
+ attr_accessor :title
9
+
10
+ # @return [String, nil]
11
+ # Body of the notification.
12
+ attr_accessor :body
13
+
14
+ # @return [String, nil]
15
+ # Image url of the notification.
16
+ attr_accessor :image
17
+
18
+ # Initializes a {Notification}.
19
+ #
20
+ # @param [String, nil] title
21
+ # Title of the notification (optional).
22
+ # @param [String, nil] body
23
+ # Body of the notification (optional).
24
+ # @param [String, nil]
25
+ # Image url of the notification (optional).
26
+ def initialize(title: nil, body: nil, image: nil)
27
+ self.title = title
28
+ self.body = body
29
+ self.image = image
30
+ end
31
+ end
32
+ end
33
+ end
34
+ end
@@ -0,0 +1,41 @@
1
+ module Firebase
2
+ module Admin
3
+ module Messaging
4
+ # A response received from a topic management operation.
5
+ class TopicManagementResponse
6
+ # @return [Integer] The number of tokens successfully subscribed or unsubscribed.
7
+ attr_reader :success_count
8
+
9
+ # @return [Integer] The number of tokens that could not be subscribed or unsubscribed due to errors.
10
+ attr_reader :failure_count
11
+
12
+ # @return [Array<ErrorInfo>] An array of {ErrorInfo} objects (possibly empty).
13
+ attr_reader :errors
14
+
15
+ # Initializes a {TopicManagementResponse}.
16
+ #
17
+ # @param [Faraday::Response] response
18
+ # The response received from the api.
19
+ def initialize(response)
20
+ unless response.body.is_a?(Hash) && response.body["results"].is_a?(Array)
21
+ raise Error.new("Unexpected topic management response", response)
22
+ end
23
+
24
+ @success_count = 0
25
+ @failure_count = 0
26
+ @errors = []
27
+
28
+ results = response.body["results"]
29
+ results.each_with_index do |result, i|
30
+ if (reason = result["error"])
31
+ @failure_count += 1
32
+ @errors << ErrorInfo.new(index: i, reason: reason)
33
+ else
34
+ @success_count += 1
35
+ end
36
+ end
37
+ end
38
+ end
39
+ end
40
+ end
41
+ end
@@ -0,0 +1,78 @@
1
+ module Firebase
2
+ module Admin
3
+ module Messaging
4
+ module Utils
5
+ def check_string(label, value, non_empty: false)
6
+ return nil unless value
7
+ raise ArgumentError, "#{label} must be a string." unless value.is_a?(String) || non_empty
8
+ raise ArgumentError, "#{label} must be a non-empty string." unless value.is_a?(String) || !non_empty
9
+ raise ArgumentError, "#{label} must be a non-empty string." if value.empty? && non_empty
10
+ value
11
+ end
12
+
13
+ def check_numeric(label, value)
14
+ return nil unless value
15
+ raise ArgumentError, "#{label} must be a number." unless value.is_a?(Numeric)
16
+ value
17
+ end
18
+
19
+ def check_string_hash(label, value)
20
+ return nil if value.nil?
21
+ raise ArgumentError, "#{label} must be a hash." unless value.is_a?(Hash)
22
+ return nil if value.empty?
23
+ raise ArgumentError, "#{label} must not contain non-string values" unless value.values.all?(String)
24
+ unless value.keys.all? { |k| k.is_a?(String) || k.is_a?(Symbol) }
25
+ raise ArgumentError, "#{label} must not contain non-string or non-symbol values"
26
+ end
27
+ value
28
+ end
29
+
30
+ def check_string_array(label, value)
31
+ return nil if value.nil?
32
+ raise ArgumentError, "#{label} must be an array of strings." unless value.is_a?(Array)
33
+ return nil if value.empty?
34
+ raise ArgumentError, "#{label} must not contain non-string values" unless value.all?(String)
35
+ value
36
+ end
37
+
38
+ def check_numeric_array(label, value)
39
+ return nil if value.nil?
40
+ raise ArgumentError, "#{label} must be an array of numbers." unless value.is_a?(Array)
41
+ return nil if value.empty?
42
+ raise ArgumentError, "#{label} must not contain non-numeric values" unless value.all?(Numeric)
43
+ value
44
+ end
45
+
46
+ def check_analytics_label(label, value)
47
+ return nil unless value
48
+ value = check_string(label, value)
49
+ raise ArgumentError, "#{label} is malformed" unless /\A[a-zA-Z0-9\-_.~%]{1,50}\Z/.match?(value)
50
+ value
51
+ end
52
+
53
+ def check_time(label, value)
54
+ return nil unless value
55
+ raise ArgumentError, "#{label} must be a time." unless value.is_a?(Time)
56
+ value
57
+ end
58
+
59
+ # @return [String, nil]
60
+ def check_color(label, value, allow_alpha: false, required: false)
61
+ return nil unless value || required
62
+ raise ArgumentError, "#{label} is required" unless value
63
+ raise ArgumentError, "#{label} must be a string" unless value.is_a?(String)
64
+ unless /\A#[0-9a-fA-F]{6}\Z/.match?(value) || (/\A#[0-9a-fA-F]{8}\Z/.match?(value) && allow_alpha)
65
+ raise ArgumentError, "#{label} must be in the form #RRGGBB" unless allow_alpha
66
+ raise ArgumentError, "#{label} must be in the form #RRGGBB or #RRGGBBAA"
67
+ end
68
+ value
69
+ end
70
+
71
+ def to_seconds_string(seconds)
72
+ has_nanos = (seconds - seconds.floor) > 0
73
+ format(has_nanos ? "%0.9fs" : "%ds", seconds)
74
+ end
75
+ end
76
+ end
77
+ end
78
+ end
@@ -2,6 +2,6 @@
2
2
 
3
3
  module Firebase
4
4
  module Admin
5
- VERSION = "0.1.0"
5
+ VERSION = "0.1.1"
6
6
  end
7
7
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: firebase-admin-sdk
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.1.0
4
+ version: 0.1.1
5
5
  platform: ruby
6
6
  authors:
7
7
  - Tariq Zaid
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2021-06-03 00:00:00.000000000 Z
11
+ date: 2021-07-12 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: googleauth
@@ -52,6 +52,20 @@ dependencies:
52
52
  - - "~>"
53
53
  - !ruby/object:Gem::Version
54
54
  version: '1.0'
55
+ - !ruby/object:Gem::Dependency
56
+ name: hashie
57
+ requirement: !ruby/object:Gem::Requirement
58
+ requirements:
59
+ - - "~>"
60
+ - !ruby/object:Gem::Version
61
+ version: '4.1'
62
+ type: :runtime
63
+ prerelease: false
64
+ version_requirements: !ruby/object:Gem::Requirement
65
+ requirements:
66
+ - - "~>"
67
+ - !ruby/object:Gem::Version
68
+ version: '4.1'
55
69
  - !ruby/object:Gem::Dependency
56
70
  name: jwt
57
71
  requirement: !ruby/object:Gem::Requirement
@@ -203,6 +217,26 @@ files:
203
217
  - lib/firebase/admin/error.rb
204
218
  - lib/firebase/admin/gce.rb
205
219
  - lib/firebase/admin/internal/http_client.rb
220
+ - lib/firebase/admin/messaging/android_config.rb
221
+ - lib/firebase/admin/messaging/android_fcm_options.rb
222
+ - lib/firebase/admin/messaging/android_notification.rb
223
+ - lib/firebase/admin/messaging/apns_config.rb
224
+ - lib/firebase/admin/messaging/apns_fcm_options.rb
225
+ - lib/firebase/admin/messaging/apns_payload.rb
226
+ - lib/firebase/admin/messaging/aps.rb
227
+ - lib/firebase/admin/messaging/aps_alert.rb
228
+ - lib/firebase/admin/messaging/client.rb
229
+ - lib/firebase/admin/messaging/critical_sound.rb
230
+ - lib/firebase/admin/messaging/error.rb
231
+ - lib/firebase/admin/messaging/error_info.rb
232
+ - lib/firebase/admin/messaging/fcm_options.rb
233
+ - lib/firebase/admin/messaging/light_settings.rb
234
+ - lib/firebase/admin/messaging/message.rb
235
+ - lib/firebase/admin/messaging/message_encoder.rb
236
+ - lib/firebase/admin/messaging/multicast_message.rb
237
+ - lib/firebase/admin/messaging/notification.rb
238
+ - lib/firebase/admin/messaging/topic_management_response.rb
239
+ - lib/firebase/admin/messaging/utils.rb
206
240
  - lib/firebase/admin/version.rb
207
241
  homepage: https://github.com/cheddar-me/firebase-admin-sdk-ruby
208
242
  licenses: