Class: Apnotic::Connection

Inherits:
Object
  • Object
show all
Defined in:
lib/apnotic/connection.rb

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(options = {}) ⇒ Connection



21
22
23
24
25
26
27
28
29
30
31
32
# File 'lib/apnotic/connection.rb', line 21

def initialize(options={})
  @uri       = URI.parse(options[:uri] || APPLE_PRODUCTION_SERVER_URI)
  @cert_path = options[:cert_path]
  @cert_pass = options[:cert_pass]

  @pipe_r, @pipe_w = Socket.pair(:UNIX, :STREAM, 0)
  @socket_thread   = nil
  @mutex           = Mutex.new

  raise "URI needs to be a HTTPS address" if uri.scheme != 'https'
  raise "Cert file not found: #{@cert_path}" unless @cert_path && File.exist?(@cert_path)
end

Instance Attribute Details

#cert_pathObject (readonly)

Returns the value of attribute cert_path.



12
13
14
# File 'lib/apnotic/connection.rb', line 12

def cert_path
  @cert_path
end

#uriObject (readonly)

Returns the value of attribute uri.



12
13
14
# File 'lib/apnotic/connection.rb', line 12

def uri
  @uri
end

Class Method Details

.development(options = {}) ⇒ Object



15
16
17
18
# File 'lib/apnotic/connection.rb', line 15

def development(options={})
  options.merge!(uri: APPLE_DEVELOPMENT_SERVER_URI)
  new(options)
end

Instance Method Details

#closeObject



40
41
42
43
44
45
46
47
48
# File 'lib/apnotic/connection.rb', line 40

def close
  exit_thread(@socket_thread)

  @ssl_context   = nil
  @h2            = nil
  @pipe_r        = nil
  @pipe_w        = nil
  @socket_thread = nil
end

#push(notification, options = {}) ⇒ Object



34
35
36
37
38
# File 'lib/apnotic/connection.rb', line 34

def push(notification, options={})
  open

  new_stream.push(notification, options)
end