Class: EventMachine::APN::Client
- Inherits:
-
Object
- Object
- EventMachine::APN::Client
- Defined in:
- lib/em-apn/client.rb
Constant Summary collapse
- SANDBOX_GATEWAY =
"gateway.sandbox.push.apple.com"
- PRODUCTION_GATEWAY =
"gateway.push.apple.com"
- PORT =
2195
Instance Attribute Summary collapse
-
#cert ⇒ Object
readonly
Returns the value of attribute cert.
-
#close_callback ⇒ Object
readonly
Returns the value of attribute close_callback.
-
#connection ⇒ Object
readonly
Returns the value of attribute connection.
-
#error_callback ⇒ Object
readonly
Returns the value of attribute error_callback.
-
#gateway ⇒ Object
readonly
Returns the value of attribute gateway.
-
#key ⇒ Object
readonly
Returns the value of attribute key.
-
#port ⇒ Object
readonly
Returns the value of attribute port.
Class Method Summary collapse
-
.connect(options = {}) ⇒ Object
A convenience method for creating and connecting.
Instance Method Summary collapse
- #connect ⇒ Object
- #deliver(notification) ⇒ Object
-
#initialize(options = {}) ⇒ Client
constructor
A new instance of Client.
- #log(notification) ⇒ Object
- #on_close(&block) ⇒ Object
- #on_error(&block) ⇒ Object
Constructor Details
#initialize(options = {}) ⇒ Client
Returns a new instance of Client.
19 20 21 22 23 24 25 26 27 28 |
# File 'lib/em-apn/client.rb', line 19 def initialize( = {}) @key = [:key] || ENV["APN_KEY"] @cert = [:cert] || ENV["APN_CERT"] @port = [:port] || PORT @gateway = [:gateway] || ENV["APN_GATEWAY"] @gateway ||= (ENV["APN_ENV"] == "production") ? PRODUCTION_GATEWAY : SANDBOX_GATEWAY @connection = nil end |
Instance Attribute Details
#cert ⇒ Object (readonly)
Returns the value of attribute cert.
10 11 12 |
# File 'lib/em-apn/client.rb', line 10 def cert @cert end |
#close_callback ⇒ Object (readonly)
Returns the value of attribute close_callback.
10 11 12 |
# File 'lib/em-apn/client.rb', line 10 def close_callback @close_callback end |
#connection ⇒ Object (readonly)
Returns the value of attribute connection.
10 11 12 |
# File 'lib/em-apn/client.rb', line 10 def connection @connection end |
#error_callback ⇒ Object (readonly)
Returns the value of attribute error_callback.
10 11 12 |
# File 'lib/em-apn/client.rb', line 10 def error_callback @error_callback end |
#gateway ⇒ Object (readonly)
Returns the value of attribute gateway.
10 11 12 |
# File 'lib/em-apn/client.rb', line 10 def gateway @gateway end |
#key ⇒ Object (readonly)
Returns the value of attribute key.
10 11 12 |
# File 'lib/em-apn/client.rb', line 10 def key @key end |
#port ⇒ Object (readonly)
Returns the value of attribute port.
10 11 12 |
# File 'lib/em-apn/client.rb', line 10 def port @port end |
Class Method Details
.connect(options = {}) ⇒ Object
A convenience method for creating and connecting.
13 14 15 16 17 |
# File 'lib/em-apn/client.rb', line 13 def self.connect( = {}) new().tap do |client| client.connect end end |
Instance Method Details
#connect ⇒ Object
30 31 32 |
# File 'lib/em-apn/client.rb', line 30 def connect @connection = EM.connect(gateway, port, Connection, self) end |
#deliver(notification) ⇒ Object
34 35 36 37 38 |
# File 'lib/em-apn/client.rb', line 34 def deliver(notification) connect if connection.nil? || connection.disconnected? log(notification) connection.send_data(notification.data) end |
#log(notification) ⇒ Object
48 49 50 |
# File 'lib/em-apn/client.rb', line 48 def log(notification) EM::APN.logger.info("TOKEN=#{notification.token} ALERT=#{notification.alert}") end |
#on_close(&block) ⇒ Object
44 45 46 |
# File 'lib/em-apn/client.rb', line 44 def on_close(&block) @close_callback = block end |
#on_error(&block) ⇒ Object
40 41 42 |
# File 'lib/em-apn/client.rb', line 40 def on_error(&block) @error_callback = block end |