class APNS::Client
Attributes
auth_token[R]
uri[R]
Public Class Methods
new(uri, auth_key)
click to toggle source
# File lib/apns/client.rb, line 10 def initialize(uri, auth_key) @uri = URI.parse(uri) @auth_key = auth_key end
Public Instance Methods
notify(device, notification)
click to toggle source
Send a notification to a device
# File lib/apns/client.rb, line 18 def notify(device, notification) response = make_request(:notify, {:device => device, :notification => notification.to_hash}) NotificationResponse.new(response) end
register(device, label = nil)
click to toggle source
Register a device
# File lib/apns/client.rb, line 26 def register(device, label = nil) response = make_request(:register, {:device => device, :label => label}) response.success? end
Private Instance Methods
make_request(method, payload = {})
click to toggle source
Make an HTTP request
# File lib/apns/client.rb, line 35 def make_request(method, payload = {}) request = Net::HTTP::Post.new("/api/#{method}") request.body = payload.merge({:auth_key => @auth_key}).to_json request.add_field 'User-Agent', "APNS Ruby Client Library/#{APNS::VERSION}" connection = Net::HTTP.new(@uri.host, @uri.port) if @uri.is_a?(URI::HTTPS) connection.use_ssl = true connection.verify_mode = OpenSSL::SSL::VERIFY_NONE end result = connection.request(request) Response.new(result) end