rapnd 0.1.10 → 0.2.0

Sign up to get free protection for your applications and to get access to all the features.
data/Gemfile CHANGED
@@ -4,6 +4,8 @@ gem "hiredis", "~> 0.3.1"
4
4
  gem "redis", "~> 2.2.0", :require => ["redis/connection/hiredis", "redis"]
5
5
  gem 'activesupport'
6
6
  gem 'daemons', '1.1.6'
7
+ gem 'i18n'
8
+ gem 'airbrake'
7
9
 
8
10
  group :development do
9
11
  gem 'mocha'
data/Gemfile.lock CHANGED
@@ -2,10 +2,15 @@ GEM
2
2
  remote: http://rubygems.org/
3
3
  specs:
4
4
  activesupport (3.0.0)
5
+ airbrake (3.0.9)
6
+ activesupport
7
+ builder
8
+ builder (3.0.0)
5
9
  daemons (1.1.6)
6
10
  diff-lcs (1.1.3)
7
11
  git (1.2.5)
8
12
  hiredis (0.3.2)
13
+ i18n (0.6.0)
9
14
  jeweler (1.6.4)
10
15
  bundler (~> 1.0)
11
16
  git (>= 1.2.5)
@@ -30,9 +35,11 @@ PLATFORMS
30
35
 
31
36
  DEPENDENCIES
32
37
  activesupport
38
+ airbrake
33
39
  bundler
34
40
  daemons (= 1.1.6)
35
41
  hiredis (~> 0.3.1)
42
+ i18n
36
43
  jeweler
37
44
  mocha
38
45
  rcov
data/VERSION CHANGED
@@ -1 +1 @@
1
- 0.1.10
1
+ 0.2.0
data/bin/rapnd CHANGED
@@ -48,6 +48,10 @@ OptionParser.new do |opts|
48
48
  opts.on("--dir=OPTIONAL", "Directory to start in") do |dir|
49
49
  options[:dir] = dir
50
50
  end
51
+
52
+ opts.on("--airbrake=OPTIONAL", "Airbrake API key") do |airbrake|
53
+ options[:airbrake] = airbrake
54
+ end
51
55
 
52
56
  opts.on('--help', 'Show help') do |help|
53
57
  puts opts
data/lib/rapnd/daemon.rb CHANGED
@@ -4,13 +4,14 @@ require 'socket'
4
4
  require 'active_support/ordered_hash'
5
5
  require 'active_support/json'
6
6
  require 'base64'
7
+ require 'airbrake'
8
+ require 'logger'
7
9
 
8
10
  module Rapnd
9
11
  class Daemon
10
- attr_accessor :redis, :host, :apple, :cert, :queue, :connected
12
+ attr_accessor :redis, :host, :apple, :cert, :queue, :connected, :logger, :airbrake
11
13
 
12
14
  def initialize(options = {})
13
- puts 'Initializing daemon...'
14
15
  options[:redis_host] ||= 'localhost'
15
16
  options[:redis_port] ||= '6379'
16
17
  options[:host] ||= 'gateway.sandbox.push.apple.com'
@@ -18,15 +19,18 @@ module Rapnd
18
19
  options[:password] ||= ''
19
20
  raise 'No cert provided!' unless options[:cert]
20
21
 
22
+ Airbrake.configure { |config| config.api_key = options[:airbrake]; @airbrake = true; } if options[:airbrake]
23
+
21
24
  @redis = Redis.new(:host => options[:redis_host], :port => options[:redis_port])
22
25
  @queue = options[:queue]
23
26
  @cert = options[:cert]
24
27
  @host = options[:host]
25
- puts "Listening on queue: #{self.queue}"
28
+ @logger = Logger.new("#{options[:dir]}/log/#{options[:queue]}.log")
29
+ @logger.info "Listening on queue: #{self.queue}"
26
30
  end
27
31
 
28
32
  def connect!
29
- puts 'Connecting...'
33
+ @logger.info 'Connecting...'
30
34
  @context = OpenSSL::SSL::SSLContext.new
31
35
  @context.cert = OpenSSL::X509::Certificate.new(File.read(@cert))
32
36
  @context.key = OpenSSL::PKey::RSA.new(File.read(@cert), @password)
@@ -37,7 +41,7 @@ module Rapnd
37
41
  self.apple.connect
38
42
 
39
43
  self.connected = true
40
- puts 'Connected!'
44
+ @logger.info 'Connected!'
41
45
 
42
46
  return @sock, @ssl
43
47
  end
@@ -47,10 +51,18 @@ module Rapnd
47
51
  if message
48
52
  notification = Rapnd::Notification.new(Marshal.load(message.last))
49
53
  self.connect! unless self.connected
50
- puts "Sending Apple: #{notification.json_payload}"
54
+ @logger.info "Sending Apple: #{notification.json_payload}"
51
55
  self.apple.write(notification.to_bytes)
52
56
  end
53
57
  self.run!
