Class: InovaFCM::Service

Inherits:
Object
  • Object
show all
Defined in:
lib/inova_fcm/service.rb

Constant Summary collapse

MAX_TOPIC_REGISTRATION_BATCH_SIZE =
1000

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(registration_ids: [], notification: {}, data: {}, topic: SecureRandom.uuid + Time.now.to_i.to_s) ⇒ Service

Returns a new instance of Service.



10
11
12
13
14
15
16
17
18
19
20
21
22
23
# File 'lib/inova_fcm/service.rb', line 10

def initialize(registration_ids: [], notification: {}, data: {}, topic: SecureRandom.uuid + Time.now.to_i.to_s)
  @topic = topic
  @registration_ids = registration_ids.uniq
  @notification = notification
  @data = data

  InovaFCM.configuration.validate!

  @fcm = FCM.new(InovaFCM.configuration.fcm_key,
    InovaFCM.configuration.firebase_admin_sdk_path,
    InovaFCM.configuration.firebase_project_id)

  validate_attributes!
end

Instance Attribute Details

#dataObject (readonly)

Returns the value of attribute data.



8
9
10
# File 'lib/inova_fcm/service.rb', line 8

def data
  @data
end

#notificationObject (readonly)

Returns the value of attribute notification.



8
9
10
# File 'lib/inova_fcm/service.rb', line 8

def notification
  @notification
end

#registration_idsObject (readonly)

Returns the value of attribute registration_ids.



8
9
10
# File 'lib/inova_fcm/service.rb', line 8

def registration_ids
  @registration_ids
end

#topicObject (readonly)

Returns the value of attribute topic.



8
9
10
# File 'lib/inova_fcm/service.rb', line 8

def topic
  @topic
end

Instance Method Details

#send_notificationObject



25
26
27
28
29
30
31
# File 'lib/inova_fcm/service.rb', line 25

def send_notification
  if @registration_ids.count > 1
    bulk_send_notification
  else
    @fcm.send_v1(prepare_token_message)
  end
end