Class: BMO::APNS::Client
- Inherits:
-
Object
- Object
- BMO::APNS::Client
- Defined in:
- lib/bmo/apns/client.rb
Overview
APNS Client Class
Defined Under Namespace
Classes: FeedbackTuple
Instance Attribute Summary collapse
-
#cert_pass ⇒ Object
APNS Client Class.
-
#cert_path ⇒ Object
APNS Client Class.
-
#feedback_host ⇒ Object
APNS Client Class.
-
#feedback_port ⇒ Object
APNS Client Class.
-
#gateway_host ⇒ Object
APNS Client Class.
-
#gateway_port ⇒ Object
APNS Client Class.
Instance Method Summary collapse
-
#feedback ⇒ Array[FeedbackTuple]
Get the Feedback from Apple.
-
#initialize(gateway_host, gateway_port, feedback_host, feedback_port, options = {}) ⇒ Client
constructor
The constructor of the Client object it will only use a ssl connection if you pass a cert_path option.
- #send_notification(notification) ⇒ Object
Constructor Details
#initialize(gateway_host, gateway_port, feedback_host, feedback_port, options = {}) ⇒ Client
The constructor of the Client object
it will only use a ssl connection if you pass a cert_path option
28 29 30 31 32 33 34 35 36 37 |
# File 'lib/bmo/apns/client.rb', line 28 def initialize(gateway_host, gateway_port, feedback_host, feedback_port, = {}) @gateway_host = gateway_host @gateway_port = gateway_port @feedback_host = feedback_host @feedback_port = feedback_port @cert_path = [:cert_path] @cert_pass = [:cert_pass] end |
Instance Attribute Details
#cert_pass ⇒ Object
APNS Client Class
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 |
# File 'lib/bmo/apns/client.rb', line 12 class Client attr_reader :cert_path, :cert_pass, :gateway_host, :gateway_port, :feedback_host, :feedback_port # The constructor of the Client object # it will only use a ssl connection if you pass a cert_path option # # @param gateway_host [String] # @param gateway_port [Integer] # @param feedback_host [String] # @param feedback_port [Integer] # # @options options [String] :cert_pass # @options options [String] :cert_path path to certificate file # def initialize(gateway_host, gateway_port, feedback_host, feedback_port, = {}) @gateway_host = gateway_host @gateway_port = gateway_port @feedback_host = feedback_host @feedback_port = feedback_port @cert_path = [:cert_path] @cert_pass = [:cert_pass] end # @param notification [Notification] the notification to send to Apple # def send_notification(notification) connection = APNS::Connection.new(@gateway_host, @gateway_port, @cert_path, @cert_pass) connection.connect do |socket| socket.write(notification.to_package) end end # Get the Feedback from Apple # # @return <Array[FeedbackTuple]> A feedback tuple contains the time # when Apple determined that the app no longer exists on the device, # and a the token of device token def feedback connection = APNS::Connection.new(@feedback_host, @feedback_port, @cert_path, @cert_pass) connection.connect do |socket| feedback_tuples = [] while (data = socket.read(38)) tuple = data.unpack('N1n1H*') feedback_tuples << FeedbackTuple.new(tuple[0], tuple[2]) end feedback_tuples end end private # Handle the Feedback Object # # @!attribute time [Time] Time when the device was notified # but didn't have the app installed # @!attribute token [String] The Token of the device notified wrongly class FeedbackTuple attr_reader :time, :token def initialize(, token) @time = Time.at() @token = token end end end |
#cert_path ⇒ Object
APNS Client Class
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 |
# File 'lib/bmo/apns/client.rb', line 12 class Client attr_reader :cert_path, :cert_pass, :gateway_host, :gateway_port, :feedback_host, :feedback_port # The constructor of the Client object # it will only use a ssl connection if you pass a cert_path option # # @param gateway_host [String] # @param gateway_port [Integer] # @param feedback_host [String] # @param feedback_port [Integer] # # @options options [String] :cert_pass # @options options [String] :cert_path path to certificate file # def initialize(gateway_host, gateway_port, feedback_host, feedback_port, = {}) @gateway_host = gateway_host @gateway_port = gateway_port @feedback_host = feedback_host @feedback_port = feedback_port @cert_path = [:cert_path] @cert_pass = [:cert_pass] end # @param notification [Notification] the notification to send to Apple # def send_notification(notification) connection = APNS::Connection.new(@gateway_host, @gateway_port, @cert_path, @cert_pass) connection.connect do |socket| socket.write(notification.to_package) end end # Get the Feedback from Apple # # @return <Array[FeedbackTuple]> A feedback tuple contains the time # when Apple determined that the app no longer exists on the device, # and a the token of device token def feedback connection = APNS::Connection.new(@feedback_host, @feedback_port, @cert_path, @cert_pass) connection.connect do |socket| feedback_tuples = [] while (data = socket.read(38)) tuple = data.unpack('N1n1H*') feedback_tuples << FeedbackTuple.new(tuple[0], tuple[2]) end feedback_tuples end end private # Handle the Feedback Object # # @!attribute time [Time] Time when the device was notified # but didn't have the app installed # @!attribute token [String] The Token of the device notified wrongly class FeedbackTuple attr_reader :time, :token def initialize(, token) @time = Time.at() @token = token end end end |
#feedback_host ⇒ Object
APNS Client Class
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 |
# File 'lib/bmo/apns/client.rb', line 12 class Client attr_reader :cert_path, :cert_pass, :gateway_host, :gateway_port, :feedback_host, :feedback_port # The constructor of the Client object # it will only use a ssl connection if you pass a cert_path option # # @param gateway_host [String] # @param gateway_port [Integer] # @param feedback_host [String] # @param feedback_port [Integer] # # @options options [String] :cert_pass # @options options [String] :cert_path path to certificate file # def initialize(gateway_host, gateway_port, feedback_host, feedback_port, = {}) @gateway_host = gateway_host @gateway_port = gateway_port @feedback_host = feedback_host @feedback_port = feedback_port @cert_path = [:cert_path] @cert_pass = [:cert_pass] end # @param notification [Notification] the notification to send to Apple # def send_notification(notification) connection = APNS::Connection.new(@gateway_host, @gateway_port, @cert_path, @cert_pass) connection.connect do |socket| socket.write(notification.to_package) end end # Get the Feedback from Apple # # @return <Array[FeedbackTuple]> A feedback tuple contains the time # when Apple determined that the app no longer exists on the device, # and a the token of device token def feedback connection = APNS::Connection.new(@feedback_host, @feedback_port, @cert_path, @cert_pass) connection.connect do |socket| feedback_tuples = [] while (data = socket.read(38)) tuple = data.unpack('N1n1H*') feedback_tuples << FeedbackTuple.new(tuple[0], tuple[2]) end feedback_tuples end end private # Handle the Feedback Object # # @!attribute time [Time] Time when the device was notified # but didn't have the app installed # @!attribute token [String] The Token of the device notified wrongly class FeedbackTuple attr_reader :time, :token def initialize(, token) @time = Time.at() @token = token end end end |
#feedback_port ⇒ Object
APNS Client Class
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 |
# File 'lib/bmo/apns/client.rb', line 12 class Client attr_reader :cert_path, :cert_pass, :gateway_host, :gateway_port, :feedback_host, :feedback_port # The constructor of the Client object # it will only use a ssl connection if you pass a cert_path option # # @param gateway_host [String] # @param gateway_port [Integer] # @param feedback_host [String] # @param feedback_port [Integer] # # @options options [String] :cert_pass # @options options [String] :cert_path path to certificate file # def initialize(gateway_host, gateway_port, feedback_host, feedback_port, = {}) @gateway_host = gateway_host @gateway_port = gateway_port @feedback_host = feedback_host @feedback_port = feedback_port @cert_path = [:cert_path] @cert_pass = [:cert_pass] end # @param notification [Notification] the notification to send to Apple # def send_notification(notification) connection = APNS::Connection.new(@gateway_host, @gateway_port, @cert_path, @cert_pass) connection.connect do |socket| socket.write(notification.to_package) end end # Get the Feedback from Apple # # @return <Array[FeedbackTuple]> A feedback tuple contains the time # when Apple determined that the app no longer exists on the device, # and a the token of device token def feedback connection = APNS::Connection.new(@feedback_host, @feedback_port, @cert_path, @cert_pass) connection.connect do |socket| feedback_tuples = [] while (data = socket.read(38)) tuple = data.unpack('N1n1H*') feedback_tuples << FeedbackTuple.new(tuple[0], tuple[2]) end feedback_tuples end end private # Handle the Feedback Object # # @!attribute time [Time] Time when the device was notified # but didn't have the app installed # @!attribute token [String] The Token of the device notified wrongly class FeedbackTuple attr_reader :time, :token def initialize(, token) @time = Time.at() @token = token end end end |
#gateway_host ⇒ Object
APNS Client Class
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 |
# File 'lib/bmo/apns/client.rb', line 12 class Client attr_reader :cert_path, :cert_pass, :gateway_host, :gateway_port, :feedback_host, :feedback_port # The constructor of the Client object # it will only use a ssl connection if you pass a cert_path option # # @param gateway_host [String] # @param gateway_port [Integer] # @param feedback_host [String] # @param feedback_port [Integer] # # @options options [String] :cert_pass # @options options [String] :cert_path path to certificate file # def initialize(gateway_host, gateway_port, feedback_host, feedback_port, = {}) @gateway_host = gateway_host @gateway_port = gateway_port @feedback_host = feedback_host @feedback_port = feedback_port @cert_path = [:cert_path] @cert_pass = [:cert_pass] end # @param notification [Notification] the notification to send to Apple # def send_notification(notification) connection = APNS::Connection.new(@gateway_host, @gateway_port, @cert_path, @cert_pass) connection.connect do |socket| socket.write(notification.to_package) end end # Get the Feedback from Apple # # @return <Array[FeedbackTuple]> A feedback tuple contains the time # when Apple determined that the app no longer exists on the device, # and a the token of device token def feedback connection = APNS::Connection.new(@feedback_host, @feedback_port, @cert_path, @cert_pass) connection.connect do |socket| feedback_tuples = [] while (data = socket.read(38)) tuple = data.unpack('N1n1H*') feedback_tuples << FeedbackTuple.new(tuple[0], tuple[2]) end feedback_tuples end end private # Handle the Feedback Object # # @!attribute time [Time] Time when the device was notified # but didn't have the app installed # @!attribute token [String] The Token of the device notified wrongly class FeedbackTuple attr_reader :time, :token def initialize(, token) @time = Time.at() @token = token end end end |
#gateway_port ⇒ Object
APNS Client Class
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 |
# File 'lib/bmo/apns/client.rb', line 12 class Client attr_reader :cert_path, :cert_pass, :gateway_host, :gateway_port, :feedback_host, :feedback_port # The constructor of the Client object # it will only use a ssl connection if you pass a cert_path option # # @param gateway_host [String] # @param gateway_port [Integer] # @param feedback_host [String] # @param feedback_port [Integer] # # @options options [String] :cert_pass # @options options [String] :cert_path path to certificate file # def initialize(gateway_host, gateway_port, feedback_host, feedback_port, = {}) @gateway_host = gateway_host @gateway_port = gateway_port @feedback_host = feedback_host @feedback_port = feedback_port @cert_path = [:cert_path] @cert_pass = [:cert_pass] end # @param notification [Notification] the notification to send to Apple # def send_notification(notification) connection = APNS::Connection.new(@gateway_host, @gateway_port, @cert_path, @cert_pass) connection.connect do |socket| socket.write(notification.to_package) end end # Get the Feedback from Apple # # @return <Array[FeedbackTuple]> A feedback tuple contains the time # when Apple determined that the app no longer exists on the device, # and a the token of device token def feedback connection = APNS::Connection.new(@feedback_host, @feedback_port, @cert_path, @cert_pass) connection.connect do |socket| feedback_tuples = [] while (data = socket.read(38)) tuple = data.unpack('N1n1H*') feedback_tuples << FeedbackTuple.new(tuple[0], tuple[2]) end feedback_tuples end end private # Handle the Feedback Object # # @!attribute time [Time] Time when the device was notified # but didn't have the app installed # @!attribute token [String] The Token of the device notified wrongly class FeedbackTuple attr_reader :time, :token def initialize(, token) @time = Time.at() @token = token end end end |
Instance Method Details
#feedback ⇒ Array[FeedbackTuple]
Get the Feedback from Apple
54 55 56 57 58 59 60 61 62 63 64 65 |
# File 'lib/bmo/apns/client.rb', line 54 def feedback connection = APNS::Connection.new(@feedback_host, @feedback_port, @cert_path, @cert_pass) connection.connect do |socket| feedback_tuples = [] while (data = socket.read(38)) tuple = data.unpack('N1n1H*') feedback_tuples << FeedbackTuple.new(tuple[0], tuple[2]) end feedback_tuples end end |
#send_notification(notification) ⇒ Object
41 42 43 44 45 46 47 |
# File 'lib/bmo/apns/client.rb', line 41 def send_notification(notification) connection = APNS::Connection.new(@gateway_host, @gateway_port, @cert_path, @cert_pass) connection.connect do |socket| socket.write(notification.to_package) end end |