Class: Racoon::Client

Inherits:
Object
  • Object
show all
Defined in:
lib/racoon/client.rb

Direct Known Subclasses

FeedbackClient

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(pem, host = 'gateway.push.apple.com', port = 2195, pass = nil) ⇒ Client

Returns a new instance of Client.



8
9
10
# File 'lib/racoon/client.rb', line 8

def initialize(pem, host = 'gateway.push.apple.com', port = 2195, pass = nil)
  @pem, @host, @port, @password = pem, host, port, pass
end

Instance Attribute Details

#hostObject

Returns the value of attribute host.



6
7
8
# File 'lib/racoon/client.rb', line 6

def host
  @host
end

#passwordObject

Returns the value of attribute password.



6
7
8
# File 'lib/racoon/client.rb', line 6

def password
  @password
end

#pemObject

Returns the value of attribute pem.



6
7
8
# File 'lib/racoon/client.rb', line 6

def pem
  @pem
end

#portObject

Returns the value of attribute port.



6
7
8
# File 'lib/racoon/client.rb', line 6

def port
  @port
end

Instance Method Details

#connect!Object



12
13
14
15
16
17
18
19
20
21
22
23
24
# File 'lib/racoon/client.rb', line 12

def connect!
  raise "Your certificate is not set." unless self.pem

  @context      = OpenSSL::SSL::SSLContext.new
  @context.cert = OpenSSL::X509::Certificate.new(self.pem)
  @context.key  = OpenSSL::PKey::RSA.new(self.pem, self.password)

  @sock         = TCPSocket.new(self.host, self.port.to_i)
  @ssl          = OpenSSL::SSL::SSLSocket.new(@sock, @context)
  @ssl.connect

  return @sock, @ssl
end

#connected?Boolean

Returns:

  • (Boolean)


40
41
42
# File 'lib/racoon/client.rb', line 40

def connected?
  @ssl
end

#disconnect!Object



26
27
28
29
30
31
# File 'lib/racoon/client.rb', line 26

def disconnect!
  @ssl.close
  @sock.close
  @ssl = nil
  @sock = nil
end

#write(notification) ⇒ Object



33
34
35
36
37
38
# File 'lib/racoon/client.rb', line 33

def write(notification)
  if host.include? "sandbox"
    Config.logger.debug "#{Time.now} [#{host}:#{port}] Device: #{notification.device_token.unpack('H*')} sending #{notification.json_payload}"
  end
  @ssl.write(notification.to_bytes)
end