imobile 0.0.4 → 0.0.5

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/CHANGELOG CHANGED
@@ -1,3 +1,5 @@
1
+ v0.0.5. Renamed device_token to push_token throughout the API.
2
+
1
3
  v0.0.4. Updated CryptoSupport with the push token device attribute.
2
4
 
3
5
  v0.0.3. Push Notification support.
data/Manifest CHANGED
@@ -1,4 +1,5 @@
1
1
  CHANGELOG
2
+ imobile.gemspec
2
3
  lib/imobile/crypto_app_fprint.rb
3
4
  lib/imobile/push_notification.rb
4
5
  lib/imobile/validate_receipt.rb
@@ -15,6 +16,6 @@ testdata/apns_production.p12
15
16
  testdata/device_attributes.yml
16
17
  testdata/encoded_notification
17
18
  testdata/forged_sandbox_receipt
18
- testdata/sandbox_device_token
19
- testdata/sandbox_device_token.bin
19
+ testdata/sandbox_push_token
20
+ testdata/sandbox_push_token.bin
20
21
  testdata/valid_sandbox_receipt
data/imobile.gemspec CHANGED
@@ -2,15 +2,15 @@
2
2
 
3
3
  Gem::Specification.new do |s|
4
4
  s.name = %q{imobile}
5
- s.version = "0.0.4"
5
+ s.version = "0.0.5"
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-26}
9
+ s.date = %q{2009-07-27}
10
10
  s.description = %q{Library for servers backing iPhone applications.}
11
11
  s.email = %q{victor@zergling.net}
