notifiable-apns-grocer 0.1.1 → 0.2.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- checksums.yaml +4 -4
- data/README.md +1 -27
- data/Rakefile +14 -0
- data/lib/notifiable/apns/grocer/stream.rb +47 -20
- data/lib/notifiable/apns/grocer/version.rb +1 -1
- data/notifiable-apns-grocer.gemspec +3 -1
- data/spec/grocer_spec.rb +15 -1
- data/spec/spec_helper.rb +3 -3
- metadata +32 -4
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: ec911dcc2570ab9c8a271321f303db764b7b62be
|
4
|
+
data.tar.gz: b96d35f7daefc693e0198727077184b1e1b1b5cf
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 126caf702a911701e0063a151b418d0664674ed975561b85c53b3ac4d75d261aee3058196b3e6423ce65676522d455a573f6251e90d1ffb1ad30b3ceb5acbeaa
|
7
|
+
data.tar.gz: 8e1167a5e9d16f288baaf31306f588165b5722f5af44c1e05f92066b183d49fc3bc52e0fb0dda264d5c36428aa4ab0af8b7de1727dfafe9c984f019e8c9b44c9
|
data/README.md
CHANGED
@@ -1,29 +1,3 @@
|
|
1
1
|
# Notifiable::Apns::Grocer
|
2
2
|
|
3
|
-
|
4
|
-
|
5
|
-
## Installation
|
6
|
-
|
7
|
-
Add this line to your application's Gemfile:
|
8
|
-
|
9
|
-
gem 'notifiable-apns-grocer'
|
10
|
-
|
11
|
-
And then execute:
|
12
|
-
|
13
|
-
$ bundle
|
14
|
-
|
15
|
-
Or install it yourself as:
|
16
|
-
|
17
|
-
$ gem install notifiable-apns-grocer
|
18
|
-
|
19
|
-
## Usage
|
20
|
-
|
21
|
-
TODO: Write usage instructions here
|
22
|
-
|
23
|
-
## Contributing
|
24
|
-
|
25
|
-
1. Fork it
|
26
|
-
2. Create your feature branch (`git checkout -b my-new-feature`)
|
27
|
-
3. Commit your changes (`git commit -am 'Add some feature'`)
|
28
|
-
4. Push to the branch (`git push origin my-new-feature`)
|
29
|
-
5. Create new Pull Request
|
3
|
+
Please refer to the [notifiable-rails](https://github.com/FutureWorkshops/notifiable-rails) Readme for further information.
|
data/Rakefile
CHANGED
@@ -1 +1,15 @@
|
|
1
1
|
require "bundler/gem_tasks"
|
2
|
+
require 'rspec/core/rake_task'
|
3
|
+
Dir[File.join(File.dirname(__FILE__), 'lib/tasks/**/*.rake')].each {|f| load f }
|
4
|
+
|
5
|
+
namespace :ci do
|
6
|
+
namespace :test do
|
7
|
+
desc "Run all specs in spec directory (excluding plugin specs)"
|
8
|
+
RSpec::Core::RakeTask.new(:spec)
|
9
|
+
end
|
10
|
+
|
11
|
+
task :prepare
|
12
|
+
|
13
|
+
desc "Run all CI tests"
|
14
|
+
task :test => ['ci:test:spec']
|
15
|
+
end
|
@@ -5,7 +5,9 @@ module Notifiable
|
|
5
5
|
module Apns
|
6
6
|
module Grocer
|
7
7
|
class Stream < Notifiable::NotifierBase
|
8
|
-
|
8
|
+
|
9
|
+
attr_accessor :sandbox, :certificate, :passphrase
|
10
|
+
|
9
11
|
def close
|
10
12
|
super
|
11
13
|
@grocer_pusher = nil
|
@@ -15,35 +17,60 @@ module Notifiable
|
|
15
17
|
protected
|
16
18
|
def enqueue(notification, device_token)
|
17
19
|
|
18
|
-
grocer_notification = ::Grocer::Notification.new(
|
20
|
+
grocer_notification = ::Grocer::Notification.new(
|
21
|
+
device_token: device_token.token,
|
22
|
+
alert: notification.provider_value(device_token.provider, :message),
|
23
|
+
custom: notification.provider_value(device_token.provider, :custom),
|
24
|
+
)
|
25
|
+
|
19
26
|
grocer_pusher.push(grocer_notification) unless Notifiable.delivery_method == :test
|
20
27
|
|
21
28
|
processed(notification, device_token)
|
22
29
|
end
|
23
30
|
|
24
31
|
def flush
|
25
|
-
process_feedback unless
|
32
|
+
process_feedback unless self.test_env?
|
26
33
|
end
|
27
34
|
|
28
|
-
private
|
29
|
-
|
30
|
-
|
31
|
-
|
35
|
+
private
|
36
|
+
def gateway_config
|
37
|
+
{
|
38
|
+
certificate: self.certificate,
|
39
|
+
passphrase: self.passphrase,
|
40
|
+
gateway: self.test_env? ? "localhost" : self.sandbox ? "gateway.sandbox.push.apple.com" : "gateway.push.apple.com",
|
41
|
+
port: 2195,
|
42
|
+
retries: 3
|
43
|
+
}
|
44
|
+
end
|
45
|
+
|
46
|
+
def feedback_config
|
47
|
+
{
|
48
|
+
certificate: self.certificate,
|
49
|
+
passphrase: self.passphrase,
|
50
|
+
gateway: self.test_env? ? "feedback.sandbox.push.apple.com" : "feedback.push.apple.com",
|
51
|
+
port: 2196,
|
52
|
+
retries: 3
|
53
|
+
}
|
54
|
+
end
|
55
|
+
|
56
|
+
def grocer_pusher
|
57
|
+
@grocer_pusher ||= ::Grocer.pusher(gateway_config)
|
58
|
+
end
|
32
59
|
|
33
|
-
|
34
|
-
|
35
|
-
|
60
|
+
def grocer_feedback
|
61
|
+
@grocer_feedback ||= ::Grocer.feedback(feedback_config)
|
62
|
+
end
|
36
63
|
|
37
|
-
|
38
|
-
|
39
|
-
|
40
|
-
|
41
|
-
|
42
|
-
|
43
|
-
|
44
|
-
|
45
|
-
|
46
|
-
|
64
|
+
def process_feedback
|
65
|
+
grocer_feedback.each do |attempt|
|
66
|
+
token = attempt.device_token
|
67
|
+
device_token = DeviceToken.find_by_token(token)
|
68
|
+
if device_token
|
69
|
+
device_token.update_attribute("is_valid", false) if device_token.updated_at < attempt.timestamp
|
70
|
+
Rails.logger.info("Device #{token} (#{device_token.user_id}) failed at #{attempt.timestamp}")
|
71
|
+
end
|
72
|
+
end
|
73
|
+
end
|
47
74
|
end
|
48
75
|
end
|
49
76
|
end
|
@@ -18,14 +18,16 @@ Gem::Specification.new do |spec|
|
|
18
18
|
spec.test_files = spec.files.grep(%r{^(test|spec|features)/})
|
19
19
|
spec.require_paths = ["lib"]
|
20
20
|
|
21
|
-
spec.add_dependency "notifiable-rails"
|
21
|
+
spec.add_dependency "notifiable-rails", ">=0.4.0"
|
22
22
|
spec.add_dependency "grocer"
|
23
23
|
|
24
24
|
spec.add_development_dependency "bundler", "~> 1.3"
|
25
25
|
spec.add_development_dependency "rake"
|
26
26
|
spec.add_development_dependency "rspec"
|
27
27
|
spec.add_development_dependency "simplecov"
|
28
|
+
spec.add_development_dependency "simplecov-rcov"
|
28
29
|
spec.add_development_dependency "sqlite3"
|
29
30
|
spec.add_development_dependency "database_cleaner"
|
31
|
+
spec.add_development_dependency 'ruby-prof'
|
30
32
|
|
31
33
|
end
|
data/spec/grocer_spec.rb
CHANGED
@@ -8,7 +8,7 @@ describe Notifiable::Apns::Grocer::Stream do
|
|
8
8
|
let(:u) { User.new(d) }
|
9
9
|
|
10
10
|
it "sends a single grocer notification" do
|
11
|
-
|
11
|
+
g.env = "test"
|
12
12
|
g.send_notification(n, d)
|
13
13
|
|
14
14
|
Timeout.timeout(2) {
|
@@ -30,6 +30,20 @@ describe Notifiable::Apns::Grocer::Stream do
|
|
30
30
|
}
|
31
31
|
end
|
32
32
|
|
33
|
+
it "supports custom properties" do
|
34
|
+
n.payload = {:apns => {:custom => {:flag => true}}}
|
35
|
+
|
36
|
+
Notifiable.batch do |b|
|
37
|
+
b.add(n, u)
|
38
|
+
end
|
39
|
+
Notifiable::NotificationDeviceToken.count.should == 1
|
40
|
+
|
41
|
+
Timeout.timeout(2) {
|
42
|
+
notification = @grocer.notifications.pop
|
43
|
+
notification.custom[:flag].should == true
|
44
|
+
}
|
45
|
+
end
|
46
|
+
|
33
47
|
end
|
34
48
|
|
35
49
|
User = Struct.new(:device_token) do
|
data/spec/spec_helper.rb
CHANGED
@@ -1,11 +1,13 @@
|
|
1
1
|
ENV['RAILS_ENV'] ||= 'test'
|
2
2
|
|
3
3
|
require 'simplecov'
|
4
|
+
require 'simplecov-rcov'
|
5
|
+
SimpleCov.formatter = SimpleCov::Formatter::RcovFormatter
|
4
6
|
SimpleCov.start do
|
5
|
-
minimum_coverage 80
|
6
7
|
add_filter "/spec/"
|
7
8
|
end
|
8
9
|
|
10
|
+
require 'timeout'
|
9
11
|
require 'database_cleaner'
|
10
12
|
require 'active_record'
|
11
13
|
require 'rails'
|
@@ -36,8 +38,6 @@ RSpec.configure do |config|
|
|
36
38
|
|
37
39
|
@grocer = Grocer.server(port: 2195)
|
38
40
|
@grocer.accept
|
39
|
-
|
40
|
-
Notifiable.apns_gateway = "localhost"
|
41
41
|
}
|
42
42
|
|
43
43
|
config.before(:each) {
|
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: notifiable-apns-grocer
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.
|
4
|
+
version: 0.2.0
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Kamil Kocemba
|
@@ -9,7 +9,7 @@ authors:
|
|
9
9
|
autorequire:
|
10
10
|
bindir: bin
|
11
11
|
cert_chain: []
|
12
|
-
date: 2014-
|
12
|
+
date: 2014-02-09 00:00:00.000000000 Z
|
13
13
|
dependencies:
|
14
14
|
- !ruby/object:Gem::Dependency
|
15
15
|
name: notifiable-rails
|
@@ -17,14 +17,14 @@ dependencies:
|
|
17
17
|
requirements:
|
18
18
|
- - '>='
|
19
19
|
- !ruby/object:Gem::Version
|
20
|
-
version:
|
20
|
+
version: 0.4.0
|
21
21
|
type: :runtime
|
22
22
|
prerelease: false
|
23
23
|
version_requirements: !ruby/object:Gem::Requirement
|
24
24
|
requirements:
|
25
25
|
- - '>='
|
26
26
|
- !ruby/object:Gem::Version
|
27
|
-
version:
|
27
|
+
version: 0.4.0
|
28
28
|
- !ruby/object:Gem::Dependency
|
29
29
|
name: grocer
|
30
30
|
requirement: !ruby/object:Gem::Requirement
|
@@ -95,6 +95,20 @@ dependencies:
|
|
95
95
|
- - '>='
|
96
96
|
- !ruby/object:Gem::Version
|
97
97
|
version: '0'
|
98
|
+
- !ruby/object:Gem::Dependency
|
99
|
+
name: simplecov-rcov
|
100
|
+
requirement: !ruby/object:Gem::Requirement
|
101
|
+
requirements:
|
102
|
+
- - '>='
|
103
|
+
- !ruby/object:Gem::Version
|
104
|
+
version: '0'
|
105
|
+
type: :development
|
106
|
+
prerelease: false
|
107
|
+
version_requirements: !ruby/object:Gem::Requirement
|
108
|
+
requirements:
|
109
|
+
- - '>='
|
110
|
+
- !ruby/object:Gem::Version
|
111
|
+
version: '0'
|
98
112
|
- !ruby/object:Gem::Dependency
|
99
113
|
name: sqlite3
|
100
114
|
requirement: !ruby/object:Gem::Requirement
|
@@ -123,6 +137,20 @@ dependencies:
|
|
123
137
|
- - '>='
|
124
138
|
- !ruby/object:Gem::Version
|
125
139
|
version: '0'
|
140
|
+
- !ruby/object:Gem::Dependency
|
141
|
+
name: ruby-prof
|
142
|
+
requirement: !ruby/object:Gem::Requirement
|
143
|
+
requirements:
|
144
|
+
- - '>='
|
145
|
+
- !ruby/object:Gem::Version
|
146
|
+
version: '0'
|
147
|
+
type: :development
|
148
|
+
prerelease: false
|
149
|
+
version_requirements: !ruby/object:Gem::Requirement
|
150
|
+
requirements:
|
151
|
+
- - '>='
|
152
|
+
- !ruby/object:Gem::Version
|
153
|
+
version: '0'
|
126
154
|
description: Plugin to use Grocer for APNS with Notifiable-Rails
|
127
155
|
email:
|
128
156
|
- kamil@futureworkshops.com
|