Class: EventMachine::ApnManager::Client
- Inherits:
-
Object
- Object
- EventMachine::ApnManager::Client
- Defined in:
- lib/em_apn_manager/client.rb
Constant Summary collapse
- SANDBOX_GATEWAY =
"gateway.sandbox.push.apple.com"
- PRODUCTION_GATEWAY =
"gateway.push.apple.com"
- TEST_GATEWAY =
"127.0.0.1"
- 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.
-
#environment ⇒ Object
readonly
Returns the value of attribute environment.
-
#error_callback ⇒ Object
readonly
Returns the value of attribute error_callback.
-
#gateway ⇒ Object
readonly
Returns the value of attribute gateway.
-
#open_callback ⇒ Object
readonly
Returns the value of attribute open_callback.
-
#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
- #connected? ⇒ Boolean
- #deliver(notification) ⇒ Object
-
#initialize(options = {}) ⇒ Client
constructor
A new instance of Client.
- #log(notification) ⇒ Object
- #on_close(&block) ⇒ Object
- #on_error(&block) ⇒ Object
- #on_open(&block) ⇒ Object
Constructor Details
#initialize(options = {}) ⇒ Client
Returns a new instance of Client.
22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 |
# File 'lib/em_apn_manager/client.rb', line 22 def initialize( = {}) @cert = [:cert] @port = [:port] || PORT @environment = [:env] || "development" @gateway = [:gateway] @gateway ||= case @environment when "test" TEST_GATEWAY when "development" SANDBOX_GATEWAY when "production" PRODUCTION_GATEWAY else TEST_GATEWAY end @connection = nil end |
Instance Attribute Details
#cert ⇒ Object (readonly)
Returns the value of attribute cert.
13 14 15 |
# File 'lib/em_apn_manager/client.rb', line 13 def cert @cert end |
#close_callback ⇒ Object (readonly)
Returns the value of attribute close_callback.
13 14 15 |
# File 'lib/em_apn_manager/client.rb', line 13 def close_callback @close_callback end |
#connection ⇒ Object (readonly)
Returns the value of attribute connection.
13 14 15 |
# File 'lib/em_apn_manager/client.rb', line 13 def connection @connection end |
#environment ⇒ Object (readonly)
Returns the value of attribute environment.
13 14 15 |
# File 'lib/em_apn_manager/client.rb', line 13 def environment @environment end |
#error_callback ⇒ Object (readonly)
Returns the value of attribute error_callback.
13 14 15 |
# File 'lib/em_apn_manager/client.rb', line 13 def error_callback @error_callback end |
#gateway ⇒ Object (readonly)
Returns the value of attribute gateway.
13 14 15 |
# File 'lib/em_apn_manager/client.rb', line 13 def gateway @gateway end |
#open_callback ⇒ Object (readonly)
Returns the value of attribute open_callback.
13 14 15 |
# File 'lib/em_apn_manager/client.rb', line 13 def open_callback @open_callback end |
#port ⇒ Object (readonly)
Returns the value of attribute port.
13 14 15 |
# File 'lib/em_apn_manager/client.rb', line 13 def port @port end |
Class Method Details
.connect(options = {}) ⇒ Object
A convenience method for creating and connecting.
16 17 18 19 20 |
# File 'lib/em_apn_manager/client.rb', line 16 def self.connect( = {}) new().tap do |client| client.connect end end |
Instance Method Details
#connect ⇒ Object
40 41 42 |
# File 'lib/em_apn_manager/client.rb', line 40 def connect @connection = EM.connect(gateway, port, Connection, self) end |
#connected? ⇒ Boolean
44 45 46 |
# File 'lib/em_apn_manager/client.rb', line 44 def connected? !connection.nil? && !connection.disconnected? end |
#deliver(notification) ⇒ Object
48 49 50 51 52 53 54 55 56 |
# File 'lib/em_apn_manager/client.rb', line 48 def deliver(notification) if !connected? puts "No connection." return end notification.validate! log(notification) connection.send_data(notification.data) end |
#log(notification) ⇒ Object
70 71 72 |
# File 'lib/em_apn_manager/client.rb', line 70 def log(notification) EM::ApnManager.logger.info("TOKEN=#{notification.token} PAYLOAD=#{notification.payload.inspect}") end |
#on_close(&block) ⇒ Object
62 63 64 |
# File 'lib/em_apn_manager/client.rb', line 62 def on_close(&block) @close_callback = block end |
#on_error(&block) ⇒ Object
58 59 60 |
# File 'lib/em_apn_manager/client.rb', line 58 def on_error(&block) @error_callback = block end |
#on_open(&block) ⇒ Object
66 67 68 |
# File 'lib/em_apn_manager/client.rb', line 66 def on_open(&block) @open_callback = block end |