resque-aps 0.9.8 → 0.9.9

Sign up to get free protection for your applications and to get access to all the features.
data/HISTORY.md CHANGED
@@ -1,3 +1,7 @@
1
+ ## 0.9.9 (2010-08-10)
2
+
3
+ * Changed the module from ResqueAps to Resque::Plugins::Aps, per Resque documentation
4
+
1
5
  ## 0.9.8 (2010-08-08)
2
6
 
3
7
  * Fix a bug in the aps_read_error logging method.
data/README.markdown CHANGED
@@ -29,7 +29,7 @@ To extend the system create an initializer:
29
29
  Resque.aps_feedback_host = AppConfig.apn_feedback_host
30
30
  Resque.aps_feedback_port = AppConfig.apn_feedback_port
31
31
 
32
- module ResqueAps
32
+ module Resque::Plugins::Aps
33
33
  class Application
34
34
  def after_aps_write(notification)
35
35
  logger.info("Sent Notification [#{notification.application_name}] [#{notification.device_token}] [#{notification.payload}]") if logger
data/Rakefile CHANGED
@@ -34,7 +34,7 @@ begin
34
34
  gemspec.email = "ashleym1972@gmail.com"
35
35
  gemspec.homepage = "http://github.com/ashleym1972/resque-aps"
36
36
  gemspec.authors = ["Ashley Martens"]
37
- gemspec.version = ResqueAps::Version
37
+ gemspec.version = Resque::Plugins::Aps::Version
38
38
 
39
39
  gemspec.add_dependency "redis", ">= 1.0.7"
40
40
  gemspec.add_dependency "resque", ">= 1.5.0"
@@ -47,9 +47,9 @@ end
47
47
 
48
48
  desc "Push a new version to Gemcutter"
49
49
  task :publish => [ :test, :gemspec, :build ] do
50
- system "git tag v#{ResqueAps::Version}"
51
- system "git push origin v#{ResqueAps::Version}"
50
+ system "git tag v#{Resque::Plugins::Aps::Version}"
51
+ system "git push origin v#{Resque::Plugins::Aps::Version}"
52
52
  system "git push origin master"
53
- system "gem push pkg/resque-aps-#{ResqueAps::Version}.gem"
53
+ system "gem push pkg/resque-aps-#{Resque::Plugins::Aps::Version}.gem"
54
54
  system "git clean -fd"
55
55
  end
@@ -1,9 +1,11 @@
1
1
  require 'openssl'
2
2
 
3
- module ResqueAps
3
+ module Resque
4
+ module Plugins
5
+ module Aps
4
6
  class Application
5
- include ResqueAps::Helper
6
- extend ResqueAps::Helper
7
+ include Resque::Plugins::Aps::Helper
8
+ extend Resque::Plugins::Aps::Helper
7
9
 
8
10
  attr_accessor :name, :cert_file, :cert_passwd
9
11
 
@@ -86,7 +88,7 @@ module ResqueAps
86
88
 
87
89
  def initialize(attributes)
88
90
  attributes.each do |k, v|
89
- respond_to?(:"#{k}=") ? send(:"#{k}=", v) : raise(ResqueAps::UnknownAttributeError, "unknown attribute: #{k}")
91
+ respond_to?(:"#{k}=") ? send(:"#{k}=", v) : raise(Resque::Plugins::Aps::UnknownAttributeError, "unknown attribute: #{k}")
90
92
  end
91
93
  end
92
94
 
@@ -161,6 +163,8 @@ module ResqueAps
161
163
  def aps_read_failed
162
164
  logger.error("ResqueAps[read_failed]: Bad data on the socket (#{name})") if logger
163
165
  end
164
-
166
+
167
+ end
168
+ end
165
169
  end
166
170
  end
@@ -1,9 +1,11 @@
1
1
  require 'timeout'
2
2
 
3
- module ResqueAps
3
+ module Resque
4
+ module Plugins
5
+ module Aps
4
6
  class Feedback
5
- include ResqueAps::Helper
6
- extend ResqueAps::Helper
7
+ include Resque::Plugins::Aps::Helper
8
+ extend Resque::Plugins::Aps::Helper
7
9
 
8
10
  @queue = "apple_push_service"
9
11
 
@@ -11,7 +13,7 @@ module ResqueAps
11
13
 
12
14
  def initialize(attributes)
13
15
  attributes.each do |k, v|
14
- respond_to?(:"#{k}=") ? send(:"#{k}=", v) : raise(ResqueAps::UnknownAttributeError, "unknown attribute: #{k}")
16
+ respond_to?(:"#{k}=") ? send(:"#{k}=", v) : raise(Resque::Plugins::Aps::UnknownAttributeError, "unknown attribute: #{k}")
15
17
  end
