pling 0.3.1 → 0.4.0

Sign up to get free protection for your applications and to get access to all the features.
@@ -0,0 +1,7 @@
1
+ ---
2
+ SHA1:
3
+ metadata.gz: 14d000e78a057ba2db7a60c0a235d1f3f09b63c2
4
+ data.tar.gz: 890d8ed20c079f8e8f41ad3bc36b7d50e7b2f711
5
+ SHA512:
6
+ metadata.gz: a51e7f0552197e83caffc20d94f383da8437228a65fe650acc505f02fa3cf07cbbcae2ba47f705c6829a4e58fbd1340c3156966483f55596f438386b07e5f9e6
7
+ data.tar.gz: ff10429ead2557b0f681c52093a5340614599e0dd16ba2fb3665021f95043efd2806487cbaff833274277623f955aa3a1adeabeb0bc6defaed3e3de88b06f17c
@@ -5,11 +5,9 @@ language: ruby
5
5
  rvm:
6
6
  - ruby-head
7
7
  - 1.9.3
8
- - 1.8.7
9
- - ree
10
8
  - jruby
11
9
  - jruby-19mode
12
- - rbx-19mode
10
+ - rbx-2
13
11
  matrix:
14
12
  allow_failures:
15
- - rvm: ruby-head
13
+ - rvm: ruby-head
data/Gemfile CHANGED
@@ -6,5 +6,4 @@ gemspec
6
6
  gem 'guard'
7
7
  gem 'guard-rspec'
8
8
  gem 'guard-yard', :platform => :ruby_19
9
- gem 'growl_notify' if RUBY_PLATFORM =~ /darwin/
10
9
  gem 'rdiscount', ">= 1.6.8", :platform => :ruby
@@ -1,6 +1,7 @@
1
1
  require 'socket'
2
2
  require 'openssl'
3
3
  require 'json'
4
+ require 'connection_pool'
4
5
 
5
6
  module Pling
6
7
  module APN
@@ -33,10 +34,10 @@ module Pling
33
34
  setup!
34
35
  end
35
36
 
36
- ##
37
+ ##
37
38
  # Establishes a new connection if connection is not available or closed
38
39
  def setup!
39
- connection.reopen if connection.closed?
40
+ setup_connection_pool
40
41
  end
41
42
 
42
43
  ##
@@ -57,9 +58,9 @@ module Pling
57
58
 
58
59
  data = data.to_json
59
60
 
60
- if data.bytesize > 256
61
+ if data.bytesize > 2048
61
62
  raise Pling::DeliveryFailed.new(
62
- "Payload size of #{data.bytesize} exceeds allowed size of 256 bytes.",
63
+ "Payload size of #{data.bytesize} exceeds allowed size of 2048 bytes.",
63
64
  message,
64
65
  device)
65
66
  end
@@ -75,18 +76,33 @@ module Pling
75
76
  super.merge(
76
77
  :host => 'gateway.push.apple.com',
77
78
  :port => 2195,
78
- :payload => false
79
+ :payload => false,
80
+ :pool_size => 3,
81
+ :timeout => 5
79
82
  )
80
83
  end
81
84
 
82
85
  def connection
