Module: Rpush

Defined in:
lib/rpush.rb,
lib/rpush.rb,
lib/rpush/cli.rb,
lib/rpush/push.rb,
lib/rpush/embed.rb,
lib/rpush/daemon.rb,
lib/rpush/plugin.rb,
lib/rpush/logger.rb,
lib/rpush/version.rb,
lib/rpush/daemon/wns.rb,
lib/rpush/daemon/gcm.rb,
lib/rpush/daemon/adm.rb,
lib/rpush/daemon/rpc.rb,
lib/rpush/deprecation.rb,
lib/rpush/reflectable.rb,
lib/rpush/daemon/wpns.rb,
lib/rpush/daemon/apns.rb,
lib/rpush/deprecatable.rb,
lib/rpush/daemon/batch.rb,
lib/rpush/apns_feedback.rb,
lib/rpush/daemon/feeder.rb,
lib/rpush/daemon/errors.rb,
lib/rpush/configuration.rb,
lib/rpush/daemon/delivery.rb,
lib/rpush/daemon/loggable.rb,
lib/rpush/client/redis/app.rb,
lib/rpush/daemon/constants.rb,
lib/rpush/multi_json_helper.rb,
lib/rpush/daemon/rpc/server.rb,
lib/rpush/daemon/rpc/client.rb,
lib/rpush/daemon/app_runner.rb,
lib/rpush/daemon/proc_title.rb,
lib/rpush/client/mongoid/app.rb,
lib/rpush/daemon/store/redis.rb,
lib/rpush/daemon/ring_buffer.rb,
lib/rpush/daemon/adm/delivery.rb,
lib/rpush/daemon/synchronizer.rb,
lib/rpush/daemon/gcm/delivery.rb,
lib/rpush/daemon/wns/delivery.rb,
lib/rpush/client/redis/wns/app.rb,
lib/rpush/client/redis/adm/app.rb,
lib/rpush/daemon/store/mongoid.rb,
lib/rpush/client/redis/gcm/app.rb,
lib/rpush/daemon/queue_payload.rb,
lib/rpush/daemon/wpns/delivery.rb,
lib/rpush/daemon/apns/delivery.rb,
lib/rpush/daemon/tcp_connection.rb,
lib/rpush/daemon/signal_handler.rb,
lib/rpush/reflection_collection.rb,
lib/rpush/daemon/delivery_error.rb,
lib/rpush/daemon/string_helpers.rb,
lib/rpush/client/redis/apns/app.rb,
lib/rpush/daemon/dispatcher/tcp.rb,
lib/rpush/client/redis/wpns/app.rb,
lib/rpush/daemon/store/interface.rb,
lib/rpush/client/mongoid/adm/app.rb,
lib/rpush/daemon/retryable_error.rb,
lib/rpush/daemon/dispatcher/http.rb,
lib/rpush/client/mongoid/gcm/app.rb,
lib/rpush/client/mongoid/wns/app.rb,
lib/rpush/daemon/dispatcher_loop.rb,
lib/rpush/client/mongoid/apns/app.rb,
lib/rpush/client/mongoid/wpns/app.rb,
lib/rpush/client/active_record/app.rb,
lib/rpush/client/redis/notification.rb,
lib/rpush/reflection_public_methods.rb,
lib/rpush/daemon/interruptible_sleep.rb,
lib/rpush/client/redis/apns/feedback.rb,
lib/rpush/daemon/store/active_record.rb,
lib/rpush/daemon/dispatcher/apns_tcp.rb,
lib/rpush/daemon/retry_header_parser.rb,
lib/rpush/client/active_model/wns/app.rb,
lib/rpush/client/active_model/adm/app.rb,
lib/rpush/client/mongoid/notification.rb,
lib/rpush/client/active_model/gcm/app.rb,
lib/rpush/client/active_record/adm/app.rb,
lib/rpush/client/active_model/apns/app.rb,
lib/rpush/client/mongoid/apns/feedback.rb,
lib/rpush/client/active_record/wns/app.rb,
lib/rpush/client/active_record/gcm/app.rb,
lib/rpush/client/active_model/wpns/app.rb,
lib/rpush/client/redis/gcm/notification.rb,
lib/rpush/client/redis/wns/notification.rb,
lib/rpush/daemon/apns/feedback_receiver.rb,
lib/rpush/client/active_record/wpns/app.rb,
lib/rpush/client/redis/adm/notification.rb,
lib/rpush/daemon/service_config_methods.rb,
lib/rpush/client/active_record/apns/app.rb,
lib/rpush/client/redis/wpns/notification.rb,
lib/rpush/client/redis/apns/notification.rb,
lib/rpush/client/mongoid/adm/notification.rb,
lib/rpush/client/mongoid/wns/notification.rb,
lib/rpush/client/mongoid/gcm/notification.rb,
lib/rpush/client/active_model/notification.rb,
lib/rpush/client/mongoid/apns/notification.rb,
lib/rpush/client/mongoid/wpns/notification.rb,
lib/rpush/client/active_record/notification.rb,
lib/rpush/client/active_record/apns/feedback.rb,
lib/rpush/client/active_model/wns/notification.rb,
lib/rpush/client/active_model/adm/notification.rb,
lib/rpush/client/active_model/gcm/notification.rb,
lib/rpush/client/active_model/wpns/notification.rb,
lib/rpush/client/active_record/wns/notification.rb,
lib/rpush/client/active_model/apns/notification.rb,
lib/rpush/client/active_record/gcm/notification.rb,
lib/rpush/client/active_record/adm/notification.rb,
lib/rpush/client/active_record/apns/notification.rb,
lib/rpush/client/active_model/adm/data_validator.rb,
lib/rpush/client/active_record/wpns/notification.rb,
lib/rpush/daemon/store/active_record/reconnectable.rb,
lib/rpush/client/active_model/payload_data_size_validator.rb,
lib/rpush/client/active_model/registration_ids_count_validator.rb,
lib/rpush/client/active_model/apns/device_token_format_validator.rb,
lib/rpush/client/active_model/apns/binary_notification_validator.rb,
lib/rpush/client/active_model/gcm/expiry_collapse_key_mutual_inclusion_validator.rb

