imobile 0.0.6 → 0.0.7
Sign up to get free protection for your applications and to get access to all the features.
- data/CHANGELOG +2 -0
- data/Manifest +1 -1
- data/README.textile +37 -0
- data/imobile.gemspec +5 -5
- data/lib/imobile/push_notification.rb +52 -6
- metadata +5 -5
- data/README +0 -6
data/CHANGELOG
CHANGED
data/Manifest
CHANGED
data/README.textile
ADDED
@@ -0,0 +1,37 @@
|
|
1
|
+
h1. Imobile
|
2
|
+
|
3
|
+
This gem/Rails plugin contains common code for powering iPhone applications. It
|
4
|
+
is particularly suitable as a server-side partner to the ZergSupport toolkit,
|
5
|
+
also available on Github under the MIT license at
|
6
|
+
http://github.com/costan/zergsupport
|
7
|
+
|
8
|
+
h2. Features
|
9
|
+
|
10
|
+
* <b>In-App Purchase</b> receipts verification - imobile can verify a StoreKit
|
11
|
+
receipt with Apple's servers. Apple's response is parsed into a Ruby-friendly
|
12
|
+
hash. See Imobile.validate_receipt in validate_receipt.rb
|
13
|
+
|
14
|
+
* <b>Push Notifications</b> - imobile supports both pushing notifications and
|
15
|
+
receiving feedback from Apple's servers. imobile can use the .p12 certificates
|
16
|
+
exported by Keychain directly, and it knows to talk to both sandbox and
|
17
|
+
production servers. imobile can send notifications in batch mode, ideal for
|
18
|
+
daemons and Cron jobs. See Imobile.push_notifications and Imobile.push_feedback
|
19
|
+
in push_notification.rb
|
20
|
+
|
21
|
+
* ZergSupport's CryptoSupport - imobile can validate the application fingerprint
|
22
|
+
generated by ZergSupport's CryptoSupport. Useful to know who's pirating your
|
23
|
+
applications. See Imobile.crypto_app_fprint in crypto_app_fprint.rb
|
24
|
+
|
25
|
+
* Production-friendly - imobile has great automated test coverage and all
|
26
|
+
methods are reasonably well document. The code is placed under the MIT license.
|
27
|
+
|
28
|
+
h2. ZergSupport
|
29
|
+
|
30
|
+
Some of imobile's functionality was designed specifically for use with the
|
31
|
+
ZergSupport iPhone application toolkit. The toolkit is available under the MIT
|
32
|
+
license at http://github.com/costan/zergsupport
|
33
|
+
|
34
|
+
h2. Contributions
|
35
|
+
|
36
|
+
Please don't hesitate to fork the project and send pull requests.
|
37
|
+
|
data/imobile.gemspec
CHANGED
@@ -2,17 +2,17 @@
|
|
2
2
|
|
3
3
|
Gem::Specification.new do |s|
|
4
4
|
s.name = %q{imobile}
|
5
|
-
s.version = "0.0.
|
5
|
+
s.version = "0.0.7"
|
6
6
|
|
7
7
|
s.required_rubygems_version = Gem::Requirement.new(">= 1.2") if s.respond_to? :required_rubygems_version=
|
8
8
|
s.authors = ["Victor Costan"]
|
9
|
-
s.date = %q{2009-07-
|
9
|
+
s.date = %q{2009-07-28}
|
10
10
|
s.description = %q{Library for servers backing iPhone applications.}
|
11
11
|
s.email = %q{victor@zergling.net}
|
12
|
-
s.extra_rdoc_files = ["CHANGELOG", "lib/imobile/crypto_app_fprint.rb", "lib/imobile/push_notification.rb", "lib/imobile/validate_receipt.rb", "lib/imobile.rb", "LICENSE", "README"]
|
13
|
-
s.files = ["CHANGELOG", "imobile.gemspec", "lib/imobile/crypto_app_fprint.rb", "lib/imobile/push_notification.rb", "lib/imobile/validate_receipt.rb", "lib/imobile.rb", "LICENSE", "Manifest", "Rakefile", "README", "test/crypto_app_fprint_test.rb", "test/push_notification_test.rb", "test/validate_receipt_test.rb", "testdata/apns_developer.p12", "testdata/apns_production.p12", "testdata/device_attributes.yml", "testdata/encoded_notification", "testdata/forged_sandbox_receipt", "testdata/sandbox_push_token", "testdata/sandbox_push_token.bin", "testdata/valid_sandbox_receipt"]
|
12
|
+
s.extra_rdoc_files = ["CHANGELOG", "lib/imobile/crypto_app_fprint.rb", "lib/imobile/push_notification.rb", "lib/imobile/validate_receipt.rb", "lib/imobile.rb", "LICENSE", "README.textile"]
|
13
|
+
s.files = ["CHANGELOG", "imobile.gemspec", "lib/imobile/crypto_app_fprint.rb", "lib/imobile/push_notification.rb", "lib/imobile/validate_receipt.rb", "lib/imobile.rb", "LICENSE", "Manifest", "Rakefile", "README.textile", "test/crypto_app_fprint_test.rb", "test/push_notification_test.rb", "test/validate_receipt_test.rb", "testdata/apns_developer.p12", "testdata/apns_production.p12", "testdata/device_attributes.yml", "testdata/encoded_notification", "testdata/forged_sandbox_receipt", "testdata/sandbox_push_token", "testdata/sandbox_push_token.bin", "testdata/valid_sandbox_receipt"]
|
14
14
|
s.homepage = %q{http://github.com/costan/imobile}
|
15
|
-
s.rdoc_options = ["--line-numbers", "--inline-source", "--title", "Imobile", "--main", "README"]
|
15
|
+
s.rdoc_options = ["--line-numbers", "--inline-source", "--title", "Imobile", "--main", "README.textile"]
|
16
16
|
s.require_paths = ["lib"]
|
17
17
|
s.rubyforge_project = %q{zerglings}
|
18
18
|
s.rubygems_version = %q{1.3.5}
|
@@ -51,7 +51,7 @@ end
|
|
51
51
|
# Reads the available feedback from Apple's Push Notification service.
|
52
52
|
#
|
53
53
|
# Args:
|
54
|
-
#
|
54
|
+
# path_or_certificate:: see Imobile.push_notification
|
55
55
|
#
|
56
56
|
# The currently provided feedback is the tokens for the devices which rejected
|
57
57
|
# notifications. Each piece of feedback is a hash with the following keys:
|
@@ -81,6 +81,53 @@ def self.pack_hex_push_token(push_token)
|
|
81
81
|
[push_token.gsub(/\s/, '')].pack('H*')
|
82
82
|
end
|
83
83
|
|
84
|
+
# Carries state for delivering batched notifications.
|
85
|
+
class PushNotificationsContext
|
86
|
+
# Sends a notification via this context's APNs connection.
|
87
|
+
#
|
88
|
+
# Args:
|
89
|
+
# notification:: see Imobile.push_notification
|
90
|
+
#
|
91
|
+
# Raises a RuntimeError if the context's APNs connection was closed.
|
92
|
+
def push(notification)
|
93
|
+
raise "The context's APNs connection was closed" if @closed
|
94
|
+
@socket.write PushNotifications.encode_notification(notification)
|
95
|
+
end
|
96
|
+
|
97
|
+
# Creates a push context for a fixed Apple Push Notifications server.
|
98
|
+
#
|
99
|
+
# Args:
|
100
|
+
# path_or_certificate:: see Imobile.push_notification
|
101
|
+
def initialize(path_or_certificate)
|
102
|
+
@certificate = PushNotifications.read_certificate path_or_certificate
|
103
|
+
@socket = PushNotifications.apns_socket @certificate, :push
|
104
|
+
@closed = false
|
105
|
+
end
|
106
|
+
|
107
|
+
# Closes the APNs connection. The context is unusable afterwards.
|
108
|
+
def close
|
109
|
+
@socket.close unless @closed
|
110
|
+
@closed = true
|
111
|
+
end
|
112
|
+
|
113
|
+
# The raw SSL connection to the APNs.
|
114
|
+
attr_reader :socket
|
115
|
+
# The APNs client certificate.
|
116
|
+
attr_reader :certificate
|
117
|
+
|
118
|
+
# True if the context's APNs connection is closed.
|
119
|
+
def closed?
|
120
|
+
@closed
|
121
|
+
end
|
122
|
+
|
123
|
+
# Called when the context is garbage-collected.
|
124
|
+
#
|
125
|
+
# Closes the APNs connection, if it wasn't already closed.
|
126
|
+
def finalize
|
127
|
+
close unless @closed
|
128
|
+
end
|
129
|
+
end
|
130
|
+
|
84
131
|
# Implementation details for push_notification.
|
85
132
|
module PushNotifications
|
86
133
|
# Reads an APNs certificate from a string or a file.
|
@@ -203,7 +250,6 @@ module PushNotifications
|
|
203
250
|
super
|
204
251
|
raw_socket.close
|
205
252
|
end
|
206
|
-
socket.sync = true
|
207
253
|
socket.connect
|
208
254
|
end
|
209
255
|
|
@@ -239,17 +285,17 @@ module PushNotifications
|
|
239
285
|
|
240
286
|
# Real implementation of Imobile.push_notifications
|
241
287
|
def self.push_notifications(certificate_or_path, notifications)
|
242
|
-
|
288
|
+
context = PushNotificationsContext.new certificate_or_path
|
243
289
|
notifications = [notifications] if notifications.kind_of? Hash
|
244
|
-
notifications.each { |
|
290
|
+
notifications.each { |notification| context.push notification }
|
245
291
|
if Kernel.block_given?
|
246
292
|
loop do
|
247
293
|
notifications = yield
|
248
294
|
notifications = [notifications] if notifications.kind_of? Hash
|
249
|
-
notifications.each { |
|
295
|
+
notifications.each { |notification| context.push notification }
|
250
296
|
end
|
251
297
|
end
|
252
|
-
|
298
|
+
context.close
|
253
299
|
end
|
254
300
|
|
255
301
|
# Real implementation of Imobile.push_notification
|
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: imobile
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.0.
|
4
|
+
version: 0.0.7
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Victor Costan
|
@@ -9,7 +9,7 @@ autorequire:
|
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
11
|
|
12
|
-
date: 2009-07-
|
12
|
+
date: 2009-07-28 00:00:00 -04:00
|
13
13
|
default_executable:
|
14
14
|
dependencies:
|
15
15
|
- !ruby/object:Gem::Dependency
|
@@ -55,7 +55,7 @@ extra_rdoc_files:
|
|
55
55
|
- lib/imobile/validate_receipt.rb
|
56
56
|
- lib/imobile.rb
|
57
57
|
- LICENSE
|
58
|
-
- README
|
58
|
+
- README.textile
|
59
59
|
files:
|
60
60
|
- CHANGELOG
|
61
61
|
- imobile.gemspec
|
@@ -66,7 +66,7 @@ files:
|
|
66
66
|
- LICENSE
|
67
67
|
- Manifest
|
68
68
|
- Rakefile
|
69
|
-
- README
|
69
|
+
- README.textile
|
70
70
|
- test/crypto_app_fprint_test.rb
|
71
71
|
- test/push_notification_test.rb
|
72
72
|
- test/validate_receipt_test.rb
|
@@ -89,7 +89,7 @@ rdoc_options:
|
|
89
89
|
- --title
|
90
90
|
- Imobile
|
91
91
|
- --main
|
92
|
-
- README
|
92
|
+
- README.textile
|
93
93
|
require_paths:
|
94
94
|
- lib
|
95
95
|
required_ruby_version: !ruby/object:Gem::Requirement
|
data/README
DELETED