Class: Push0r::ApnsService
- Defined in:
- lib/push0r/APNS/ApnsService.rb
Overview
ApnsService is a Service implementation to push notifications to iOS and OSX users using the Apple Push Notification Service.
Instance Method Summary collapse
- #can_send?(message) ⇒ Boolean
- #end_push ⇒ Object
-
#get_feedback ⇒ Array<String>
Calls the APNS feedback service and returns an array of expired push tokens.
- #init_push ⇒ Object
-
#initialize(certificate_data, environment = ApnsEnvironment::PRODUCTION) ⇒ ApnsService
constructor
Returns a new ApnsService instance.
- #send(message) ⇒ Object
Constructor Details
#initialize(certificate_data, environment = ApnsEnvironment::PRODUCTION) ⇒ ApnsService
Returns a new ApnsService instance
33 34 35 36 37 38 39 |
# File 'lib/push0r/APNS/ApnsService.rb', line 33 def initialize(certificate_data, environment = ApnsEnvironment::PRODUCTION) @certificate_data = certificate_data @environment = environment @ssl = nil @sock = nil @messages = [] end |
Instance Method Details
#can_send?(message) ⇒ Boolean
42 43 44 |
# File 'lib/push0r/APNS/ApnsService.rb', line 42 def can_send?() return .is_a?(ApnsPushMessage) && .environment == @environment end |
#end_push ⇒ Object
57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 |
# File 'lib/push0r/APNS/ApnsService.rb', line 57 def end_push = [] result = false begin begin setup_ssl(true) rescue SocketError => e puts "Error: #{e}" break end (result, , error_code) = unless result << FailedMessage.new(error_code, [.receiver_token], ) (.identifier) result = true if @messages.empty? end end until result close_ssl @messages = [] ## reset return [, []] end |
#get_feedback ⇒ Array<String>
Calls the APNS feedback service and returns an array of expired push tokens
83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 |
# File 'lib/push0r/APNS/ApnsService.rb', line 83 def get_feedback tokens = [] begin setup_ssl(true) rescue SocketError => e puts "Error: #{e}" return tokens end if IO.select([@ssl], nil, nil, 1) while (line = @ssl.read(38)) f = line.unpack('N1n1H64') time = Time.at(f[0]) token = f[2].scan(/.{8}/).join(' ') tokens << token end end close_ssl return tokens end |
#init_push ⇒ Object
52 53 54 |
# File 'lib/push0r/APNS/ApnsService.rb', line 52 def init_push # not used for apns end |
#send(message) ⇒ Object
47 48 49 |
# File 'lib/push0r/APNS/ApnsService.rb', line 47 def send() @messages << end |