Defined Under Namespace

Modules: Client, Daemon, Deprecatable, MultiJsonHelper, Reflectable Classes: ApnsConfiguration, ApnsFeedbackReceiverConfiguration, CLI, CertificateExpiredError, Configuration, ConfigurationError, ConfigurationWithoutDefaults, DeliveryError, Deprecation, Logger, Plugin, RateLimitError, ReflectionCollection, RetryableError

Constant Summary collapse

VERSION =
'2.5.0'
CURRENT_ATTRS =
[:push_poll, :embedded, :pid_file, :batch_size, :push, :client, :logger, :log_file, :foreground, :log_level, :plugin, :apns]
DEPRECATED_ATTRS =
[]
CONFIG_ATTRS =
CURRENT_ATTRS + DEPRECATED_ATTRS

Class Attribute Summary collapse

Class Method Summary collapse

Class Attribute Details

.configObject


8
9
10
# File 'lib/rpush/configuration.rb', line 8

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

.loggerObject


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

def self.logger
  @logger ||= Logger.new
end

.reflection_stackObject (readonly)

Returns the value of attribute reflection_stack


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

def reflection_stack
  @reflection_stack
end

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
  require 'rpush/daemon'
  Rpush::Daemon.common_init

  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)

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

def self.attr_accessible_available?
  require 'rails'
rescue LoadError
  false
else
  ::Rails::VERSION::STRING < '4' || defined?(::ActiveRecord::MassAssignmentSecurity)
end

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

Yields:


12
13
14
15
16
# File 'lib/rpush/configuration.rb', line 12

def configure
  return unless block_given?
  yield config
  config.initialize_client
end

.debugObject


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

def self.debug
  status
end

.embedObject


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

def self.embed
  require 'rpush/daemon'

  if @embed_thread
    STDERR.puts 'Rpush.embed can only be run once inside this process.'
  end

  Rpush.config.embedded = true
  Rpush.config.foreground = true
  Kernel.at_exit { shutdown }
  @embed_thread = Thread.new { Rpush::Daemon.start }
end

.jruby?Boolean

Returns:

  • (Boolean)

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

def self.jruby?
  defined? JRUBY_VERSION
end

.plugin(name) ⇒ Object


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

def self.plugin(name)
  plugins[name] ||= Rpush::Plugin.new(name)
  plugins[name]
end

.pluginsObject


7
8
9
# File 'lib/rpush/plugin.rb', line 7

def self.plugins
  @plugins ||= {}
end

.pushObject


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

def self.push
  require 'rpush/daemon'

  Rpush.config.push = true
  Rpush::Daemon.common_init
  Rpush::Daemon::Synchronizer.sync
  Rpush::Daemon::Feeder.start(true) # non-blocking
  Rpush::Daemon::AppRunner.stop
end

.reflect {|reflection_stack[0]| ... } ⇒ Object

Yields:


8
9
10
# File 'lib/rpush/reflection_public_methods.rb', line 8

def self.reflect
  yield reflection_stack[0] if block_given?
end

.rootObject


39
40
41
42
43
44
# File 'lib/rpush.rb', line 39

def self.root
  require 'rails'
  Rails.root || Dir.pwd
rescue LoadError
  Dir.pwd
end

.shutdownObject


15
16
17
18
19
20
21
22
23
24
# File 'lib/rpush/embed.rb', line 15

def self.shutdown
  return unless Rpush.config.embedded
  Rpush::Daemon.shutdown
  @embed_thread.join if @embed_thread
rescue StandardError => e
  STDERR.puts(e.message)
  STDERR.puts(e.backtrace.join("\n"))
ensure
  @embed_thread = nil
end

.statusObject


31
32
33
34
35
36
# File 'lib/rpush/embed.rb', line 31

def self.status
  return unless Rpush.config.embedded
  status = Rpush::Daemon::AppRunner.status
  Rpush.logger.info(JSON.pretty_generate(status))
  status
end

.syncObject


26
27
28
29
# File 'lib/rpush/embed.rb', line 26

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