Class: APNS::Service

Inherits:
Object
  • Object
show all
Includes:
ActiveModel::Model
Defined in:
lib/mercurius/apns/service.rb

Constant Summary collapse

MAX_NUMBER_OF_RETRIES =
3

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initializeService

Returns a new instance of Service.



10
11
12
13
14
15
16
17
# File 'lib/mercurius/apns/service.rb', line 10

def initialize(*)
  super
  @host ||= APNS.host
  @port ||= APNS.port
  @pem ||= APNS.pem
  @connection ||= APNS::Connection.new(@host, @port, @pem)
  @attempts = 0
end

Instance Attribute Details

#attemptsObject (readonly)

Returns the value of attribute attempts.



8
9
10
# File 'lib/mercurius/apns/service.rb', line 8

def attempts
  @attempts
end

#connectionObject

Returns the value of attribute connection.



7
8
9
# File 'lib/mercurius/apns/service.rb', line 7

def connection
  @connection
end

#hostObject

Returns the value of attribute host.



7
8
9
# File 'lib/mercurius/apns/service.rb', line 7

def host
  @host
end

#pemObject

Returns the value of attribute pem.



7
8
9
# File 'lib/mercurius/apns/service.rb', line 7

def pem
  @pem
end

#portObject

Returns the value of attribute port.



7
8
9
# File 'lib/mercurius/apns/service.rb', line 7

def port
  @port
end

Instance Method Details

#deliver(notification, *device_tokens) ⇒ Object



26
27
28
29
30
31
32
33
# File 'lib/mercurius/apns/service.rb', line 26

def deliver(notification, *device_tokens)
  device_tokens = Array(device_tokens).flatten
  with_connection do |connection|
    device_tokens.each do |device_token|
      connection.write notification.pack(device_token)
    end
  end
end

#persist(&block) ⇒ Object



19
20
21
22
23
24
# File 'lib/mercurius/apns/service.rb', line 19

def persist(&block)
  @_persistent = true
  yield
  @_persistent = false
  connection.close
end