16
18
  end
17
19
 
@@ -67,7 +69,7 @@ module ResqueAps
67
69
  timeout(5) do
68
70
  until socket.eof?
69
71
  app.before_aps_read
70
- feedback = read_feedback(ssl_socket, app_name, product_id)
72
+ feedback = read_feedback(socket, app_name, product_id)
71
73
  if feedback
72
74
  count += 1
73
75
  app.after_app_read(feedback)
@@ -85,4 +87,6 @@ module ResqueAps
85
87
  end
86
88
 
87
89
  end
90
+ end
91
+ end
88
92
  end
@@ -1,5 +1,7 @@
1
1
 
2
- module ResqueAps
2
+ module Resque
3
+ module Plugins
4
+ module Aps
3
5
  module Helper
4
6
  extend Resque::Helpers
5
7
 
@@ -8,4 +10,6 @@ module ResqueAps
8
10
  end
9
11
 
10
12
  end
13
+ end
14
+ end
11
15
  end
@@ -1,13 +1,15 @@
1
- module ResqueAps
1
+ module Resque
2
+ module Plugins
3
+ module Aps
2
4
  class Notification
3
- include ResqueAps::Helper
4
- extend ResqueAps::Helper
5
+ include Resque::Plugins::Aps::Helper
6
+ extend Resque::Plugins::Aps::Helper
5
7
 
6
8
  attr_accessor :application_name, :device_token, :payload
7
9
 
8
10
  def initialize(attributes)
9
11
  attributes.each do |k, v|
10
- respond_to?(:"#{k}=") ? send(:"#{k}=", v) : raise(ResqueAps::UnknownAttributeError, "unknown attribute: #{k}")
12
+ respond_to?(:"#{k}=") ? send(:"#{k}=", v) : raise(Resque::Plugins::Aps::UnknownAttributeError, "unknown attribute: #{k}")
11
13
  end
12
14
  end
13
15
 
@@ -156,7 +158,7 @@ module ResqueAps
156
158
  # The message formatted for sending in binary
157
159
  #
158
160
  def formatted
159
- ResqueAps::Notification.format_message_for_sending(self.device_token, self.payload)
161
+ Resque::Plugins::Aps::Notification.format_message_for_sending(self.device_token, self.payload)
160
162
  end
161
163
 
162
164
  #
@@ -190,4 +192,6 @@ module ResqueAps
190
192
  # "\0\0 #{token_hex}\0#{json.length.chr}#{json}"
191
193
  end
192
194
  end
195
+ end
196
+ end
193
197
  end
@@ -1,7 +1,9 @@
1
1
  require 'rack/test'
2
2
  require 'resque/server'
3
3
 
4
- module ResqueAps
4
+ module Resque
5
+ module Plugins
6
+ module Aps
5
7
  module TestHelper
6
8
  class Test::Unit::TestCase
7
9
  include Rack::Test::Methods
@@ -16,5 +18,7 @@ module ResqueAps
16
18
  end
17
19
  end
18
20
  end
21
+ end
22
+ end
19
23
  end
20
24
 
@@ -1,6 +1,8 @@
1
1
 
2
2
  # Extend Resque::Server to add tabs
3
- module ResqueAps
3
+ module Resque
4
+ module Plugins
5
+ module Aps
4
6
 
5
7
  module Server
6
8
 
@@ -19,7 +21,7 @@ module ResqueAps
19
21
  end
20
22
 
21
23
  post "/aps/:application_name" do
22
- Resque.enqueue(ResqueAps::Application, params[:application_name])
24
+ Resque.enqueue(Resque::Plugins::Aps::Application, params[:application_name])
23
25
  redirect url("/aps")
24
26
  end
25
27
  end
@@ -30,4 +32,6 @@ module ResqueAps
30
32
 
31
33
  end
32
34
 
35
+ end
36
+ end
33
37
  end
@@ -1,4 +1,8 @@
1
- module ResqueAps
1
+ module Resque
2
+ module Plugins
3
+ module Aps
2
4
  class UnknownAttributeError < Exception
3
5
  end
6
+ end
7
+ end
4
8
  end
@@ -1,3 +1,7 @@
1
- module ResqueAps
2
- Version = '0.9.8'
1
+ module Resque
2
+ module Plugins
3
+ module Aps
4
+ Version = '0.9.9'
5
+ end
6
+ end
3
7
  end
data/lib/resque_aps.rb CHANGED
@@ -10,7 +10,9 @@ require 'resque_aps/notification'
10
10
  require 'resque_aps/feedback'
