apple_push 0.1.1 → 0.1.2

Sign up to get free protection for your applications and to get access to all the features.
@@ -7,32 +7,34 @@ require 'eventmachine'
7
7
  require 'thin'
8
8
  require 'apple_push'
9
9
 
10
+ def terminate(message, exit_code=1)
11
+ STDERR.puts(message)
12
+ exit(exit_code)
13
+ end
14
+
10
15
  config_path = ARGV.shift.to_s.strip
11
16
 
12
17
  if config_path.empty?
13
- STDERR.puts "Error: Configuration file required!"
14
- exit(1)
18
+ terminate("Configuration file required!")
15
19
  end
16
20
 
17
21
  config = nil
22
+
18
23
  begin
19
24
  config = ApplePush::Configuration.load_file(config_path)
20
- rescue ArgumentError => ex
21
- STDERR.puts "Error: #{ex.message}"
22
- puts ex.backtrace
23
- exit(1)
25
+ rescue StandardError => ex
26
+ terminate(ex.message)
24
27
  end
25
28
 
26
29
  EM.run do
27
30
  begin
28
31
  ApplePush.configure(config)
29
- rescue Exception => ex
30
- STDERR.puts "Error: #{ex.message}"
31
- exit(1)
32
+ rescue StandardError => ex
33
+ terminate(ex.message)
32
34
  end
33
35
 
34
36
  host = ApplePush.configuration[:host]
35
37
  port = ApplePush.configuration[:port]
36
38
 
37
39
  Thin::Server.start(ApplePush::Server, host, port)
38
- end
40
+ end
@@ -15,8 +15,9 @@ module ApplePush
15
15
  config = ApplePush::Configuration.new(options)
16
16
 
17
17
  @@options.merge!(
18
- :host => config.host || '127.0.0.1',
19
- :port => config.port || '27000'
18
+ :host => config.host || '127.0.0.1',
19
+ :port => config.port || '27000',
20
+ :timeout => config.timeout || 5
20
21
  )
21
22
 
22
23
  if !config.sandbox? && !config.live?
@@ -53,9 +54,12 @@ module ApplePush
53
54
  raise ArgumentError, "Path to certificate file required." if !config.cert?
54
55
  raise ArgumentError, "Path to key file required." if !config.cert_key?
55
56
 
