Class: Apns::Persistent::PushClient
- Defined in:
- lib/apns/persistent/push_client.rb
Class Method Summary collapse
- .gateway_uri(sandbox) ⇒ Object
- .message(token, alert, badge, sound, category, content_available, mutable_content, custom_payload, id, expiry, priority) ⇒ Object
- .push_once(certificate:, passphrase: nil, sandbox: true, token:, alert: nil, badge: nil, sound: nil, category: nil, content_available: true, mutable_content: false, custom_payload: nil, id: nil, expiry: nil, priority: nil) ⇒ Object
Instance Method Summary collapse
- #push(token:, alert: nil, badge: nil, sound: nil, category: nil, content_available: true, mutable_content: false, custom_payload: nil, id: nil, expiry: nil, priority: nil) ⇒ Object
- #register_error_handle ⇒ Object
Methods inherited from Client
Constructor Details
This class inherits a constructor from Apns::Persistent::Client
Class Method Details
.gateway_uri(sandbox) ⇒ Object
80 81 82 |
# File 'lib/apns/persistent/push_client.rb', line 80 def gateway_uri(sandbox) sandbox ? "apn://gateway.sandbox.push.apple.com:2195" : "apn://gateway.push.apple.com:2195" end |
.message(token, alert, badge, sound, category, content_available, mutable_content, custom_payload, id, expiry, priority) ⇒ Object
84 85 86 87 88 89 90 91 |
# File 'lib/apns/persistent/push_client.rb', line 84 def (token, alert, badge, sound, category, content_available, mutable_content, custom_payload, id, expiry, priority) data = [token_data(token), payload_data(custom_payload, alert, badge, sound, category, content_available, mutable_content), id_data(id), expiration_data(expiry), priority_data(priority)].compact.join [2, data.bytes.count, data].pack('cNa*') end |
.push_once(certificate:, passphrase: nil, sandbox: true, token:, alert: nil, badge: nil, sound: nil, category: nil, content_available: true, mutable_content: false, custom_payload: nil, id: nil, expiry: nil, priority: nil) ⇒ Object
6 7 8 9 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 |
# File 'lib/apns/persistent/push_client.rb', line 6 def self.push_once(certificate: , passphrase: nil, sandbox: true, token: , alert: nil, badge: nil, sound: nil, category: nil, content_available: true, mutable_content: false, custom_payload: nil, id: nil, expiry: nil, priority: nil) client = PushClient.new(certificate: certificate, passphrase: passphrase, sandbox: sandbox) client.open client.push(token: token, alert: alert, badge: badge, sound: sound, category: category, content_available: content_available, mutable_content: mutable_content, custom_payload: custom_payload, id: id, expiry: expiry, priority: priority) do |command, status, return_id| if block_given? yield(command, status, return_id) end end client.close end |
Instance Method Details
#push(token:, alert: nil, badge: nil, sound: nil, category: nil, content_available: true, mutable_content: false, custom_payload: nil, id: nil, expiry: nil, priority: nil) ⇒ Object
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 |
# File 'lib/apns/persistent/push_client.rb', line 43 def push(token: , alert: nil, badge: nil, sound: nil, category: nil, content_available: true, mutable_content: false, custom_payload: nil, id: nil, expiry: nil, priority: nil) raise 'please open' if closed? m = PushClient.(token, alert, badge, sound, category, content_available, mutable_content, custom_payload, id, expiry, priority) @connection.write(m) if block_given? && @connection.readable? if error = @connection.read(6) command, status, return_id = error.unpack('ccN') yield(command, status, return_id) @connection.reopen end end end |
#register_error_handle ⇒ Object
69 70 71 72 73 74 75 76 77 |
# File 'lib/apns/persistent/push_client.rb', line 69 def register_error_handle Thread.new do while error = @connection.read(6) command, status, id = error.unpack('ccN') yield(command, status, id) @connection.reopen end end end |