Module: EM::APNS

Defined in:
lib/em-apns/error.rb,
lib/em-apns/server.rb,
lib/em-apns/version.rb,
lib/em-apns/connection.rb,
lib/em-apns/server_runner.rb,
lib/em-apns/connection_pool.rb,
lib/em-apns.rb

Defined Under Namespace

Modules: Server Classes: Connection, ConnectionPool, Error, ServerRunner

Constant Summary collapse

VERSION =
"0.1.1"

Class Attribute Summary collapse

Class Method Summary collapse

Class Attribute Details

.certObject

Returns the value of attribute cert.



16
17
18
# File 'lib/em-apns.rb', line 16

def cert
  @cert
end

.envObject

Returns the value of attribute env.



16
17
18
# File 'lib/em-apns.rb', line 16

def env
  @env
end

.hostObject

Returns the value of attribute host.



16
17
18
# File 'lib/em-apns.rb', line 16

def host
  @host
end

.keyObject

Returns the value of attribute key.



16
17
18
# File 'lib/em-apns.rb', line 16

def key
  @key
end

.loggerObject



22
23
24
# File 'lib/em-apns.rb', line 22

def logger
  @logger ||= Logger.new(STDOUT)
end

.poolObject

Returns the value of attribute pool.



16
17
18
# File 'lib/em-apns.rb', line 16

def pool
  @pool
end

.sockObject



18
19
20
# File 'lib/em-apns.rb', line 18

def sock
  @sock ||= (defined?(Rails) && Rails.respond_to?(:root) ? File.join(Rails.root, 'tmp/sockets', "em-apns-#{Rails.env}.sock") : nil)
end

Class Method Details

.config(options) ⇒ Object



40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
# File 'lib/em-apns.rb', line 40

def config options
  raise 'App root folder are not defined' unless options[:root]
  if options[:config]
    configurations = YAML.load_file options['config']
  else
    config_file = File.join(options[:root],"config/em-apns.yml")
    configurations = YAML.load_file(config_file)
  end
  @env = options[:environment] || 'development'
  @sock = File.join(options[:root], "tmp/sockets/em-apns-#{@env}.sock")
  @pool = configurations['pool']
  @key = configurations['key']
  @cert = configurations['cert']
  raise 'No key or certficate file' unless @key && @cert
  @host = case @env
  when 'development'
    "gateway.sandbox.push.apple.com"
  when 'production'
    "gateway.push.apple.com"
  else
    "localhost"
  end
end

.send_notification(*args) ⇒ Object



26
27
28
# File 'lib/em-apns.rb', line 26

def send_notification(*args)
  send_notifications([Notification.new(*args)])
end

.send_notifications(notifications) ⇒ Object



30
31
32
33
34
35
36
37
38
# File 'lib/em-apns.rb', line 30

def send_notifications(notifications)
  UNIXSocket.open(sock) do |socket|
    notifications.each do |n|
      socket.puts(n.data)
    end
  end
rescue => e
  logger.error(e)
end