Class: APNS::Sender

Inherits:
Object
  • Object
show all
Defined in:
lib/apns/sender.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(params = {}) ⇒ Sender

Returns a new instance of Sender.



6
7
8
9
10
11
# File 'lib/apns/sender.rb', line 6

def initialize(params = {})
  @host = params[:host] || 'gateway.sandbox.push.apple.com'
  @port = params[:port] || 2195
  @pem = params[:pem] || raise("Path to your pem file required!")
  @pass = params[:pass]
end

Instance Attribute Details

#hostObject (readonly)

Returns the value of attribute host.



4
5
6
# File 'lib/apns/sender.rb', line 4

def host
  @host
end

#passObject (readonly)

Returns the value of attribute pass.



4
5
6
# File 'lib/apns/sender.rb', line 4

def pass
  @pass
end

#pemObject (readonly)

Returns the value of attribute pem.



4
5
6
# File 'lib/apns/sender.rb', line 4

def pem
  @pem
end

#portObject (readonly)

Returns the value of attribute port.



4
5
6
# File 'lib/apns/sender.rb', line 4

def port
  @port
end

Instance Method Details

#send_notifications(notifications) ⇒ Object



13
14
15
16
17
18
19
20
# File 'lib/apns/sender.rb', line 13

def send_notifications(notifications)
  packages = notifications.select(&:valid?).map { |n| Packager.new(n).package }
  return if packages.none?
  connection do |ssl|
    packages.each { |package| ssl.write(package) }
  end
  true
end