11
11
  require 'resque_aps/unknown_attribute_error'
12
12
 
13
- module ResqueAps
13
+ module Resque
14
+ module Plugins
15
+ module Aps
14
16
 
15
17
  def logger=(logger)
16
18
  @logger = logger
@@ -75,13 +77,13 @@ module ResqueAps
75
77
  def enqueue_aps(application_name, notification)
76
78
  count = aps_notification_count_for_application(application_name)
77
79
  redis.rpush(aps_application_queue_key(application_name), encode(notification.to_hash))
78
- enqueue(ResqueAps::Application, application_name) if count <= aps_queue_size_lower || count >= aps_queue_size_upper
80
+ enqueue(Resque::Plugins::Aps::Application, application_name) if count <= aps_queue_size_lower || count >= aps_queue_size_upper
79
81
  true
80
82
  end
81
83
 
82
84
  def dequeue_aps(application_name)
83
85
  h = decode(redis.lpop(aps_application_queue_key(application_name)))
84
- return ResqueAps::Notification.new(h) if h
86
+ return Resque::Plugins::Aps::Notification.new(h) if h
85
87
  nil
86
88
  end
87
89
 
@@ -94,7 +96,7 @@ module ResqueAps
94
96
  def aps_notifications_for_application(application_name, start = 0, count = 1)
95
97
  r = redis.lrange(aps_application_queue_key(application_name), start, count)
96
98
  if r
97
- r.map { |h| ResqueAps::Notification.new(decode(h)) }
99
+ r.map { |h| Resque::Plugins::Aps::Notification.new(decode(h)) }
98
100
  else
99
101
  []
100
102
  end
@@ -107,7 +109,7 @@ module ResqueAps
107
109
 
108
110
  def aps_application(name)
109
111
  h = decode(redis.get(aps_application_key(name)))
110
- return ResqueAps::Application.new(h) if h
112
+ return Resque::Plugins::Aps::Application.new(h) if h
111
113
  nil
112
114
  end
113
115
 
@@ -132,9 +134,11 @@ module ResqueAps
132
134
  def aps_application_queue_key(application_name)
133
135
  "#{aps_application_key(application_name)}:queue"
134
136
  end
137
+ end
138
+ end
135
139
  end
136
140
 
137
- Resque.extend ResqueAps
141
+ Resque.extend Resque::Plugins::Aps
138
142
  Resque::Server.class_eval do
139
- include ResqueAps::Server
143
+ include Resque::Plugins::Aps::Server
140
144
  end
@@ -1,32 +1,32 @@
1
1
  require File.dirname(__FILE__) + '/test_helper'
2
2
 
3
- context "ResqueAps::Application" do
3
+ context "Resque::Plugins::Aps::Application" do
4
4
  test "has a nice #inspect" do
5
- n = ResqueAps::Application.new('name' => 'SomeApp', 'cert_file' => '/var/apps/certificates/some_app.pem', 'cert_passwd' => 'hello')
6
- assert_equal '#<ResqueAps::Application "SomeApp", "hello", "/var/apps/certificates/some_app.pem">', n.inspect
5
+ n = Resque::Plugins::Aps::Application.new('name' => 'SomeApp', 'cert_file' => '/var/apps/certificates/some_app.pem', 'cert_passwd' => 'hello')
6
+ assert_equal '#<Resque::Plugins::Aps::Application "SomeApp", "hello", "/var/apps/certificates/some_app.pem">', n.inspect
7
7
  end
8
8
 
9
9
  test "can create and close sockets" do
10
10
  cert = File.read(File.dirname(__FILE__) + "/../test-dev.pem")
11
- socket, ssl = ResqueAps::Application.create_sockets(cert, nil, Resque.aps_gateway_host, Resque.aps_gateway_port)
12
- ResqueAps::Application.close_sockets(socket, ssl)
11
+ socket, ssl = Resque::Plugins::Aps::Application.create_sockets(cert, nil, Resque.aps_gateway_host, Resque.aps_gateway_port)
12
+ Resque::Plugins::Aps::Application.close_sockets(socket, ssl)
13
13
  end
14
14
 
15
15
  test "can run socket block" do
16
- a = ResqueAps::Application.new(:name => "TestApp", :cert_file => File.dirname(__FILE__) + "/../test-dev.pem")
16
+ a = Resque::Plugins::Aps::Application.new(:name => "TestApp", :cert_file => File.dirname(__FILE__) + "/../test-dev.pem")
17
17
  a.socket do |s, a|
18
18
  end
19
19
  end
