Module: ActsAsHocPushable

Extended by:
ActiveSupport::Concern
Defined in:
lib/acts_as_hoc_pushable.rb,
lib/acts_as_hoc_pushable/version.rb,
lib/acts_as_hoc_pushable/configuration.rb,
lib/acts_as_hoc_pushable/push_notification.rb,
lib/acts_as_hoc_pushable/active_record/device.rb,
lib/acts_as_hoc_pushable/acts_as_hoc_pushable.rb,
lib/generators/acts_as_hoc_pushable/install_generator.rb

Defined Under Namespace

Modules: ClassMethods, Generators Classes: Configuration, Device, PushNotification

Constant Summary collapse

LOCK =
Mutex.new
VERSION =
"1.0.1"

Class Method Summary collapse

Instance Method Summary collapse

Class Method Details

.configurationObject



20
21
22
23
# File 'lib/acts_as_hoc_pushable.rb', line 20

def configuration
  @configuration = nil unless defined?(@configuration)
  @configuration || LOCK.synchronize { @configuration ||= ActsAsHocPushable::Configuration.new }
end

.configure(config_hash = nil) {|configuration| ... } ⇒ Object

Yields:



10
11
12
13
14
15
16
17
18
# File 'lib/acts_as_hoc_pushable.rb', line 10

def configure(config_hash=nil)
  if config_hash
    config_hash.each do |k,v|
      configuration.send("#{k}=", v) rescue nil if configuration.respond_to?("#{k}=")
    end
  end

  yield(configuration) if block_given?
end

Instance Method Details

#active_devicesObject



13
14
15
# File 'lib/acts_as_hoc_pushable/acts_as_hoc_pushable.rb', line 13

def active_devices
  devices.active
end

#add_device(device_params) ⇒ Object



26
27
28
29
30
31
32
33
# File 'lib/acts_as_hoc_pushable/acts_as_hoc_pushable.rb', line 26

def add_device(token:, platform:, platform_version:, push_environment:)
  device = devices.new(token: token, platform: platform, platform_version: platform_version, push_environment: push_environment)
  return device if device.save
  device.errors.each do |attribute, message|
    errors.add(:devices, "#{attribute} #{message}")
  end
  nil
end

#add_device!(device_params) ⇒ Object



44
45
46
47
48
# File 'lib/acts_as_hoc_pushable/acts_as_hoc_pushable.rb', line 44

def add_device!(device_params)
  device = devices.new(device_params)
  device.save!
  device
end

#android_devicesObject



21
22
23
# File 'lib/acts_as_hoc_pushable/acts_as_hoc_pushable.rb', line 21

def android_devices
  devices.android
end

#ios_devicesObject



17
18
19
# File 'lib/acts_as_hoc_pushable/acts_as_hoc_pushable.rb', line 17

def ios_devices
  devices.ios
end

#send_push_notification(title:, message:, **data) ⇒ Object



50
51
52
# File 'lib/acts_as_hoc_pushable/acts_as_hoc_pushable.rb', line 50

def send_push_notification(title:, message:, **data)
  ActsAsHocPushable::PushNotification.send_push_notification(devices: devices, title: title, message: message, **data)
end

#send_silent_push_notification(**data) ⇒ Object



54
55
56
# File 'lib/acts_as_hoc_pushable/acts_as_hoc_pushable.rb', line 54

def send_silent_push_notification(**data)
  ActsAsHocPushable::PushNotification.send_silent_push_notification(devices: devices, **data)
end