Module: Rapns

Defined in:
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_rails_2.rb,
lib/rapns_rails_2.rb,
lib/rapns/apns/app.rb,
lib/rapns/notifier.rb,
lib/rapns/upgraded.rb,
lib/rapns/reflection.rb,
lib/rapns/deprecation.rb,
lib/rapns/daemon/batch.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/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/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/daemon/delivery_handler_collection.rb,
lib/rapns/gcm/registration_ids_count_validator.rb,
lib/rapns/daemon/apns/certificate_expired_error.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, Notifier, Reflections

Constant Summary collapse

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

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

.attr_accessible_available?Boolean

Returns:

  • (Boolean)


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

def self.attr_accessible_available?
  is_rails2_or_3?
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

.is_rails2?Boolean

Returns:

  • (Boolean)


6
7
8
9
10
11
# File 'lib/rapns_rails_2.rb', line 6

def self.is_rails2?
  require 'rails'
  false
rescue MissingSourceFile
  true
end

.is_rails2_or_3?Boolean

Returns:

  • (Boolean)


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

def self.is_rails2_or_3?
  is_rails2? || ::Rails::VERSION::STRING < '4'
end

.jruby?Boolean

Returns:

  • (Boolean)


52
53
54
# File 'lib/rapns_rails_2.rb', line 52

def self.jruby?
  defined? JRUBY_VERSION
end

.loggerObject



60
61
62
63
# File 'lib/rapns_rails_2.rb', line 60

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

.logger=(logger) ⇒ Object



65
66
67
# File 'lib/rapns_rails_2.rb', line 65

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

.notifierObject

Default notifier instance. This uses the :connect, :port values in Rapns.config.wakeup to connect to the wakeup socket in the Rapns Daemon. It will fall back to :host, :port if :connect is not specified.



44
45
46
47
48
49
50
51
# File 'lib/rapns/notifier.rb', line 44

def self.notifier
  unless @notifier
    if Rapns.config.wakeup
      @notifier = Notifier.new(Rapns.config.wakeup[:connect] || Rapns.config.wakeup[:host], Rapns.config.wakeup[:port])
    end
  end
  @notifier
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



56
57
58
# File 'lib/rapns_rails_2.rb', line 56

def self.require_for_daemon
  require 'rapns/daemon'
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

.wakeupObject

Call this from a client application after saving a Notification to the database to wakeup the Rapns Daemon to deliver the notification immediately.



38
39
40
# File 'lib/rapns/notifier.rb', line 38

def self.wakeup
  notifier.notify
end