20
20
 
21
21
  test "can perform" do
22
- n = ResqueAps::Notification.new('application_name' => 'TestApp', 'device_token' => 'aihdf08u2402hbdfquhiwr', 'payload' => '{"aps": { "alert": "hello"}}')
22
+ n = Resque::Plugins::Aps::Notification.new('application_name' => 'TestApp', 'device_token' => 'aihdf08u2402hbdfquhiwr', 'payload' => '{"aps": { "alert": "hello"}}')
23
23
  assert Resque.enqueue_aps('TestApp', n)
24
24
  Resque.create_aps_application('TestApp', File.dirname(__FILE__) + "/../test-dev.pem", nil)
25
- ResqueAps::Application.perform('TestApp')
25
+ Resque::Plugins::Aps::Application.perform('TestApp')
26
26
  end
27
27
 
28
28
  context "ApplicationWithHooks" do
29
- module ResqueAps
29
+ module Resque::Plugins::Aps
30
30
  class Application
31
31
  def before_aps_write(notification)
32
32
  logger.debug "before_aps_write #{notification.inspect}"
@@ -52,10 +52,10 @@ context "ResqueAps::Application" do
52
52
  end
53
53
 
54
54
  test "can perform with logging hooks" do
55
- n = ResqueAps::Notification.new('application_name' => 'TestApp', 'device_token' => 'aihdf08u2402hbdfquhiwr', 'payload' => '{"aps": { "alert": "hello"}}')
55
+ n = Resque::Plugins::Aps::Notification.new('application_name' => 'TestApp', 'device_token' => 'aihdf08u2402hbdfquhiwr', 'payload' => '{"aps": { "alert": "hello"}}')
56
56
  assert Resque.enqueue_aps('TestApp', n)
57
57
  Resque.create_aps_application('TestApp', File.dirname(__FILE__) + "/../test-dev.pem", nil)
58
- ResqueAps::Application.perform('TestApp')
58
+ Resque::Plugins::Aps::Application.perform('TestApp')
59
59
  end
60
60
  end
61
61
  end
@@ -1,8 +1,8 @@
1
1
  require File.dirname(__FILE__) + '/test_helper'
2
2
 
3
- context "ResqueAps::Application" do
3
+ context "Resque::Plugins::Aps::Application" do
4
4
  test "can perform" do
5
5
  Resque.create_aps_application('TestApp', File.dirname(__FILE__) + "/../test-dev.pem", nil)
6
- ResqueAps::Feedback.perform('TestApp')
6
+ Resque::Plugins::Aps::Feedback.perform('TestApp')
7
7
  end
8
8
  end
@@ -1,8 +1,8 @@
1
1
  require File.dirname(__FILE__) + '/test_helper'
2
2
 
3
- context "ResqueAps::Notification" do
3
+ context "Resque::Plugins::Aps::Notification" do
4
4
  test "has a nice #inspect" do
5
- n = ResqueAps::Notification.new('application_name' => 'SomeApp', 'device_token' => 'aihdf08u2402hbdfquhiwr', 'payload' => '{"aps": { "alert": "hello"}}')
6
- assert_equal '#<ResqueAps::Notification "SomeApp", "aihdf08u2402hbdfquhiwr", "{\"aps\": { \"alert\": \"hello\"}}">', n.inspect
5
+ n = Resque::Plugins::Aps::Notification.new('application_name' => 'SomeApp', 'device_token' => 'aihdf08u2402hbdfquhiwr', 'payload' => '{"aps": { "alert": "hello"}}')
6
+ assert_equal '#<Resque::Plugins::Aps::Notification "SomeApp", "aihdf08u2402hbdfquhiwr", "{\"aps\": { \"alert\": \"hello\"}}">', n.inspect
7
7
  end
8
8
  end
@@ -29,7 +29,7 @@ context "on GET to /aps/some_ivar_application" do
29
29
  setup do
30
30
  Resque.redis.flushall
31
31
  Resque.create_aps_application(:some_ivar_application, nil, nil)
32
- n = ResqueAps::Notification.new('application_name' => 'some_ivar_application', 'device_token' => 'aihdf08u2402hbdfquhiwr', 'payload' => '{"aps": { "alert": "hello"}}')
32
+ n = Resque::Plugins::Aps::Notification.new('application_name' => 'some_ivar_application', 'device_token' => 'aihdf08u2402hbdfquhiwr', 'payload' => '{"aps": { "alert": "hello"}}')
33
33
  assert Resque.enqueue_aps(:some_ivar_application, n)
34
34
  assert Resque.enqueue_aps(:some_ivar_application, n)
