apn_sender 0.0.4 → 0.0.5

Sign up to get free protection for your applications and to get access to all the features.
data/VERSION CHANGED
@@ -1 +1 @@
1
- 0.0.4
1
+ 0.0.5
data/apn_sender.gemspec CHANGED
@@ -5,11 +5,11 @@
5
5
 
6
6
  Gem::Specification.new do |s|
7
7
  s.name = %q{apn_sender}
8
- s.version = "0.0.4"
8
+ s.version = "0.0.5"
9
9
 
10
10
  s.required_rubygems_version = Gem::Requirement.new(">= 0") if s.respond_to? :required_rubygems_version=
11
11
  s.authors = ["Kali Donovan"]
12
- s.date = %q{2010-05-02}
12
+ s.date = %q{2010-05-03}
13
13
  s.description = %q{Resque-based background worker to send Apple Push Notifications over a persistent TCP socket. Includes Resque tweaks to allow persistent sockets between jobs, helper methods for enqueueing APN notifications, and a background daemon to send them.}
14
14
  s.email = %q{kali.donovan@gmail.com}
15
15
  s.extra_rdoc_files = [
@@ -5,11 +5,11 @@ module APN
5
5
  #
6
6
  # APN::Notification.new's first argument is the token of the iPhone which should receive the notification. The second argument
7
7
  # is a hash with any of :alert, :badge, and :sound keys. All three accept string arguments, while :sound can also be set to +true+
8
- # to play the default sound installed with the application. At least one of these keys must exist. The hash also accepts a
9
- # :custom key to send a hash of custom application data:
8
+ # to play the default sound installed with the application. At least one of these keys must exist. Any other keys are merged into
9
+ # the root of the hash payload ultimately sent to the iPhone:
10
10
  #
11
11
  # APN::Notification.new(token, {:alert => 'Stuff', :custom => {:code => 23}})
12
- # # Writes this JSON to servers: {"code":23,"aps":{"alert":"Stuff"}}
12
+ # # Writes this JSON to servers: {"aps" => {"alert" => "Stuff"}, "custom" => {"code" => 23}}
13
13
  #
14
14
  # As a shortcut, APN::Notification.new also accepts a string as the second argument, which it converts into the alert to send. The
15
15
  # following two lines are equivalent:
@@ -18,6 +18,11 @@ module APN
18
18
  # APN::Notification.new(token, {:alert => 'Some Alert'})
19
19
  #
20
20
  class Notification
21
+ # Available to help clients determine before they create the notification if their message will be too large.
22
+ # Each iPhone Notification payload must be 256 or fewer characters. Encoding a null message has a 57
23
+ # character overhead, so there are 199 characters available for the alert string.
24
+ MAX_ALERT_LENGTH = 199
25
+
21
26
  attr_accessor :options, :token
22
27
  def initialize(token, opts)
23
28
  @options = hash_as_symbols(opts.is_a?(Hash) ? opts : {:alert => opts})
@@ -50,14 +55,17 @@ module APN
50
55
  [@token.gsub(/[\s|<|>]/,'')].pack('H*')
51
56
  end
52
57
 
53
- # Convert the supplied options into the JSON needed for Apple's push notification servers
58
+ # Converts the supplied options into the JSON needed for Apple's push notification servers.
59
+ # Extracts :alert, :badge, and :sound keys into the 'aps' hash, merges any other hash data
60
+ # into the root of the hash to encode and send to apple.
54
61
  def packaged_message
55
62
  hsh = {'aps' => {}}
56
- hsh['aps']['alert'] = @options[:alert].to_s if @options[:alert]
57
- hsh['aps']['badge'] = @options[:badge].to_i if @options[:badge]
58
- hsh['aps']['sound'] = @options[:sound] if @options[:sound] and @options[:sound].is_a? String
59
- hsh['aps']['sound'] = 'default' if @options[:sound] and @options[:sound].is_a? TrueClass
60
- hsh.merge!(@options[:custom]) if @options[:custom]
63
+ hsh['aps']['alert'] = @options.delete(:alert).to_s if @options[:alert]
64
+ hsh['aps']['badge'] = @options.delete(:badge).to_i if @options[:badge]
65
+ if sound = @options.delete(:sound)
66
+ hsh['aps']['sound'] = sound.is_a?(TrueClass) ? 'default' : sound.to_s
67
+ end
68
+ hsh.merge!(@options)
61
69
  hsh.to_json
62
70
  end
63
71
 
data/lib/apn/sender.rb CHANGED
@@ -55,7 +55,7 @@ __END__
55
55
  k = 'ceecdc18 ef17b2d0 745475e0 0a6cd5bf 54534184 ac2649eb 40873c81 ae76dbe8'
56
56
  c = '0f58e3e2 77237b8f f8213851 c835dee0 376b7a31 9e0484f7 06fe3035 7c5dda2f'
57
57
  Resque.enqueue APN::NotificationJob, k, {:alert => 'Resque Test'}
58
- APN.notify 'ceecdc18 ef17b2d0 745475e0 0a6cd5bf 54534184 ac2649eb 40873c81 ae76dbe8', 'Resque Test'
58
+ APN.notify k, 'Resque Test'
59
59
 
60
60
  # If you need to really force quit some screwed up workers
61
61
  Resque.workers.map{|w| Resque.redis.srem(:workers, w)}
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: apn_sender
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
  - Kali Donovan
@@ -9,7 +9,7 @@ autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
11
 
12
- date: 2010-05-02 00:00:00 -07:00
12
+ date: 2010-05-03 00:00:00 -07:00
13
13
  default_executable:
14
14
  dependencies:
15
15
  - !ruby/object:Gem::Dependency