apple_shove 1.1.4 → 2.0.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- data/README.md +13 -3
- data/lib/apple_shove/apns/error_response_packet.rb +32 -0
- data/lib/apple_shove/apple_shove.rb +2 -5
- data/lib/apple_shove/notification.rb +18 -4
- data/lib/apple_shove/version.rb +1 -1
- metadata +5 -4
data/README.md
CHANGED
@@ -60,12 +60,18 @@ Sending a notification request looks like this:
|
|
60
60
|
token = '[device token string]'
|
61
61
|
payload = { mdm: '[push magic string]' } # this can also be an app notification
|
62
62
|
|
63
|
-
AppleShove.notify
|
63
|
+
AppleShove.notify p12: apns_p12,
|
64
|
+
device_token: token,
|
65
|
+
payload: payload,
|
66
|
+
expiration_date: Time.now + 60*60, # optional expiration timestamp. defaults to one year in the future.
|
67
|
+
priority: 5 # optional. defaults to 10.
|
64
68
|
|
65
69
|
Need it to be a sandbox notification?
|
66
70
|
|
67
|
-
|
68
|
-
|
71
|
+
AppleShove.notify p12: apns_p12,
|
72
|
+
device_token: token,
|
73
|
+
payload: payload,
|
74
|
+
sandbox: true
|
69
75
|
|
70
76
|
### Checking the Feedback Service
|
71
77
|
|
@@ -73,6 +79,10 @@ We also have a feedback mechanism in place:
|
|
73
79
|
|
74
80
|
tokens_array = AppleShove.feedback_tokens(apns_p12)
|
75
81
|
|
82
|
+
# or, for the sandboxed feedback service:
|
83
|
+
|
84
|
+
tokens_array = AppleShove.feedback_tokens(apns_p12, true)
|
85
|
+
|
76
86
|
### Running the Service
|
77
87
|
|
78
88
|
# bundle exec rake -T
|
@@ -0,0 +1,32 @@
|
|
1
|
+
module AppleShove
|
2
|
+
module APNS
|
3
|
+
class ErrorResponsePacket
|
4
|
+
|
5
|
+
attr_reader :status, :identifier
|
6
|
+
|
7
|
+
STATUS_MESSAGES = { 0 => 'No errors encountered',
|
8
|
+
1 => 'Processing error',
|
9
|
+
2 => 'Missing device token',
|
10
|
+
3 => 'Missing topic',
|
11
|
+
4 => 'Missing payload',
|
12
|
+
5 => 'Invalid token size',
|
13
|
+
6 => 'Invalid topic size',
|
14
|
+
7 => 'Invalid payload size',
|
15
|
+
8 => 'Invalid token',
|
16
|
+
10 => 'Shotdown',
|
17
|
+
255 => 'None (unknown)' }
|
18
|
+
|
19
|
+
def initialize(binary_response)
|
20
|
+
response = binary_response.unpack('CCA4')
|
21
|
+
|
22
|
+
@status = response[1]
|
23
|
+
@identifier = response[2]
|
24
|
+
end
|
25
|
+
|
26
|
+
def status_message
|
27
|
+
STATUS_MESSAGES[@status]
|
28
|
+
end
|
29
|
+
|
30
|
+
end
|
31
|
+
end
|
32
|
+
end
|
@@ -1,10 +1,7 @@
|
|
1
1
|
module AppleShove
|
2
2
|
|
3
|
-
def self.notify(
|
4
|
-
notification
|
5
|
-
device_token: device_token,
|
6
|
-
payload: payload,
|
7
|
-
sandbox: sandbox
|
3
|
+
def self.notify(params = {})
|
4
|
+
notification = Notification.new params
|
8
5
|
|
9
6
|
queue = NotificationQueue.new(CONFIG[:redis_key])
|
10
7
|
queue.add(notification)
|
@@ -1,10 +1,18 @@
|
|
1
1
|
module AppleShove
|
2
2
|
class Notification
|
3
3
|
|
4
|
-
attr_accessor :p12, :sandbox, :device_token, :payload
|
4
|
+
attr_accessor :p12, :sandbox, :device_token, :payload, :expiration_date, :priority
|
5
5
|
|
6
6
|
def initialize(attributes = {})
|
7
|
-
|
7
|
+
[:p12, :device_token, :payload].each do |req_attr|
|
8
|
+
raise "#{req_attr} must be specified" unless attributes.keys.collect { |k| k.to_s }.include? req_attr.to_s
|
9
|
+
end
|
10
|
+
|
11
|
+
attributes.each { |k, v| self.send("#{k}=", v) }
|
12
|
+
|
13
|
+
@sandbox = false if @sandbox.nil?
|
14
|
+
@expiration_date ||= Time.now + 60*60*24*365
|
15
|
+
@priority ||= 10
|
8
16
|
end
|
9
17
|
|
10
18
|
def self.parse(json)
|
@@ -20,8 +28,14 @@ module AppleShove
|
|
20
28
|
# Apple APNS format
|
21
29
|
def binary_message
|
22
30
|
payload_json = @payload.to_json
|
23
|
-
|
24
|
-
|
31
|
+
|
32
|
+
frame = [ [ 1, 32, @device_token ].pack('CnH64'),
|
33
|
+
[ 2, payload_json.length, payload_json ].pack('Cna*'),
|
34
|
+
[ 3, 4, '' ].pack('CnA4'),
|
35
|
+
[ 4, 4, @expiration_date.to_i ].pack('CnN'),
|
36
|
+
[ 5, 1, @priority ].pack('CnC') ].join
|
37
|
+
|
38
|
+
[ 2, frame.length, frame ].pack('CNa*')
|
25
39
|
end
|
26
40
|
|
27
41
|
private
|
data/lib/apple_shove/version.rb
CHANGED
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: apple_shove
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version:
|
4
|
+
version: 2.0.0
|
5
5
|
prerelease:
|
6
6
|
platform: ruby
|
7
7
|
authors:
|
@@ -9,7 +9,7 @@ authors:
|
|
9
9
|
autorequire:
|
10
10
|
bindir: bin
|
11
11
|
cert_chain: []
|
12
|
-
date: 2013-
|
12
|
+
date: 2013-09-19 00:00:00.000000000 Z
|
13
13
|
dependencies:
|
14
14
|
- !ruby/object:Gem::Dependency
|
15
15
|
name: bundler
|
@@ -123,6 +123,7 @@ files:
|
|
123
123
|
- apple_shove.gemspec
|
124
124
|
- lib/apple_shove.rb
|
125
125
|
- lib/apple_shove/apns/connection.rb
|
126
|
+
- lib/apple_shove/apns/error_response_packet.rb
|
126
127
|
- lib/apple_shove/apns/feedback_connection.rb
|
127
128
|
- lib/apple_shove/apns/notify_connection.rb
|
128
129
|
- lib/apple_shove/apple_shove.rb
|
@@ -156,7 +157,7 @@ required_ruby_version: !ruby/object:Gem::Requirement
|
|
156
157
|
version: '0'
|
157
158
|
segments:
|
158
159
|
- 0
|
159
|
-
hash:
|
160
|
+
hash: 144914022133974576
|
160
161
|
required_rubygems_version: !ruby/object:Gem::Requirement
|
161
162
|
none: false
|
162
163
|
requirements:
|
@@ -165,7 +166,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
165
166
|
version: '0'
|
166
167
|
segments:
|
167
168
|
- 0
|
168
|
-
hash:
|
169
|
+
hash: 144914022133974576
|
169
170
|
requirements: []
|
170
171
|
rubyforge_project:
|
171
172
|
rubygems_version: 1.8.24
|