58
+ rescue Exception => e
59
+ if e.class == Interrupt || e.class == SystemExit
60
+ @logger.info "Shutting down..."
61
+ exit(0)
62
+ end
63
+ Airbrake.notify(e, {:environment_name => self.queue }) if @airbrake
64
+ @logger.error "Encountered error: #{e}"
65
+ retry
54
66
  end
55
67
  end
56
68
  end
@@ -6,7 +6,7 @@ module Rapnd
6
6
  [:badge, :alert, :sound, :device_token, :custom].each do |k|
7
7
  self.instance_variable_set("@#{k}".to_sym, hash[k]) if hash[k]
8
8
  end
9
- raise 'Must provide device token' if self.device_token.nil?
9
+ raise "Must provide device token: #{hash}" if self.device_token.nil?
10
10
  self.device_token = self.device_token.delete(' ')
11
11
  end
12
12
 
@@ -26,7 +26,7 @@ module Rapnd
26
26
 
27
27
  def json_payload
28
28
  j = ActiveSupport::JSON.encode(payload)
29
- raise PayloadInvalid.new("The payload is larger than allowed: #{j.length}") if j.size > 256
29
+ raise "The payload #{j} is larger than allowed: #{j.length}" if j.size > 256
30
30
  j
31
31
  end
32
32
 
data/rapnd.gemspec CHANGED
@@ -5,7 +5,7 @@
5
5
 
6
6
  Gem::Specification.new do |s|
7
7
  s.name = "rapnd"
8
- s.version = "0.1.10"
8
+ s.version = "0.2.0"
9
9
 
10
10
  s.required_rubygems_version = Gem::Requirement.new(">= 0") if s.respond_to? :required_rubygems_version=
11
11
  s.authors = ["Josh Symonds"]
@@ -50,6 +50,8 @@ Gem::Specification.new do |s|
50
50
  s.add_runtime_dependency(%q<redis>, ["~> 2.2.0"])
51
51
  s.add_runtime_dependency(%q<activesupport>, [">= 0"])
52
52
  s.add_runtime_dependency(%q<daemons>, ["= 1.1.6"])
53
+ s.add_runtime_dependency(%q<i18n>, [">= 0"])
54
+ s.add_runtime_dependency(%q<airbrake>, [">= 0"])
53
55
  s.add_development_dependency(%q<mocha>, [">= 0"])
54
56
  s.add_development_dependency(%q<rspec>, [">= 0"])
55
57
  s.add_development_dependency(%q<bundler>, [">= 0"])
@@ -60,6 +62,8 @@ Gem::Specification.new do |s|
60
62
  s.add_dependency(%q<redis>, ["~> 2.2.0"])
61
63
  s.add_dependency(%q<activesupport>, [">= 0"])
62
64
  s.add_dependency(%q<daemons>, ["= 1.1.6"])
65
+ s.add_dependency(%q<i18n>, [">= 0"])
66
+ s.add_dependency(%q<airbrake>, [">= 0"])
63
67
  s.add_dependency(%q<mocha>, [">= 0"])
64
68
  s.add_dependency(%q<rspec>, [">= 0"])
65
69
  s.add_dependency(%q<bundler>, [">= 0"])
@@ -71,6 +75,8 @@ Gem::Specification.new do |s|
71
75
  s.add_dependency(%q<redis>, ["~> 2.2.0"])
72
76
  s.add_dependency(%q<activesupport>, [">= 0"])
73
77
  s.add_dependency(%q<daemons>, ["= 1.1.6"])
78
+ s.add_dependency(%q<i18n>, [">= 0"])
79
+ s.add_dependency(%q<airbrake>, [">= 0"])
74
80
  s.add_dependency(%q<mocha>, [">= 0"])
75
81
  s.add_dependency(%q<rspec>, [">= 0"])
76
82
  s.add_dependency(%q<bundler>, [">= 0"])
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: rapnd
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.1.10
4
+ version: 0.2.0
5
5
  prerelease:
6
6
  platform: ruby
7
7
  authors:
@@ -13,7 +13,7 @@ date: 2012-02-17 00:00:00.000000000 Z
13
13
  dependencies:
14
14
  - !ruby/object:Gem::Dependency
15
15
  name: hiredis
16
- requirement: &70362664346760 !ruby/object:Gem::Requirement
16
+ requirement: &70193136337680 !ruby/object:Gem::Requirement
17
17
  none: false
18
18
  requirements:
19
19
  - - ~>
@@ -21,10 +21,10 @@ dependencies:
21
21
  version: 0.3.1
22
22
  type: :runtime
23
23
  prerelease: false
24
- version_requirements: *70362664346760
24
+ version_requirements: *70193136337680
25
25
  - !ruby/object:Gem::Dependency
26
26
  name: redis
27
- requirement: &70362664345260 !ruby/object:Gem::Requirement
27
+ requirement: &70193136336520 !ruby/object:Gem::Requirement
28
28
  none: false
29
29
  requirements:
30
30
  - - ~>
@@ -32,10 +32,10 @@ dependencies:
32
32
  version: 2.2.0
33
33
  type: :runtime
34
34
  prerelease: false
35
- version_requirements: *70362664345260
35
+ version_requirements: *70193136336520
36
36
  - !ruby/object:Gem::Dependency
