Class: Pushofy::ApplePush

Inherits:
Object
  • Object
show all
Defined in:
lib/pushofy/applepush.rb

Instance Method Summary collapse

Constructor Details

#initialize(payload_hash, settings) ⇒ ApplePush

Returns a new instance of ApplePush.



9
10
11
12
13
# File 'lib/pushofy/applepush.rb', line 9

def initialize(payload_hash, settings)
  @deviceTokenHex = payload_hash["device"]
  @payload_hash = payload_hash.delete('device')
  @settings = settings
end

Instance Method Details

#feedbackObject



27
28
29
30
31
32
33
34
35
36
37
38
39
# File 'lib/pushofy/applepush.rb', line 27

def feedback
  host = 'feedback.sandbox.push.apple.com'
  path =  Dir.pwd + '/app/controllers/CertificateName.pem'
  ssl_client = Pushofy::ConnectionToAppleServer::ssl_connect(host, 2196, path)
  ssl_client.connect
  apns_feedback = []
  while message = ssl_client.gets
    timestamp, _token_size, token = message.unpack('N1n1H*')
    apns_feedback << [Time.at(timestamp), token]
  end
  ssl.close
  sock.close
end

#pushObject



14
15
16
17
18
19
20
21
22
23
24
25
# File 'lib/pushofy/applepush.rb', line 14

def push
  path = @cert_name
  ssl_client = Pushofy::ConnectionToAppleServer::ssl_connect(@settings[:host], @settings[:port], @settings[:password], @settings[:cert])
  ssl_client.connect
  device = [@deviceTokenHex]
  device_token_binary = device.pack('H*')
  pt = device_token_binary
  pm = @payload_hash.to_json
  message = [0, 0, 32, pt, 0, pm.size, pm].pack('ccca*cca*')
  ssl_client.write(message)
  ssl_client.flush
end