Class: APND::CLI
- Inherits:
-
Object
- Object
- APND::CLI
- Defined in:
- lib/apnd/cli.rb
Overview
:nodoc: all
Class Method Summary collapse
-
.daemon(argv) ⇒ Object
Run apnd daemon.
-
.push(argv) ⇒ Object
Run apnd push.
Class Method Details
.daemon(argv) ⇒ Object
Run apnd daemon
93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 |
# File 'lib/apnd/cli.rb', line 93 def self.daemon(argv) help = <<-HELP Usage: apnd daemon --apple-cert </path/to/cert> HELP = {} opts = OptionParser.new do |opt| opt. = help opt.separator "Required Arguments:\n" opt.on('--apple-cert [PATH]', 'PATH to APN certificate from Apple') do |cert| [:apple_cert] = cert end opt.separator "\nOptional Arguments:\n" opt.on('--apple-host [HOST]', "Connect to Apple at HOST (default is gateway.sandbox.push.apple.com)") do |host| [:apple_host] = host end opt.on('--apple-port [PORT]', 'Connect to Apple on PORT (default is 2195)') do |port| [:apple_port] = port.to_i end opt.on('--apple-cert-pass [PASSWORD]', 'PASSWORD for APN certificate from Apple') do |pass| [:apple_cert_pass] = pass end opt.on('--daemon-port [PORT]', 'Run APND on PORT (default is 22195)') do |port| [:daemon_port] = port.to_i end opt.on('--daemon-bind [ADDRESS]', 'Bind APND to ADDRESS (default is 0.0.0.0)') do |bind| [:daemon_bind] = bind end opt.on('--daemon-log-file [PATH]', 'PATH to APND log file (default is /var/log/apnd.log)') do |log| [:daemon_log_file] = log end opt.on('--daemon-timer [SECONDS]', 'Set APND queue refresh time to SECONDS (default is 30)') do |seconds| [:daemon_timer] = seconds.to_i end opt.on('--foreground', 'Run APND in foreground without daemonizing') do [:foreground] = true end opt.separator "\nHelp:\n" opt.on('--help', 'Show this message') do puts opt exit end end begin opts.parse! if .empty? puts opts exit end unless [:apple_cert] raise OptionParser::MissingArgument, "must specify --apple-cert" end rescue OptionParser::InvalidOption, OptionParser::MissingArgument puts "#{$0}: #{$!.}" puts "#{$0}: try '#{$0} --help' for more information" exit end APND.configure do |config| # Setup AppleConnection config.apple.cert = [:apple_cert] if [:apple_cert] config.apple.cert_pass = [:apple_cert_pass] if [:apple_cert_pass] config.apple.host = [:apple_host] if [:apple_host] config.apple.port = [:apple_port] if [:apple_port] # Setup Daemon config.daemon.bind = [:daemon_bind] if [:daemon_bind] config.daemon.port = [:daemon_port] if [:daemon_port] config.daemon.log_file = [:daemon_log_file] if [:daemon_log_file] config.daemon.timer = [:daemon_timer] if [:daemon_timer] end if APND.settings.apple.cert.nil? puts opts exit else unless [:foreground] Daemonize.daemonize(APND.settings.daemon.log_file, 'apnd') end APND::Daemon.run! end end |
.push(argv) ⇒ Object
Run apnd push
10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 |
# File 'lib/apnd/cli.rb', line 10 def self.push(argv) help = <<-HELP Usage: apnd push [OPTIONS] --token <token> HELP = {} opts = OptionParser.new do |opt| opt. = help opt.separator "Required Arguments:\n" opt.on('--token [TOKEN]', "Set Notification's iPhone token to TOKEN") do |token| [:token] = token end opt.separator "\nOptional Arguments:\n" opt.on('--alert [MESSAGE]', "Set Notification's alert to MESSAGE") do |alert| [:alert] = alert end opt.on('--sound [SOUND]', "Set Notification's sound to SOUND") do |sound| [:sound] = sound end opt.on('--badge [NUMBER]', "Set Notification's badge number to NUMBER") do |badge| [:badge] = badge.to_i end opt.on('--custom [JSON]', "Set Notification's custom data to JSON") do |custom| begin [:custom] = JSON.parse(custom) rescue JSON::ParserError => e puts "Invalid JSON: #{e}" exit -1 end end opt.on('--host [HOST]', "Send Notification to HOST, usually the one running APND (default is 'localhost')") do |host| [:host] = host end opt.on('--port [PORT]', 'Send Notification on PORT (default is 22195)') do |port| [:port] = port.to_i end opt.separator "\nHelp:\n" opt.on('--help', 'Show this message') do puts opt exit end end begin opts.parse! if .empty? puts opts exit end unless [:token] raise OptionParser::MissingArgument, "must specify --token" end rescue OptionParser::InvalidOption, OptionParser::MissingArgument puts "#{$0}: #{$!.}" puts "#{$0}: try '#{$0} --help' for more information" exit end # Configure Notification upstream host/port APND::Notification.upstream_host = .delete(:host) if [:host] APND::Notification.upstream_port = .delete(:port) if [:port] APND::Notification.create() end |