12
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", "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_device_token", "testdata/sandbox_device_token.bin", "testdata/valid_sandbox_receipt", "imobile.gemspec"]
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"]
14
14
  s.homepage = %q{http://github.com/costan/imobile}
15
15
  s.rdoc_options = ["--line-numbers", "--inline-source", "--title", "Imobile", "--main", "README"]
16
16
  s.require_paths = ["lib"]
@@ -21,7 +21,7 @@ module Imobile
21
21
  #
22
22
  # Args:
23
23
  # notification:: ruby Hash indicating the desired notification; the hash
24
- # should have an extra key named :device_token, containing
24
+ # should have an extra key named :push_token, containing
25
25
  # the binary-encoded (not hexadecimally-encoded) iMobile device
26
26
  # token, as provided by the UIApplicationDelegate method
27
27
  # application:didRegisterForRemoteNotificationsWithDeviceToken:
@@ -55,7 +55,7 @@ end
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:
58
- # :device_token:: the device's token, in binary (not hexadecimal) format
58
+ # :push_token:: the device's token, in binary (not hexadecimal) format
59
59
  # :time:: the last time when the device rejected notifications; according to
60
60
  # Apple, the rejection can be discarded if the device sent a
61
61
  # token after this time
@@ -76,9 +76,9 @@ def self.valid_notification?(notification)
76
76
  PushNotifications.encode_notification(notification) ? true : false
77
77
  end
78
78
 
79
- # Packs a hexadecimal iMobile device token into binary form.
80
- def self.pack_hex_device_token(device_token)
81
- [device_token.gsub(/\s/, '')].pack('H*')
79
+ # Packs a hexadecimal iMobile token for push notifications into binary form.
80
+ def self.pack_hex_push_token(push_token)
81
+ [push_token.gsub(/\s/, '')].pack('H*')
82
82
  end
83
83
 
84
84
  # Implementation details for push_notification.
@@ -118,13 +118,13 @@ module PushNotifications
118
118
  # Returns a string suitable for transmission over an APNs, or nil if the
119
119
  # notification is invalid (i.e. the json encoding exceeds 256 bytes).
120
120
  def self.encode_notification(notification)
121
- device_token = notification[:device_token] || ''
121
+ push_token = notification[:push_token] || ''
122
122
  notification = notification.dup
123
- notification.delete :device_token
123
+ notification.delete :push_token
124
124
  json_notification = notification.to_json
125
125
  return nil if json_notification.length > 256
126
126
 
127
- ["\0", [device_token.length].pack('n'), device_token,
127
+ ["\0", [push_token.length].pack('n'), push_token,
128
128
  [json_notification.length].pack('n'), json_notification].join
129
129
  end
130
130
 
@@ -226,7 +226,8 @@ module PushNotifications
226
226
  #
227
227
  # The currently provided feedback is the tokens for the devices which rejected
228
228
  # notifications. Each piece of feedback is a hash with the following keys:
229
- # :device_token:: the device's token, in binary (not hexadecimal) format
229
+ # :push_token:: the device's token for push notifications, in binary
230
+ # (not hexadecimal) format
230
231
  # :time:: the last time when the device rejected notifications; according to
231
232
  # Apple, the rejection can be discarded if the device sent a
232
233
  # token after this time
@@ -238,9 +239,9 @@ module PushNotifications
238
239
  loop do
239
240
  break unless header = fixed_socket_read(socket, 6)
240
241
  time = Time.at header[0, 4].unpack('N').first
241
- device_token = fixed_socket_read(socket, header[4, 2].unpack('n').first)
242
- break unless device_token
243
- feedback_item = { :device_token => device_token, :time => time }
242
+ push_token = fixed_socket_read(socket, header[4, 2].unpack('n').first)
243
+ break unless push_token
244
+ feedback_item = { :push_token => push_token, :time => time }
244
245
  yield feedback_item
245
246
  end
246
247
  socket.close
@@ -17,8 +17,8 @@ class PushNotificationTest < Test::Unit::TestCase
17
17
  @dev_cert_path = File.join(testdata_path, 'apns_developer.p12')
18
18
  @prod_cert_path = File.join(testdata_path, 'apns_production.p12')
19
19
 
20
- @hex_dev_token = File.read File.join(testdata_path, 'sandbox_device_token')
21
- @dev_token = File.read File.join(testdata_path, 'sandbox_device_token.bin')
20
+ @hex_dev_token = File.read File.join(testdata_path, 'sandbox_push_token')
21
+ @dev_token = File.read File.join(testdata_path, 'sandbox_push_token.bin')
22
22
 
23
23
  @notification = {:aps => {:alert => 'imobile test notification'}}
24
24
  @encoded_notification = File.read File.join(testdata_path,
@@ -46,12 +46,12 @@ class PushNotificationTest < Test::Unit::TestCase
46
46
  "Wrong data in prod certificate #{cert_data[:certificate].inspect}")
47
47
  end
48
48
 
49
- def test_pack_device_token
50
- assert_equal @dev_token, Imobile.pack_hex_device_token(@hex_dev_token)
49
+ def test_pack_push_token
50
+ assert_equal @dev_token, Imobile.pack_hex_push_token(@hex_dev_token)
51
51
  end
52
52
 
53
53
  def test_encode_notification
54
- notification = @notification.merge :device_token => @dev_token
54
+ notification = @notification.merge :push_token => @dev_token
55
55
  encoded = Imobile::PushNotifications.encode_notification notification
56
56
 
57
57
  assert_equal @encoded_notification, encoded
@@ -60,7 +60,7 @@ class PushNotificationTest < Test::Unit::TestCase
60
60
  def test_valid_notification
61
61
  assert Imobile.valid_notification?(@notification),
62
62
  'Failed on easy valid notification'
63
- notification = @notification.merge :device_token => '1' * 512
63
+ notification = @notification.merge :push_token => '1' * 512
64
64
  assert Imobile.valid_notification?(notification),
65
65
  'Failed on notification with large device token'
66
66
  notification[:aps][:alert] = '1' * 512
@@ -85,7 +85,7 @@ class PushNotificationTest < Test::Unit::TestCase
85
85
  end
86
86
 
87
87
  def test_smoke_push
88
- notification = @notification.merge :device_token => @dev_token
88
+ notification = @notification.merge :push_token => @dev_token
89
89
  Imobile.push_notification notification, @dev_cert_path
90
90
  end
91
91
 
@@ -95,8 +95,8 @@ class PushNotificationTest < Test::Unit::TestCase
95
95
  token1 = @dev_token
96
96
  token2 = @dev_token.reverse
97
97
  golden_feedback = [
98
- {:device_token => token1, :time => time1},
99
- {:device_token => token2, :time => time2}
98
+ {:push_token => token1, :time => time1},
99
+ {:push_token => token2, :time => time2}
100
100
  ]
101
101
 
102
102
  reads = [
@@ -143,8 +143,8 @@ class PushNotificationTest < Test::Unit::TestCase
143
143
 
144
144
  # Verifies that a piece of feedback looks valid.
145
145
  def check_feedback_item(feedback)
146
- assert feedback[:device_token],
147
- "A feedback item does not contain a device token"
146
+ assert feedback[:push_token],
147
+ "A feedback item does not contain a push token"
148
148
  assert feedback[:time],
149
149
  "A feedback item does not contain a timestamp"
150
150
  end
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
4
+ version: 0.0.5
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-26 00:00:00 -04:00
12
+ date: 2009-07-27 00:00:00 -04:00
13
13
  default_executable:
14
14
  dependencies:
15
15
  - !ruby/object:Gem::Dependency
@@ -58,6 +58,7 @@ extra_rdoc_files:
58
58
  - README
59
59
  files:
60
60
  - CHANGELOG
61
+ - imobile.gemspec
61
62
  - lib/imobile/crypto_app_fprint.rb
62
63
  - lib/imobile/push_notification.rb
63
64
  - lib/imobile/validate_receipt.rb
@@ -74,10 +75,9 @@ files:
74
75
  - testdata/device_attributes.yml
75
76
  - testdata/encoded_notification
76
77
  - testdata/forged_sandbox_receipt
77
- - testdata/sandbox_device_token
78
- - testdata/sandbox_device_token.bin
78
+ - testdata/sandbox_push_token
79
+ - testdata/sandbox_push_token.bin
79
80
  - testdata/valid_sandbox_receipt
80
- - imobile.gemspec
81
81
  has_rdoc: true
82
82
  homepage: http://github.com/costan/imobile
83
83
  licenses: []