Module: Agilib::PushNotification::Model

Extended by:
ActiveSupport::Concern
Defined in:
lib/agilib/push_notification/model.rb

Defined Under Namespace

Modules: ClassMethods

Instance Method Summary collapse

Instance Method Details

#send_push_notification(message, data = {}, platforms = :all) ⇒ Object



8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
# File 'lib/agilib/push_notification/model.rb', line 8

def send_push_notification(message, data = {}, platforms = :all)
  @platforms  = Hash.new
  @devices    = self.devices.all
  @responses  = Hash.new

  message = message[0,50]

  unless platforms.is_a? Array
    if platforms.to_sym == :all
      @platforms = Agilib::PushNotification.avaiable_platforms
    else
      @platforms[platforms] = Agilib::PushNotification.avaiable_platforms[platforms]
    end
  else
    platforms.each do |platform|
      @platforms[platform] = Agilib::PushNotification.avaiable_platforms[platform] if Agilib::PushNotification.avaiable_platforms.has_key?(platform)
    end
  end

  @devices.each do |device|
    if @platforms.has_key? device.platform.to_sym
      platform = @platforms[device.platform.to_sym]
      @responses[device.platform.to_sym] = platform.send_notification(message, data, device)
    end
  end

  return @responses
end