35
35
  assert Resque.enqueue_aps(:some_ivar_application, n)
@@ -1,6 +1,6 @@
1
1
  require File.dirname(__FILE__) + '/test_helper'
2
2
 
3
- context "ResqueAps" do
3
+ context "Resque::Plugins::Aps" do
4
4
  setup do
5
5
  Resque.redis.flushall
6
6
  end
@@ -43,7 +43,7 @@ context "ResqueAps" do
43
43
  end
44
44
 
45
45
  test "can enqueue aps notifications" do
46
- n = ResqueAps::Notification.new('application_name' => 'SomeApp', 'device_token' => 'aihdf08u2402hbdfquhiwr', 'payload' => '{"aps": { "alert": "hello"}}')
46
+ n = Resque::Plugins::Aps::Notification.new('application_name' => 'SomeApp', 'device_token' => 'aihdf08u2402hbdfquhiwr', 'payload' => '{"aps": { "alert": "hello"}}')
47
47
  assert Resque.enqueue_aps('SomeApp', n)
48
48
  assert_equal 1, Resque.aps_notification_count_for_application('SomeApp')
49
49
  assert Resque.enqueue_aps('SomeApp', n)
@@ -51,21 +51,21 @@ context "ResqueAps" do
51
51
  end
52
52
 
53
53
  test "can dequeue aps notifications" do
54
- n = ResqueAps::Notification.new('application_name' => 'SomeApp', 'device_token' => 'aihdf08u2402hbdfquhiwr', 'payload' => '{"aps": { "alert": "hello"}}')
54
+ n = Resque::Plugins::Aps::Notification.new('application_name' => 'SomeApp', 'device_token' => 'aihdf08u2402hbdfquhiwr', 'payload' => '{"aps": { "alert": "hello"}}')
55
55
  assert Resque.enqueue_aps('SomeApp', n)
56
56
  assert_equal 1, Resque.aps_notification_count_for_application('SomeApp')
57
57
 
58
58
  nn = Resque.dequeue_aps('SomeApp')
59
59
 
60
60
  assert nn
61
- assert_kind_of ResqueAps::Notification, nn
61
+ assert_kind_of Resque::Plugins::Aps::Notification, nn
62
62
  assert_equal n.application_name, nn.application_name
63
63
  assert_equal n.device_token, nn.device_token
64
64
  assert_equal n.payload, nn.payload
65
65
  end
66
66
 
67
67
  test "knows how big the application notification queue is" do
68
- n = ResqueAps::Notification.new('application_name' => 'SomeApp', 'device_token' => 'aihdf08u2402hbdfquhiwr', 'payload' => '{"aps": { "alert": "hello"}}')
68
+ n = Resque::Plugins::Aps::Notification.new('application_name' => 'SomeApp', 'device_token' => 'aihdf08u2402hbdfquhiwr', 'payload' => '{"aps": { "alert": "hello"}}')
69
69
  assert Resque.enqueue_aps('SomeApp', n)
70
70
  assert_equal 1, Resque.aps_notification_count_for_application('SomeApp')
71
71
 
@@ -74,7 +74,7 @@ context "ResqueAps" do
74
74
  end
75
75
 
76
76
  test "can get a list of application notifications" do
77
- n = ResqueAps::Notification.new('application_name' => 'SomeApp', 'device_token' => 'aihdf08u2402hbdfquhiwr', 'payload' => '{"aps": { "alert": "hello"}}')
77
+ n = Resque::Plugins::Aps::Notification.new('application_name' => 'SomeApp', 'device_token' => 'aihdf08u2402hbdfquhiwr', 'payload' => '{"aps": { "alert": "hello"}}')
78
78
  assert Resque.enqueue_aps('SomeApp', n)
79
79
  assert Resque.enqueue_aps('SomeApp', n)
80
80
  assert Resque.enqueue_aps('SomeApp', n)
metadata CHANGED
@@ -5,8 +5,8 @@ version: !ruby/object:Gem::Version
5
5
  segments:
6
6
  - 0
7
7
  - 9
8
- - 8
9
- version: 0.9.8
8
+ - 9
9
+ version: 0.9.9
10
10
  platform: ruby
11
11
  authors:
12
12
  - Ashley Martens
@@ -14,7 +14,7 @@ autorequire:
14
14
  bindir: bin
15
15
  cert_chain: []
16
16
 
17
- date: 2010-08-08 00:00:00 -07:00
17
+ date: 2010-08-10 00:00:00 -07:00
18
18
  default_executable:
19
19
  dependencies:
20
20
  - !ruby/object:Gem::Dependency