Class: Mameapns::Application
- Inherits:
-
Object
- Object
- Mameapns::Application
show all
- Includes:
- Options
- Defined in:
- lib/mameapns/application.rb
Instance Method Summary
collapse
Methods included from Options
included, #initialize, #to_hash, #to_json
Instance Method Details
#attempt_to_connect? ⇒ Boolean
To attempt to connect to apns server and close actually it used to check ssl cert files and ohter configurations.
raises:
ConnectionError: Unable to connect to apns. generaly socket error.
SSLError: Given invalid SSL Cert.
103
104
105
106
107
108
|
# File 'lib/mameapns/application.rb', line 103
def attempt_to_connect?
setup_session
@deliver_session.connect
@deliver_session.close
end
|
#deliver(notification) ⇒ Object
72
73
74
|
# File 'lib/mameapns/application.rb', line 72
def deliver(notification)
@deliver_session.push(notification)
end
|
#feedback_host ⇒ Object
22
23
24
25
26
27
28
|
# File 'lib/mameapns/application.rb', line 22
def feedback_host
@feedback_host ||= if develop
"feedback.sandbox.push.apple.com"
else
"feedback.push.apple.com"
end
end
|
#handle_delivery_error(notification, err) ⇒ Object
76
77
78
|
# File 'lib/mameapns/application.rb', line 76
def handle_delivery_error(notification, err)
@on_delivery_error.call(notification, err) if @on_delivery_error
end
|
#handle_exception(e) ⇒ Object
84
85
86
|
# File 'lib/mameapns/application.rb', line 84
def handle_exception(e)
@on_exception.call(e) if @on_exception
end
|
#handle_feedback(notification, err) ⇒ Object
80
81
82
|
# File 'lib/mameapns/application.rb', line 80
def handle_feedback(notification, err)
@on_feedback.call(err.device_token) if @on_feedback
end
|
#handle_sent(notification) ⇒ Object
88
89
90
|
# File 'lib/mameapns/application.rb', line 88
def handle_sent(notification)
@on_sent.call(notification) if @on_sent
end
|
#host ⇒ Object
14
15
16
17
18
19
20
|
# File 'lib/mameapns/application.rb', line 14
def host
@host ||= if develop
"gateway.sandbox.push.apple.com"
else
"gateway.push.apple.com"
end
end
|
#on_delivery_error(&block) ⇒ Object
92
93
94
|
# File 'lib/mameapns/application.rb', line 92
def on_delivery_error(&block)
@on_delivery_error = block
end
|
#on_exception(&block) ⇒ Object
117
118
119
|
# File 'lib/mameapns/application.rb', line 117
def on_exception(&block)
@on_exception = block
end
|
#setup_session ⇒ Object
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
|
# File 'lib/mameapns/application.rb', line 37
def setup_session
@deliver_session = Session::Deliver.new(
ssl_cert: ssl_cert,
ssl_cert_key: ssl_cert_key,
ssl_cert_pass: ssl_cert_pass,
host: host,
port: port
)
@feedback_session = Session::Feedback.new(
ssl_cert: ssl_cert,
ssl_cert_key: ssl_cert_key,
ssl_cert_pass: ssl_cert_pass,
host: feedback_host,
port: feedback_port
)
@deliver_session.on_sent(&method(:handle_sent))
@deliver_session.on_error(&method(:handle_delivery_error))
@deliver_session.on_exception(&method(:handle_exception))
@feedback_session.on_error(&method(:handle_feedback))
@feedback_session.on_exception(&method(:handle_exception))
end
|
#start ⇒ Object
30
31
32
33
34
35
|
# File 'lib/mameapns/application.rb', line 30
def start
setup_session
@deliver_session.start
@feedback_session.start
end
|
#stop ⇒ Object
62
63
64
65
|
# File 'lib/mameapns/application.rb', line 62
def stop
@deliver_session.stop
@feedback_session.stop
end
|
#wait_stop ⇒ Object
67
68
69
70
|
# File 'lib/mameapns/application.rb', line 67
def wait_stop
@deliver_session.wait_stop
@feedback_session.wait_stop
end
|