Module: Rpush

Defined in:
lib/rpush.rb,
lib/rpush.rb,
lib/rpush/app.rb,
lib/rpush/push.rb,
lib/rpush/embed.rb,
lib/rpush/daemon.rb,
lib/rpush/logger.rb,
lib/rpush/adm/app.rb,
lib/rpush/gcm/app.rb,
lib/rpush/version.rb,
lib/rpush/apns/app.rb,
lib/rpush/notifier.rb,
lib/rpush/wpns/app.rb,
lib/rpush/daemon/adm.rb,
lib/rpush/daemon/gcm.rb,
lib/rpush/reflection.rb,
lib/rpush/daemon/apns.rb,
lib/rpush/daemon/wpns.rb,
lib/rpush/deprecation.rb,
lib/rpush/daemon/batch.rb,
lib/rpush/deprecatable.rb,
lib/rpush/notification.rb,
lib/rpush/apns/feedback.rb,
lib/rpush/apns_feedback.rb,
lib/rpush/configuration.rb,
lib/rpush/daemon/feeder.rb,
lib/rpush/daemon/delivery.rb,
lib/rpush/daemon/loggable.rb,
lib/rpush/adm/notification.rb,
lib/rpush/daemon/constants.rb,
lib/rpush/gcm/notification.rb,
lib/rpush/apns/notification.rb,
lib/rpush/daemon/app_runner.rb,
lib/rpush/multi_json_helper.rb,
lib/rpush/wpns/notification.rb,
lib/rpush/adm/data_validator.rb,
lib/rpush/daemon/reflectable.rb,
lib/rpush/daemon/adm/delivery.rb,
lib/rpush/daemon/gcm/delivery.rb,
lib/rpush/daemon/apns/delivery.rb,
lib/rpush/daemon/wpns/delivery.rb,
lib/rpush/daemon/delivery_error.rb,
lib/rpush/daemon/dispatcher/tcp.rb,
lib/rpush/daemon/tcp_connection.rb,
lib/rpush/daemon/dispatcher/http.rb,
lib/rpush/daemon/dispatcher_loop.rb,
lib/rpush/daemon/retryable_error.rb,
lib/rpush/daemon/interruptible_sleep.rb,
lib/rpush/daemon/retry_header_parser.rb,
lib/rpush/daemon/store/active_record.rb,
lib/rpush/payload_data_size_validator.rb,
lib/rpush/daemon/apns/feedback_receiver.rb,
lib/rpush/daemon/service_config_methods.rb,
lib/rpush/daemon/too_many_requests_error.rb,
lib/rpush/daemon/apns/disconnection_error.rb,
lib/rpush/registration_ids_count_validator.rb,
lib/rpush/daemon/dispatcher_loop_collection.rb,
lib/rpush/apns/binary_notification_validator.rb,
lib/rpush/apns/device_token_format_validator.rb,
lib/rpush/daemon/apns/certificate_expired_error.rb,
lib/rpush/daemon/store/active_record/reconnectable.rb,
lib/rpush/gcm/expiry_collapse_key_mutual_inclusion_validator.rb

Defined Under Namespace

Modules: Adm, Apns, Daemon, Deprecatable, Gcm, MultiJsonHelper, Wpns Classes: App, Configuration, ConfigurationWithoutDefaults, DeliveryError, Deprecation, Logger, Notification, Notifier, PayloadDataSizeValidator, Reflections, RegistrationIdsCountValidator, RetryableError, TooManyRequestsError

Constant Summary collapse

VERSION =
'1.0.0'
CONFIG_ATTRS =
[:foreground, :push_poll, :feedback_poll, :embedded,
: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/rpush/apns_feedback.rb', line 2

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

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

  nil
end

.attr_accessible_available?Boolean

Returns:

  • (Boolean)


5
6
7
8
# File 'lib/rpush.rb', line 5

def self.attr_accessible_available?
  require 'rails'
  ::Rails::VERSION::STRING < '4'
end

.configObject



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

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

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

Yields:



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

def self.configure
  yield config if block_given?
end

.debugObject



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

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

.embed(options = {}) ⇒ Object



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

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

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

  Kernel.at_exit { shutdown }
end

.jruby?Boolean

Returns:

  • (Boolean)


47
48
49
# File 'lib/rpush.rb', line 47

def self.jruby?
  defined? JRUBY_VERSION
end

.loggerObject



55
56
57
# File 'lib/rpush.rb', line 55

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

.logger=(logger) ⇒ Object



59
60
61
# File 'lib/rpush.rb', line 59

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

.notifierObject

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



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

def self.notifier
  unless @notifier
    if Rpush.config.wakeup
      @notifier = Notifier.new(Rpush.config.wakeup[:connect] || Rpush.config.wakeup[:host], Rpush.config.wakeup[:port])
    end
  end
  @notifier
end

.push(options = {}) ⇒ Object



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

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

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

  Rpush::Daemon.initialize_store
  Rpush::Daemon::AppRunner.sync
  Rpush::Daemon::Feeder.start
  Rpush::Daemon::AppRunner.wait
  Rpush::Daemon::AppRunner.stop
end

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

Yields:



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

def self.reflect
  yield reflections if block_given?
end

.reflectionsObject



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

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

.require_for_daemonObject



51
52
53
# File 'lib/rpush.rb', line 51

def self.require_for_daemon
  require 'rpush/daemon'
end

.shutdownObject



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

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

.syncObject



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

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

.wakeupObject

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



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

def self.wakeup
  notifier.notify
end