37
37
  name: activesupport
38
- requirement: &70362664359820 !ruby/object:Gem::Requirement
38
+ requirement: &70193136335780 !ruby/object:Gem::Requirement
39
39
  none: false
40
40
  requirements:
41
41
  - - ! '>='
@@ -43,10 +43,10 @@ dependencies:
43
43
  version: '0'
44
44
  type: :runtime
45
45
  prerelease: false
46
- version_requirements: *70362664359820
46
+ version_requirements: *70193136335780
47
47
  - !ruby/object:Gem::Dependency
48
48
  name: daemons
49
- requirement: &70362664357520 !ruby/object:Gem::Requirement
49
+ requirement: &70193136334720 !ruby/object:Gem::Requirement
50
50
  none: false
51
51
  requirements:
52
52
  - - =
@@ -54,10 +54,32 @@ dependencies:
54
54
  version: 1.1.6
55
55
  type: :runtime
56
56
  prerelease: false
57
- version_requirements: *70362664357520
57
+ version_requirements: *70193136334720
58
+ - !ruby/object:Gem::Dependency
59
+ name: i18n
60
+ requirement: &70193136333620 !ruby/object:Gem::Requirement
61
+ none: false
62
+ requirements:
63
+ - - ! '>='
64
+ - !ruby/object:Gem::Version
65
+ version: '0'
66
+ type: :runtime
67
+ prerelease: false
68
+ version_requirements: *70193136333620
69
+ - !ruby/object:Gem::Dependency
70
+ name: airbrake
71
+ requirement: &70193136332420 !ruby/object:Gem::Requirement
72
+ none: false
73
+ requirements:
74
+ - - ! '>='
75
+ - !ruby/object:Gem::Version
76
+ version: '0'
77
+ type: :runtime
78
+ prerelease: false
79
+ version_requirements: *70193136332420
58
80
  - !ruby/object:Gem::Dependency
59
81
  name: mocha
60
- requirement: &70362664355780 !ruby/object:Gem::Requirement
82
+ requirement: &70193136010220 !ruby/object:Gem::Requirement
61
83
  none: false
62
84
  requirements:
63
85
  - - ! '>='
@@ -65,10 +87,10 @@ dependencies:
65
87
  version: '0'
66
88
  type: :development
67
89
  prerelease: false
68
- version_requirements: *70362664355780
90
+ version_requirements: *70193136010220
69
91
  - !ruby/object:Gem::Dependency
70
92
  name: rspec
71
- requirement: &70362664354260 !ruby/object:Gem::Requirement
93
+ requirement: &70193136009000 !ruby/object:Gem::Requirement
72
94
  none: false
73
95
  requirements:
74
96
  - - ! '>='
@@ -76,10 +98,10 @@ dependencies:
76
98
  version: '0'
77
99
  type: :development
78
100
  prerelease: false
79
- version_requirements: *70362664354260
101
+ version_requirements: *70193136009000
80
102
  - !ruby/object:Gem::Dependency
81
103
  name: bundler
82
- requirement: &70362664352960 !ruby/object:Gem::Requirement
104
+ requirement: &70193136008080 !ruby/object:Gem::Requirement
83
105
  none: false
84
106
  requirements:
85
107
  - - ! '>='
@@ -87,10 +109,10 @@ dependencies:
87
109
  version: '0'
88
110
  type: :development
89
111
  prerelease: false
90
- version_requirements: *70362664352960
112
+ version_requirements: *70193136008080
91
113
  - !ruby/object:Gem::Dependency
92
114
  name: jeweler
93
- requirement: &70362664367260 !ruby/object:Gem::Requirement
115
+ requirement: &70193136007000 !ruby/object:Gem::Requirement
94
116
  none: false
95
117
  requirements:
96
118
  - - ! '>='
@@ -98,10 +120,10 @@ dependencies:
98
120
  version: '0'
99
121
  type: :development
100
122
  prerelease: false
101
- version_requirements: *70362664367260
123
+ version_requirements: *70193136007000
102
124
  - !ruby/object:Gem::Dependency
103
125
  name: rcov
104
- requirement: &70362664363840 !ruby/object:Gem::Requirement
126
+ requirement: &70193136006200 !ruby/object:Gem::Requirement
105
127
  none: false
106
128
  requirements:
107
129
  - - ! '>='
@@ -109,7 +131,7 @@ dependencies:
109
131
  version: '0'
110
132
  type: :development
111
133
  prerelease: false
112
- version_requirements: *70362664363840
134
+ version_requirements: *70193136006200
113
135
  description: redis APN daemon
114
136
  email: veraticus@gmail.com
115
137
  executables:
@@ -151,7 +173,7 @@ required_ruby_version: !ruby/object:Gem::Requirement
151
173
  version: '0'
152
174
  segments:
153
175
  - 0
154
- hash: -2992434140880509732
176
+ hash: -2383858397958020777
155
177
  required_rubygems_version: !ruby/object:Gem::Requirement
156
178
  none: false
157
179
  requirements: