jirapong-apn_on_rails 0.4.7 → 0.4.8
Sign up to get free protection for your applications and to get access to all the features.
@@ -1,6 +1,6 @@
|
|
1
|
-
# Represents the message you wish to send.
|
1
|
+
# Represents the message you wish to send.
|
2
2
|
# An APN::Notification belongs to an APN::Device.
|
3
|
-
#
|
3
|
+
#
|
4
4
|
# Example:
|
5
5
|
# apn = APN::Notification.new
|
6
6
|
# apn.badge = 5
|
@@ -8,22 +8,22 @@
|
|
8
8
|
# apn.alert = 'Hello!'
|
9
9
|
# apn.device = APN::Device.find(1)
|
10
10
|
# apn.save
|
11
|
-
#
|
11
|
+
#
|
12
12
|
# To deliver call the following method:
|
13
13
|
# APN::Notification.send_notifications
|
14
|
-
#
|
14
|
+
#
|
15
15
|
# As each APN::Notification is sent the <tt>sent_at</tt> column will be timestamped,
|
16
16
|
# so as to not be sent again.
|
17
17
|
class APN::Notification < APN::Base
|
18
18
|
include ::ActionView::Helpers::TextHelper
|
19
19
|
extend ::ActionView::Helpers::TextHelper
|
20
20
|
serialize :custom_properties
|
21
|
-
|
21
|
+
|
22
22
|
belongs_to :device, :class_name => 'APN::Device'
|
23
23
|
has_one :app, :class_name => 'APN::App', :through => :device
|
24
|
-
|
24
|
+
|
25
25
|
# Stores the text alert message you want to send to the device.
|
26
|
-
#
|
26
|
+
#
|
27
27
|
# If the message is over 150 characters long it will get truncated
|
28
28
|
# to 150 characters with a <tt>...</tt>
|
29
29
|
def alert=(message)
|
@@ -32,9 +32,9 @@ class APN::Notification < APN::Base
|
|
32
32
|
end
|
33
33
|
write_attribute('alert', message)
|
34
34
|
end
|
35
|
-
|
35
|
+
|
36
36
|
# Creates a Hash that will be the payload of an APN.
|
37
|
-
#
|
37
|
+
#
|
38
38
|
# Example:
|
39
39
|
# apn = APN::Notification.new
|
40
40
|
# apn.badge = 5
|
@@ -42,7 +42,7 @@ class APN::Notification < APN::Base
|
|
42
42
|
# apn.alert = 'Hello!'
|
43
43
|
# apn.apple_hash # => {"aps" => {"badge" => 5, "sound" => "my_sound.aiff", "alert" => "Hello!"}}
|
44
44
|
#
|
45
|
-
# Example 2:
|
45
|
+
# Example 2:
|
46
46
|
# apn = APN::Notification.new
|
47
47
|
# apn.badge = 0
|
48
48
|
# apn.sound = true
|
@@ -64,9 +64,9 @@ class APN::Notification < APN::Base
|
|
64
64
|
end
|
65
65
|
result
|
66
66
|
end
|
67
|
-
|
67
|
+
|
68
68
|
# Creates the JSON string required for an APN message.
|
69
|
-
#
|
69
|
+
#
|
70
70
|
# Example:
|
71
71
|
# apn = APN::Notification.new
|
72
72
|
# apn.badge = 5
|
@@ -76,18 +76,18 @@ class APN::Notification < APN::Base
|
|
76
76
|
def to_apple_json
|
77
77
|
self.apple_hash.to_json
|
78
78
|
end
|
79
|
-
|
79
|
+
|
80
80
|
# Creates the binary message needed to send to Apple.
|
81
81
|
def message_for_sending
|
82
82
|
json = self.to_apple_json
|
83
|
-
message = "\0\0 #{self.device.to_hexa}\0#{json.length.chr}#{json}"
|
83
|
+
message = "\0\0 #{self.device.to_hexa.encode('UTF-8')}\0#{json.length.chr.encode('UTF-8')}#{json.encode('UTF-8')}"
|
84
84
|
raise APN::Errors::ExceededMessageSizeError.new(message) if message.size.to_i > 256
|
85
85
|
message
|
86
86
|
end
|
87
|
-
|
87
|
+
|
88
88
|
def self.send_notifications
|
89
89
|
ActiveSupport::Deprecation.warn("The method APN::Notification.send_notifications is deprecated. Use APN::App.send_notifications instead.")
|
90
90
|
APN::App.send_notifications
|
91
91
|
end
|
92
|
-
|
93
|
-
end # APN::Notification
|
92
|
+
|
93
|
+
end # APN::Notification
|
data/lib/apn_on_rails/version.rb
CHANGED