Class: EventMachine::ApnManager::CLI
- Inherits:
-
Thor
- Object
- Thor
- EventMachine::ApnManager::CLI
- Defined in:
- lib/em_apn_manager/cli.rb
Instance Method Summary collapse
-
#initialize(args = [], opts = [], config = {}) ⇒ CLI
constructor
3 ways to specify the redis 1.
- #mock_apn_server ⇒ Object
-
#push_test_message ⇒ Object
if message is DISCONNECT, mock apns will disconnect.
- #server ⇒ Object
Constructor Details
#initialize(args = [], opts = [], config = {}) ⇒ CLI
3 ways to specify the redis
-
config yml file
-
pass redis-url is ‘redis://username:password@host:port/database’
like ‘redis://test:test@localhost:6379/em_apn_manager`
28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 |
# File 'lib/em_apn_manager/cli.rb', line 28 def initialize(args = [], opts = [], config = {}) super(args, opts, config) redis_config = [:redis] if redis_config.nil? # read the environment var. @environment = ENV["RAILS_ENV"] || "development" @environment = [:environment] if %w{test development production}.include? [:environment] # Read config option, or use default config yml config_path = [:config] || File.join(".", "config", "em_apn_manager.yml") if config_path && File.exists?(config_path) EM::ApnManager.config = Thor::CoreExt::HashWithIndifferentAccess.new(YAML.load_file(config_path)) redis_config = EM::ApnManager.config[@environment] end # default redis redis_config ||= "redis://localhost:6379/em_apn_manager" end # create redis connection $apn_manager_redis = Redis.new url: redis_config end |
Instance Method Details
#mock_apn_server ⇒ Object
82 83 84 85 |
# File 'lib/em_apn_manager/cli.rb', line 82 def mock_apn_server EM::ApnManager.logger.info("Starting Mock APN Server") EM.run { EM.start_server("127.0.0.1", 2195, EM::ApnManager::ApnServer) } end |
#push_test_message ⇒ Object
if message is DISCONNECT, mock apns will disconnect.
66 67 68 69 70 71 72 73 74 75 76 77 78 79 |
# File 'lib/em_apn_manager/cli.rb', line 66 def EM::ApnManager.push_notification({ env: @environment, cert: File.read(ENV["APN_CERT"]), # test cert # iPhone5 # "D42A6795D0C6C0E5F3CC762F905C3654D2A07E72D64CDEC1E2F74AC43C4CC440" # iPhone4 # "BACF565FB283E9F7378D5A0AEBCBCB49A4D7834AED8FAC7FE0CB28144D94E456" # My iPhone4s # "0F93C49EAAF3544B5218D2BAE893608C515F69B445279AB2B17511C37046C52B" token: ["0F93C49EAAF3544B5218D2BAE893608C515F69B445279AB2B17511C37046C52B"].sample, message: "Hahahaha I am going to spam you. #{rand * 100}" }) end |
#server ⇒ Object
55 56 57 58 59 60 61 |
# File 'lib/em_apn_manager/cli.rb', line 55 def server daemonize if [:daemon] write_pid_file([:pid_file]) if [:pid_file] EM::ApnManager.logger.info("Starting APN Manager") EM.run { EM::ApnManager::Manager.run } end |