56
- pool_size = Integer(config.pool || 1)
57
-
58
- @@pools[env] = ConnectionPool.new(:size => pool_size, :timeout => 5) do
57
+ opts = {
58
+ :size => (Integer(config.pool || 1) rescue 1),
59
+ :timeout => configuration[:timeout]
60
+ }
61
+
62
+ @@pools[env] = ConnectionPool.new(opts) do
59
63
  EM::APN::Client.connect(
60
64
  :gateway => env == 'live' ? LIVE_URL : SANDBOX_URL,
61
65
  :cert => File.expand_path(config.cert),
@@ -9,11 +9,12 @@ module ApplePush
9
9
  #
10
10
  def self.load_file(path)
11
11
  path = File.expand_path(path)
12
+
12
13
  if !File.exists?(path)
13
14
  raise ArgumentError, "File \"#{path}\" does not exist."
14
15
  end
15
- data = YAML.load_file(path)
16
- Configuration.new(data)
16
+
17
+ Configuration.new(YAML.load_file(path))
17
18
  end
18
19
  end
19
20
  end
@@ -1,3 +1,3 @@
1
1
  module ApplePush
2
- VERSION = '0.1.1'
2
+ VERSION = '0.1.2'
3
3
  end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: apple_push
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.1.1
4
+ version: 0.1.2
5
5
  prerelease:
6
6
  platform: ruby
7
7
  authors:
@@ -9,11 +9,11 @@ authors:
9
9
  autorequire:
10
10
  bindir: bin
11
11
  cert_chain: []
12
- date: 2012-02-22 00:00:00.000000000Z
12
+ date: 2012-04-11 00:00:00.000000000Z
13
13
  dependencies:
14
14
  - !ruby/object:Gem::Dependency
15
15
  name: eventmachine
16
- requirement: &70349632289120 !ruby/object:Gem::Requirement
16
+ requirement: &70222318304700 !ruby/object:Gem::Requirement
17
17
  none: false
18
18
  requirements:
19
19
  - - ! '>='
@@ -21,10 +21,10 @@ dependencies:
21
21
  version: '0'
22
22
  type: :runtime
23
23
  prerelease: false
24
- version_requirements: *70349632289120
24
+ version_requirements: *70222318304700
25
25
  - !ruby/object:Gem::Dependency
26
26
  name: sinatra
27
- requirement: &70349632287660 !ruby/object:Gem::Requirement
27
+ requirement: &70222318304180 !ruby/object:Gem::Requirement
28
28
  none: false
29
29
  requirements:
30
30
  - - ! '>='
@@ -32,10 +32,10 @@ dependencies:
32
32
  version: '0'
33
33
  type: :runtime
34
34
  prerelease: false
35
- version_requirements: *70349632287660
35
+ version_requirements: *70222318304180
36
36
  - !ruby/object:Gem::Dependency
37
37
  name: thin
38
- requirement: &70349632284240 !ruby/object:Gem::Requirement
38
+ requirement: &70222318303680 !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: *70349632284240
46
+ version_requirements: *70222318303680
47
47
  - !ruby/object:Gem::Dependency
48
48
  name: connection_pool
49
- requirement: &70349632283260 !ruby/object:Gem::Requirement
49
+ requirement: &70222318303160 !ruby/object:Gem::Requirement
50
50
  none: false
51
51
  requirements:
52
52
  - - ! '>='
@@ -54,10 +54,10 @@ dependencies:
54
54
  version: '0'
55
55
  type: :runtime
56
56
  prerelease: false
57
- version_requirements: *70349632283260
57
+ version_requirements: *70222318303160
58
58
  - !ruby/object:Gem::Dependency
59
59
  name: multi_json
60
- requirement: &70349632226680 !ruby/object:Gem::Requirement
60
+ requirement: &70222318302640 !ruby/object:Gem::Requirement
61
61
  none: false
62
62
  requirements:
63
63
  - - ! '>='
@@ -65,10 +65,10 @@ dependencies:
65
65
  version: '0'
66
66
  type: :runtime
67
67
  prerelease: false
68
- version_requirements: *70349632226680
68
+ version_requirements: *70222318302640
69
69
  - !ruby/object:Gem::Dependency
70
70
  name: hashr
71
- requirement: &70349632225640 !ruby/object:Gem::Requirement
71
+ requirement: &70222318302120 !ruby/object:Gem::Requirement
72
72
  none: false
73
73
  requirements:
74
74
  - - ! '>='
@@ -76,10 +76,10 @@ dependencies:
76
76
  version: '0'
77
77
  type: :runtime
78
78
  prerelease: false
79
- version_requirements: *70349632225640
79
+ version_requirements: *70222318302120
80
80
  - !ruby/object:Gem::Dependency
81
81
  name: em-apn
82
- requirement: &70349632224840 !ruby/object:Gem::Requirement
82
+ requirement: &70222318301600 !ruby/object:Gem::Requirement
83
83
  none: false
84
84
  requirements:
85
85
  - - ! '>='
@@ -87,7 +87,7 @@ dependencies:
87
87
  version: '0'
88
88
  type: :runtime
89
89
  prerelease: false
90
- version_requirements: *70349632224840
90
+ version_requirements: *70222318301600
91
91
  description: Sinatra-based server to deliver Apple Push Notifications
92
92
  email:
93
93
  - dan.sosedoff@gmail.com
@@ -127,7 +127,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
127
127
  version: '0'
128
128
  requirements: []
129
129
  rubyforge_project:
130
- rubygems_version: 1.8.10
130
+ rubygems_version: 1.8.15
131
131
  signing_key:
132
132
  specification_version: 3
133
133
  summary: Simple API to send APN notifications