83
- @connection ||= Connection.new(
86
+ @connection
87
+ end
88
+
89
+ def setup_connection_pool
90
+ @connection ||= connection_pool
91
+ end
92
+
93
+ def new_connection
94
+ Connection.new(
84
95
  :host => configuration[:host],
85
96
  :port => configuration[:port],
86
97
  :certificate => configuration[:certificate]
87
98
  )
88
99
  end
89
100
 
101
+ def connection_pool
102
+ ConnectionPool::Wrapper.new(size: configuration[:pool_size], timeout: configuration[:timeout]) do
103
+ new_connection
104
+ end
105
+ end
90
106
  end
91
107
  end
92
108
  end
@@ -104,7 +104,7 @@ module Pling
104
104
  end
105
105
 
106
106
  def connection
107
- @connection ||= Faraday.new(configuration[:connection]) do |builder|
107
+ Faraday.new(configuration[:connection]) do |builder|
108
108
  builder.use Faraday::Request::UrlEncoded
109
109
  builder.use Faraday::Response::Logger if configuration[:debug]
110
110
  builder.adapter(configuration[:adapter])
@@ -75,7 +75,7 @@ module Pling
75
75
  end
76
76
 
77
77
  def connection
78
- @connection ||= Faraday.new(configuration[:connection]) do |builder|
78
+ Faraday.new(configuration[:connection]) do |builder|
79
79
  builder.use FaradayMiddleware::EncodeJson
80
80
  builder.use FaradayMiddleware::ParseJson, :content_type => /\bjson$/
81
81
  builder.use Faraday::Response::Logger if configuration[:debug]
@@ -1,3 +1,3 @@
1
1
  module Pling
2
- VERSION = "0.3.1"
2
+ VERSION = "0.4.0"
3
3
  end
@@ -19,6 +19,7 @@ Gem::Specification.new do |s|
19
19
  s.add_runtime_dependency "faraday", "~> 0.7"
20
20
  s.add_runtime_dependency "faraday_middleware", "~> 0.8"
21
21
  s.add_runtime_dependency "json", "~> 1.4"
22
+ s.add_runtime_dependency "connection_pool", "~> 2.0.0"
22
23
  s.add_runtime_dependency("jruby-openssl") if RUBY_PLATFORM == 'java'
23
24
 
24
25
  s.add_development_dependency "rspec", "~> 2.7"
@@ -18,6 +18,21 @@ describe Pling::APN::Gateway do
18
18
  Pling::APN::Gateway.handled_types.should =~ [:apple, :apn, :ios, :ipad, :iphone, :ipod]
19
19
  end
20
20
 
21
+ describe '#setup!' do
22
+ before do
23
+ valid_configuration.merge!(pool_size: 99, timeout: 55)
24
+ end
25
+
26
+ subject { Pling::APN::Gateway.new(valid_configuration) }
27
+
28
+ let(:connection_pool) { double(:connection_pool_double) }
29
+
30
+ it 'initializes a new connection pool for the APN connection' do
31
+ ConnectionPool::Wrapper.should_receive(:new).with(size: 99, timeout: 55).and_return(connection_pool)
32
+ subject.setup!
33
+ end
34
+ end
35
+
21
36
  describe '#deliver' do
22
37
  subject { Pling::APN::Gateway.new(valid_configuration) }
23
38
 
@@ -29,6 +44,14 @@ describe Pling::APN::Gateway do
29
44
  expect { subject.deliver(message, nil) }.to raise_error
30
45
  end
31
46
 
47
+ it 'should initialize a new APN connection if none is established' do
48
+ Pling::APN::Connection.should_receive(:new).and_return(connection)
49
+ subject.deliver(message, device)
50
+
51
+ Pling::APN::Connection.should_not_receive(:new)
52
+ subject.deliver(message, device)
53
+ end
54
+
32
55
  it 'should call #to_pling_message on the given message' do
33
56
  message.should_receive(:to_pling_message).and_return(message)
34
57
  subject.deliver(message, device)
@@ -39,9 +62,9 @@ describe Pling::APN::Gateway do
39
62
  subject.deliver(message, device)
40
63
  end
41
64
 
42
- it 'should raise an exception when the payload exceeds 256 bytes' do
43
- message.body = "X" * 256
44
- expect { subject.deliver(message, device) }.to raise_error(Pling::DeliveryFailed, /Payload size of \d+ exceeds allowed size of 256 bytes/)
65
+ it 'should raise an exception when the payload exceeds 2048 bytes' do
66
+ message.body = "X" * 3000
67
+ expect { subject.deliver(message, device) }.to raise_error(Pling::DeliveryFailed, /Payload size of \d+ exceeds allowed size of 2048 bytes/)
45
68
  end
46
69
 
47
70
  it 'should try to deliver the given message' do
@@ -138,4 +161,4 @@ describe Pling::APN::Gateway do
138
161
  end
139
162
  end
140
163
  end
141
- end
164
+ end
metadata CHANGED
@@ -1,8 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: pling
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.3.1
5
- prerelease:
4
+ version: 0.4.0
6
5
  platform: ruby
7
6
  authors:
8
7
  - Benedikt Deicke
@@ -11,102 +10,104 @@ authors:
11
10
  autorequire:
12
11
  bindir: bin
13
12
  cert_chain: []
14
- date: 2013-07-05 00:00:00.000000000 Z
13
+ date: 2015-09-24 00:00:00.000000000 Z
15
14
  dependencies:
16
15
  - !ruby/object:Gem::Dependency
17
16
  name: faraday
18
17
  requirement: !ruby/object:Gem::Requirement
19
- none: false
20
18
  requirements:
21
- - - ~>
19
+ - - "~>"
22
20
  - !ruby/object:Gem::Version
23
21
  version: '0.7'
24
22
  type: :runtime
25
23
  prerelease: false
26
24
  version_requirements: !ruby/object:Gem::Requirement
27
- none: false
28
25
  requirements:
29
- - - ~>
26
+ - - "~>"
30
27
  - !ruby/object:Gem::Version
31
28
  version: '0.7'
32
29
  - !ruby/object:Gem::Dependency
33
30
  name: faraday_middleware
34
31
  requirement: !ruby/object:Gem::Requirement
35
- none: false
36
32
  requirements:
37
- - - ~>
33
+ - - "~>"
38
34
  - !ruby/object:Gem::Version
39
35
  version: '0.8'
40
36
  type: :runtime
41
37
  prerelease: false
42
38
  version_requirements: !ruby/object:Gem::Requirement
43
- none: false
44
39
  requirements:
45
- - - ~>
40
+ - - "~>"
46
41
  - !ruby/object:Gem::Version
47
42
  version: '0.8'
48
43
  - !ruby/object:Gem::Dependency
49
44
  name: json
50
45
  requirement: !ruby/object:Gem::Requirement
51
- none: false
52
46
  requirements:
53
- - - ~>
47
+ - - "~>"
54
48
  - !ruby/object:Gem::Version
55
49
  version: '1.4'
56
50
  type: :runtime
57
51
  prerelease: false
58
52
  version_requirements: !ruby/object:Gem::Requirement
59
- none: false
60
53
  requirements:
61
- - - ~>
54
+ - - "~>"
62
55
  - !ruby/object:Gem::Version
63
56
  version: '1.4'
57
+ - !ruby/object:Gem::Dependency
58
+ name: connection_pool
59
+ requirement: !ruby/object:Gem::Requirement
60
+ requirements:
61
+ - - "~>"
62
+ - !ruby/object:Gem::Version
63
+ version: 2.0.0
64
+ type: :runtime
65
+ prerelease: false
66
+ version_requirements: !ruby/object:Gem::Requirement
67
+ requirements:
68
+ - - "~>"
69
+ - !ruby/object:Gem::Version
70
+ version: 2.0.0
64
71
  - !ruby/object:Gem::Dependency
65
72
  name: rspec
66
73
  requirement: !ruby/object:Gem::Requirement
67
- none: false
68
74
  requirements:
69
- - - ~>
75
+ - - "~>"
70
76
  - !ruby/object:Gem::Version
71
77
  version: '2.7'
72
78
  type: :development
73
79
  prerelease: false
74
80
  version_requirements: !ruby/object:Gem::Requirement
75
- none: false
76
81
  requirements:
77
- - - ~>
82
+ - - "~>"
78
83
  - !ruby/object:Gem::Version
79
84
  version: '2.7'
80
85
  - !ruby/object:Gem::Dependency
81
86
  name: yard
82
87
  requirement: !ruby/object:Gem::Requirement
83
- none: false
84
88
  requirements:
85
- - - ! '>='
89
+ - - ">="
86
90
  - !ruby/object:Gem::Version
87
91
  version: '0.7'
88
92
  type: :development
89
93
  prerelease: false
90
94
  version_requirements: !ruby/object:Gem::Requirement
91
- none: false
92
95
  requirements:
93
- - - ! '>='
96
+ - - ">="
94
97
  - !ruby/object:Gem::Version
95
98
  version: '0.7'
96
99
  - !ruby/object:Gem::Dependency
97
100
  name: rake
98
101
  requirement: !ruby/object:Gem::Requirement
99
- none: false
100
102
  requirements:
101
- - - ! '>='
103
+ - - ">="
102
104
  - !ruby/object:Gem::Version
103
105
  version: '0.9'
104
106
  type: :development
105
107
  prerelease: false
106
108
  version_requirements: !ruby/object:Gem::Requirement
107
- none: false
108
109
  requirements:
109
- - - ! '>='
110
+ - - ">="
110
111
  - !ruby/object:Gem::Version
111
112
  version: '0.9'
112
113
  description: Pling is a notification framework that supports multiple gateways. Currently
@@ -119,8 +120,8 @@ executables: []
119
120
  extensions: []
120
121
  extra_rdoc_files: []
121
122
  files:
122
- - .gitignore
123
- - .travis.yml
123
+ - ".gitignore"
124
+ - ".travis.yml"
124
125
  - Gemfile
125
126
  - Guardfile
126
127
  - LICENSE
@@ -162,27 +163,26 @@ files:
162
163
  - spec/spec_helper.rb
163
164
  homepage: http://flinc.github.com/pling
164
165
  licenses: []
166
+ metadata: {}
165
167
  post_install_message:
166
168
  rdoc_options: []
167
169
  require_paths:
168
170
  - lib
169
171
  required_ruby_version: !ruby/object:Gem::Requirement
170
- none: false
171
172
  requirements:
172
- - - ! '>='
173
+ - - ">="
173
174
  - !ruby/object:Gem::Version
174
175
  version: '0'
175
176
  required_rubygems_version: !ruby/object:Gem::Requirement
176
- none: false
177
177
  requirements:
178
- - - ! '>='
178
+ - - ">="
179
179
  - !ruby/object:Gem::Version
180
180
  version: '0'
181
181
  requirements: []
182
182
  rubyforge_project:
183
- rubygems_version: 1.8.25
183
+ rubygems_version: 2.4.6
184
184
  signing_key:
185
- specification_version: 3
185
+ specification_version: 4
186
186
  summary: Pling is a notification framework that supports multiple gateways
187
187
  test_files:
188
188
  - spec/pling/.DS_Store