Module: Rapns

Defined in:
lib/rapns.rb,
lib/rapns/app.rb,
lib/rapns/push.rb,
lib/rapns/embed.rb,
lib/rapns/daemon.rb,
lib/rapns/logger.rb,
lib/rapns/gcm/app.rb,
lib/rapns/version.rb,
lib/rapns/apns/app.rb,
lib/rapns/upgraded.rb,
lib/rapns/reflection.rb,
lib/rapns/deprecation.rb,
lib/rapns/deprecatable.rb,
lib/rapns/notification.rb,
lib/rapns/apns/feedback.rb,
lib/rapns/apns_feedback.rb,
lib/rapns/configuration.rb,
lib/rapns/daemon/feeder.rb,
lib/rapns/daemon/delivery.rb,
lib/rapns/gcm/notification.rb,
lib/rapns/apns/notification.rb,
lib/rapns/daemon/app_runner.rb,
lib/rapns/multi_json_helper.rb,
lib/rapns/daemon/reflectable.rb,
lib/rapns/daemon/gcm/delivery.rb,
lib/rapns/daemon/apns/delivery.rb,
lib/rapns/daemon/delivery_error.rb,
lib/rapns/daemon/delivery_queue.rb,
lib/rapns/daemon/gcm/app_runner.rb,
lib/rapns/daemon/apns/app_runner.rb,
lib/rapns/daemon/apns/connection.rb,
lib/rapns/daemon/delivery_handler.rb,
lib/rapns/daemon/delivery_queue_18.rb,
lib/rapns/daemon/delivery_queue_19.rb,
lib/rapns/daemon/interruptible_sleep.rb,
lib/rapns/daemon/store/active_record.rb,
lib/rapns/daemon/gcm/delivery_handler.rb,
lib/rapns/daemon/apns/delivery_handler.rb,
lib/rapns/daemon/apns/feedback_receiver.rb,
lib/rapns/daemon/apns/disconnection_error.rb,
lib/rapns/gcm/payload_data_size_validator.rb,
lib/rapns/apns/binary_notification_validator.rb,
lib/rapns/apns/device_token_format_validator.rb,
lib/rapns/gcm/registration_ids_count_validator.rb,
lib/rapns/daemon/store/active_record/reconnectable.rb,
lib/rapns/gcm/expiry_collapse_key_mutual_inclusion_validator.rb

Defined Under Namespace

Modules: Apns, Daemon, Deprecatable, Gcm, MultiJsonHelper, Upgraded Classes: App, Configuration, ConfigurationWithoutDefaults, DeliveryError, Deprecation, Logger, Notification, Reflections

Constant Summary collapse

VERSION =
'3.3.1'
CONFIG_ATTRS =
[:foreground, :push_poll, :feedback_poll, :embedded,
:airbrake_notify, :check_for_errors, :pid_file, :batch_size,
:push, :store, :logger]

Class Method Summary collapse

Class Method Details

.apns_feedbackObject



2
3
4
5
6
7
8
9
10
11
12
# File 'lib/rapns/apns_feedback.rb', line 2

def self.apns_feedback
  Rapns.require_for_daemon
  Rapns::Daemon.initialize_store

  Rapns::Apns::App.all.each do |app|
    receiver = Rapns::Daemon::Apns::FeedbackReceiver.new(app, 0)
    receiver.check_for_feedback
  end

  nil
end

.configObject



2
3
4
# File 'lib/rapns/configuration.rb', line 2

def self.config
  @config ||= Rapns::Configuration.new
end

.configure {|config| ... } ⇒ Object

Yields:



6
7
8
# File 'lib/rapns/configuration.rb', line 6

def self.configure
  yield config if block_given?
end

.debugObject



24
25
26
27
# File 'lib/rapns/embed.rb', line 24

def self.debug
  return unless Rapns.config.embedded
  Rapns::Daemon::AppRunner.debug
end

.embed(options = {}) ⇒ Object



2
3
4
5
6
7
8
9
10
11
12
# File 'lib/rapns/embed.rb', line 2

def self.embed(options = {})
  Rapns.require_for_daemon

  config = Rapns::ConfigurationWithoutDefaults.new
  options.each { |k, v| config.send("#{k}=", v) }
  config.embedded = true
  Rapns.config.update(config)
  Rapns::Daemon.start

  Kernel.at_exit { shutdown }
end

.jruby?Boolean

Returns:

  • (Boolean)


31
32
33
# File 'lib/rapns.rb', line 31

def self.jruby?
  defined? JRUBY_VERSION
end

.loggerObject



40
41
42
43
# File 'lib/rapns.rb', line 40

def self.logger
  @logger ||= Logger.new(:foreground => Rapns.config.foreground,
                         :airbrake_notify => Rapns.config.airbrake_notify)
end

.logger=(logger) ⇒ Object



45
46
47
# File 'lib/rapns.rb', line 45

def self.logger=(logger)
  @logger = logger
end

.push(options = {}) ⇒ Object



2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
# File 'lib/rapns/push.rb', line 2

def self.push(options = {})
  Rapns.require_for_daemon

  config = Rapns::ConfigurationWithoutDefaults.new
  options.each { |k, v| config.send("#{k}=", v) }
  config.push = true
  Rapns.config.update(config)

  Upgraded.check(:exit => false)
  Rapns::Daemon.initialize_store
  Rapns::Daemon::AppRunner.sync
  Rapns::Daemon::Feeder.start
  Rapns::Daemon::AppRunner.wait
  Rapns::Daemon::AppRunner.stop
end

.reflect {|reflections| ... } ⇒ Object

Yields:



2
3
4
# File 'lib/rapns/reflection.rb', line 2

def self.reflect
  yield reflections if block_given?
end

.reflectionsObject



6
7
8
# File 'lib/rapns/reflection.rb', line 6

def self.reflections
  @reflections ||= Reflections.new
end

.require_for_daemonObject



35
36
37
38
# File 'lib/rapns.rb', line 35

def self.require_for_daemon
  require 'rapns/daemon'
  require 'rapns/patches'
end

.shutdownObject



14
15
16
17
# File 'lib/rapns/embed.rb', line 14

def self.shutdown
  return unless Rapns.config.embedded
  Rapns::Daemon.shutdown
end

.syncObject



19
20
21
22
# File 'lib/rapns/embed.rb', line 19

def self.sync
  return unless Rapns.config.embedded
  Rapns::Daemon::AppRunner.sync
end