notifiable-gcm-spacialdb 0.9.0 → 0.10.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/.gitignore +1 -0
- data/Gemfile +2 -0
- data/Gemfile.lock +141 -89
- data/lib/notifiable/gcm/spacialdb/batch.rb +74 -76
- data/lib/notifiable/gcm/spacialdb/version.rb +1 -1
- data/notifiable-gcm-spacialdb.gemspec +6 -6
- data/spec/batch_spec.rb +41 -80
- data/spec/spec_helper.rb +3 -2
- metadata +15 -27
- data/.ruby-gemset +0 -1
- data/.ruby-version +0 -1
- data/spec/support/db/migrate/20131210115648_create_notifiable_apps.rb +0 -10
- data/spec/support/db/migrate/20131210115649_create_notifiable_device_tokens.rb +0 -19
- data/spec/support/db/migrate/20131210115650_create_notifiable_notifications.rb +0 -16
- data/spec/support/db/migrate/20131210115651_create_notifiable_localized_notifications.rb +0 -22
- data/spec/support/db/migrate/20131210115652_create_notifiable_statuses.rb +0 -12
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 9d6f7c97e0686c9df19b325d26045a5f03778150
|
4
|
+
data.tar.gz: f376083ac33fe4e4e9939e78ab6a5ca1a266c155
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: c79af147476ad3e19d1593c54736c907894c1faf3006abb3ed8a3920bf0bb2d5e914f03204d0a9c4abedbbee36a1519c266bafc2cb051487987011e9aca57e44
|
7
|
+
data.tar.gz: 2117913e0dc1b6d914d6122d3448c979a828b67da6e5fd6764a48f9ed3a3d24c3577ba5e338522a3645d8af2dcefb0f5bad7858d411bbeaf355bf99d2e2e0965
|
data/.gitignore
CHANGED
data/Gemfile
CHANGED
data/Gemfile.lock
CHANGED
@@ -1,98 +1,141 @@
|
|
1
1
|
PATH
|
2
2
|
remote: .
|
3
3
|
specs:
|
4
|
-
notifiable-gcm-spacialdb (0.
|
5
|
-
gcm (~> 0.
|
6
|
-
notifiable-rails (>= 0.
|
4
|
+
notifiable-gcm-spacialdb (0.10.0)
|
5
|
+
gcm (~> 0.1.1)
|
6
|
+
notifiable-rails (>= 0.26.3)
|
7
7
|
|
8
8
|
GEM
|
9
9
|
remote: https://rubygems.org/
|
10
10
|
specs:
|
11
|
-
|
12
|
-
actionpack (=
|
13
|
-
|
11
|
+
actioncable (5.1.5)
|
12
|
+
actionpack (= 5.1.5)
|
13
|
+
nio4r (~> 2.0)
|
14
|
+
websocket-driver (~> 0.6.1)
|
15
|
+
actionmailer (5.1.5)
|
16
|
+
actionpack (= 5.1.5)
|
17
|
+
actionview (= 5.1.5)
|
18
|
+
activejob (= 5.1.5)
|
14
19
|
mail (~> 2.5, >= 2.5.4)
|
15
|
-
|
16
|
-
|
17
|
-
|
18
|
-
|
19
|
-
rack
|
20
|
-
|
21
|
-
|
20
|
+
rails-dom-testing (~> 2.0)
|
21
|
+
actionpack (5.1.5)
|
22
|
+
actionview (= 5.1.5)
|
23
|
+
activesupport (= 5.1.5)
|
24
|
+
rack (~> 2.0)
|
25
|
+
rack-test (>= 0.6.3)
|
26
|
+
rails-dom-testing (~> 2.0)
|
27
|
+
rails-html-sanitizer (~> 1.0, >= 1.0.2)
|
28
|
+
actionview (5.1.5)
|
29
|
+
activesupport (= 5.1.5)
|
22
30
|
builder (~> 3.1)
|
23
|
-
|
24
|
-
|
25
|
-
|
26
|
-
|
27
|
-
|
28
|
-
|
29
|
-
|
30
|
-
|
31
|
-
|
32
|
-
|
33
|
-
|
31
|
+
erubi (~> 1.4)
|
32
|
+
rails-dom-testing (~> 2.0)
|
33
|
+
rails-html-sanitizer (~> 1.0, >= 1.0.3)
|
34
|
+
activejob (5.1.5)
|
35
|
+
activesupport (= 5.1.5)
|
36
|
+
globalid (>= 0.3.6)
|
37
|
+
activemodel (5.1.5)
|
38
|
+
activesupport (= 5.1.5)
|
39
|
+
activerecord (5.1.5)
|
40
|
+
activemodel (= 5.1.5)
|
41
|
+
activesupport (= 5.1.5)
|
42
|
+
arel (~> 8.0)
|
43
|
+
activerecord-postgis-adapter (5.2.1)
|
44
|
+
activerecord (~> 5.1)
|
45
|
+
rgeo-activerecord (~> 6.0)
|
46
|
+
activesupport (5.1.5)
|
47
|
+
concurrent-ruby (~> 1.0, >= 1.0.2)
|
48
|
+
i18n (~> 0.7)
|
34
49
|
minitest (~> 5.1)
|
35
|
-
thread_safe (~> 0.1)
|
36
50
|
tzinfo (~> 1.1)
|
37
|
-
addressable (2.
|
38
|
-
|
39
|
-
|
40
|
-
|
41
|
-
|
42
|
-
|
43
|
-
|
44
|
-
|
45
|
-
|
51
|
+
addressable (2.5.2)
|
52
|
+
public_suffix (>= 2.0.2, < 4.0)
|
53
|
+
arel (8.0.0)
|
54
|
+
builder (3.2.3)
|
55
|
+
byebug (10.0.1)
|
56
|
+
concurrent-ruby (1.0.5)
|
57
|
+
crack (0.4.3)
|
58
|
+
safe_yaml (~> 1.0.0)
|
59
|
+
crass (1.0.3)
|
46
60
|
database_cleaner (1.2.0)
|
47
|
-
diff-lcs (1.
|
48
|
-
docile (1.1.
|
49
|
-
|
50
|
-
gcm (0.
|
61
|
+
diff-lcs (1.3)
|
62
|
+
docile (1.1.5)
|
63
|
+
erubi (1.7.1)
|
64
|
+
gcm (0.1.1)
|
51
65
|
httparty
|
52
66
|
json
|
53
|
-
|
54
|
-
|
67
|
+
globalid (0.4.1)
|
68
|
+
activesupport (>= 4.2.0)
|
69
|
+
httparty (0.16.1)
|
55
70
|
multi_xml (>= 0.5.2)
|
56
|
-
i18n (0.
|
57
|
-
|
58
|
-
|
59
|
-
|
60
|
-
|
61
|
-
|
62
|
-
|
63
|
-
|
64
|
-
|
65
|
-
|
66
|
-
|
67
|
-
|
68
|
-
|
69
|
-
|
70
|
-
|
71
|
-
|
72
|
-
|
73
|
-
|
74
|
-
|
75
|
-
|
76
|
-
|
77
|
-
|
78
|
-
|
79
|
-
|
80
|
-
|
81
|
-
|
82
|
-
|
83
|
-
|
71
|
+
i18n (0.9.5)
|
72
|
+
concurrent-ruby (~> 1.0)
|
73
|
+
json (2.1.0)
|
74
|
+
loofah (2.2.1)
|
75
|
+
crass (~> 1.0.2)
|
76
|
+
nokogiri (>= 1.5.9)
|
77
|
+
mail (2.7.0)
|
78
|
+
mini_mime (>= 0.1.1)
|
79
|
+
method_source (0.9.0)
|
80
|
+
mini_mime (1.0.0)
|
81
|
+
mini_portile2 (2.3.0)
|
82
|
+
minitest (5.11.3)
|
83
|
+
multi_json (1.13.1)
|
84
|
+
multi_xml (0.6.0)
|
85
|
+
nio4r (2.3.0)
|
86
|
+
nokogiri (1.8.2)
|
87
|
+
mini_portile2 (~> 2.3.0)
|
88
|
+
notifiable-rails (0.26.3)
|
89
|
+
activerecord-postgis-adapter
|
90
|
+
pg
|
91
|
+
rails
|
92
|
+
pg (1.0.0)
|
93
|
+
public_suffix (3.0.2)
|
94
|
+
rack (2.0.4)
|
95
|
+
rack-test (0.8.3)
|
96
|
+
rack (>= 1.0, < 3)
|
97
|
+
rails (5.1.5)
|
98
|
+
actioncable (= 5.1.5)
|
99
|
+
actionmailer (= 5.1.5)
|
100
|
+
actionpack (= 5.1.5)
|
101
|
+
actionview (= 5.1.5)
|
102
|
+
activejob (= 5.1.5)
|
103
|
+
activemodel (= 5.1.5)
|
104
|
+
activerecord (= 5.1.5)
|
105
|
+
activesupport (= 5.1.5)
|
106
|
+
bundler (>= 1.3.0)
|
107
|
+
railties (= 5.1.5)
|
108
|
+
sprockets-rails (>= 2.0.0)
|
109
|
+
rails-dom-testing (2.0.3)
|
110
|
+
activesupport (>= 4.2.0)
|
111
|
+
nokogiri (>= 1.6)
|
112
|
+
rails-html-sanitizer (1.0.3)
|
113
|
+
loofah (~> 2.0)
|
114
|
+
railties (5.1.5)
|
115
|
+
actionpack (= 5.1.5)
|
116
|
+
activesupport (= 5.1.5)
|
117
|
+
method_source
|
84
118
|
rake (>= 0.8.7)
|
85
119
|
thor (>= 0.18.1, < 2.0)
|
86
120
|
rake (10.1.1)
|
87
|
-
|
88
|
-
|
89
|
-
|
90
|
-
|
91
|
-
rspec
|
92
|
-
|
93
|
-
|
94
|
-
|
95
|
-
|
121
|
+
rgeo (1.0.0)
|
122
|
+
rgeo-activerecord (6.0.0)
|
123
|
+
activerecord (~> 5.0)
|
124
|
+
rgeo (~> 1.0)
|
125
|
+
rspec (3.7.0)
|
126
|
+
rspec-core (~> 3.7.0)
|
127
|
+
rspec-expectations (~> 3.7.0)
|
128
|
+
rspec-mocks (~> 3.7.0)
|
129
|
+
rspec-core (3.7.1)
|
130
|
+
rspec-support (~> 3.7.0)
|
131
|
+
rspec-expectations (3.7.0)
|
132
|
+
diff-lcs (>= 1.2.0, < 2.0)
|
133
|
+
rspec-support (~> 3.7.0)
|
134
|
+
rspec-mocks (3.7.0)
|
135
|
+
diff-lcs (>= 1.2.0, < 2.0)
|
136
|
+
rspec-support (~> 3.7.0)
|
137
|
+
rspec-support (3.7.1)
|
138
|
+
safe_yaml (1.0.4)
|
96
139
|
simplecov (0.8.2)
|
97
140
|
docile (~> 1.1.0)
|
98
141
|
multi_json
|
@@ -100,21 +143,24 @@ GEM
|
|
100
143
|
simplecov-html (0.8.0)
|
101
144
|
simplecov-rcov (0.2.3)
|
102
145
|
simplecov (>= 0.4.1)
|
103
|
-
sprockets (3.
|
146
|
+
sprockets (3.7.1)
|
104
147
|
concurrent-ruby (~> 1.0)
|
105
148
|
rack (> 1, < 3)
|
106
|
-
sprockets-rails (2.
|
107
|
-
actionpack (>=
|
108
|
-
activesupport (>=
|
109
|
-
sprockets (>=
|
110
|
-
sqlite3 (1.3.
|
111
|
-
thor (0.
|
112
|
-
thread_safe (0.3.
|
113
|
-
tzinfo (1.2.
|
149
|
+
sprockets-rails (3.2.1)
|
150
|
+
actionpack (>= 4.0)
|
151
|
+
activesupport (>= 4.0)
|
152
|
+
sprockets (>= 3.0.0)
|
153
|
+
sqlite3 (1.3.13)
|
154
|
+
thor (0.20.0)
|
155
|
+
thread_safe (0.3.6)
|
156
|
+
tzinfo (1.2.5)
|
114
157
|
thread_safe (~> 0.1)
|
115
|
-
webmock (1.17.
|
158
|
+
webmock (1.17.4)
|
116
159
|
addressable (>= 2.2.7)
|
117
160
|
crack (>= 0.3.2)
|
161
|
+
websocket-driver (0.6.5)
|
162
|
+
websocket-extensions (>= 0.1.0)
|
163
|
+
websocket-extensions (0.1.3)
|
118
164
|
|
119
165
|
PLATFORMS
|
120
166
|
ruby
|
@@ -125,8 +171,14 @@ DEPENDENCIES
|
|
125
171
|
database_cleaner (~> 1.2.0)
|
126
172
|
notifiable-gcm-spacialdb!
|
127
173
|
rake (~> 10.1.1)
|
128
|
-
rspec (~>
|
174
|
+
rspec (~> 3.7)
|
129
175
|
simplecov (~> 0.8.2)
|
130
176
|
simplecov-rcov (~> 0.2.3)
|
131
|
-
sqlite3
|
177
|
+
sqlite3
|
132
178
|
webmock (~> 1.17.1)
|
179
|
+
|
180
|
+
RUBY VERSION
|
181
|
+
ruby 2.4.3p205
|
182
|
+
|
183
|
+
BUNDLED WITH
|
184
|
+
1.16.1
|
@@ -12,90 +12,88 @@ module Notifiable
|
|
12
12
|
@batch_size || 1000
|
13
13
|
end
|
14
14
|
|
15
|
-
def
|
16
|
-
|
17
|
-
@batch = []
|
15
|
+
def batch
|
16
|
+
@batch ||= []
|
18
17
|
end
|
19
18
|
|
20
|
-
protected
|
21
|
-
|
22
|
-
|
23
|
-
|
24
|
-
|
25
|
-
|
26
|
-
|
27
|
-
|
28
|
-
|
29
|
-
|
30
|
-
|
19
|
+
protected
|
20
|
+
|
21
|
+
def enqueue(device_token, notification)
|
22
|
+
raise "API Key missing" if @api_key.nil?
|
23
|
+
|
24
|
+
@batch_notification = notification
|
25
|
+
batch << device_token
|
26
|
+
send_batch(notification) if batch.count >= batch_size
|
27
|
+
end
|
28
|
+
|
29
|
+
def flush
|
30
|
+
send_batch(@batch_notification) unless batch.empty?
|
31
|
+
end
|
31
32
|
|
32
33
|
private
|
33
|
-
|
34
|
-
|
35
|
-
|
36
|
-
|
37
|
-
|
38
|
-
|
39
|
-
data = {:message => notification.message}.merge(notification.send_params)
|
40
|
-
response = gcm.send_notification(@batch.collect{|dt| dt.token}, {:data => data})
|
41
|
-
|
42
|
-
if response[:status_code] == 200
|
43
|
-
process_success_response(response)
|
44
|
-
else
|
45
|
-
Rails.logger.error "Sending notification id: #{notification.id} code: #{response[:status_code]} response: #{response[:response]}"
|
46
|
-
end
|
47
|
-
end
|
48
|
-
@batch = []
|
49
|
-
end
|
50
|
-
|
51
|
-
def process_success_response(response)
|
52
|
-
body = JSON.parse(response.fetch(:body, "{}"))
|
53
|
-
results = body.fetch("results", [])
|
54
|
-
results.each_with_index do |result, i|
|
55
|
-
dt = @batch[i]
|
56
|
-
|
57
|
-
# Remove the token if it is marked NotRegistered (user deleted the App for example)
|
58
|
-
if ["InvalidRegistration", "NotRegistered"].include? result["error"]
|
59
|
-
dt.update_attribute('is_valid', false)
|
60
|
-
|
61
|
-
# Process canonical IDs
|
62
|
-
elsif result["registration_id"] && Notifiable::DeviceToken.exists?(:token => result["registration_id"])
|
63
|
-
dt.update_attribute('is_valid', false)
|
64
|
-
elsif result["registration_id"]
|
65
|
-
dt.update_attribute('token', result["registration_id"])
|
66
|
-
end
|
34
|
+
|
35
|
+
def send_batch(notification)
|
36
|
+
gcm = ::GCM.new(@api_key)
|
37
|
+
|
38
|
+
data = {:message => notification.message}.merge(notification.send_params)
|
39
|
+
response = gcm.send_notification(batch.collect{|dt| dt.token}, {:data => data})
|
67
40
|
|
68
|
-
|
69
|
-
|
70
|
-
|
41
|
+
if response[:status_code] == 200
|
42
|
+
process_success_response(response)
|
43
|
+
else
|
44
|
+
Rails.logger.error "Sending notification id: #{notification.id} code: #{response[:status_code]} response: #{response[:response]}"
|
45
|
+
end
|
46
|
+
@batch = []
|
47
|
+
end
|
71
48
|
|
72
|
-
|
73
|
-
|
74
|
-
|
75
|
-
|
76
|
-
|
77
|
-
|
78
|
-
|
79
|
-
|
80
|
-
|
81
|
-
|
82
|
-
|
83
|
-
|
84
|
-
|
85
|
-
|
86
|
-
when "InvalidTtl"
|
87
|
-
7
|
88
|
-
when "Unavailable"
|
89
|
-
8
|
90
|
-
when "InternalServerError"
|
91
|
-
9
|
92
|
-
when "InvalidPackageName"
|
93
|
-
10
|
94
|
-
else
|
95
|
-
0
|
49
|
+
def process_success_response(response)
|
50
|
+
body = JSON.parse(response.fetch(:body, "{}"))
|
51
|
+
results = body.fetch("results", [])
|
52
|
+
results.each_with_index do |result, i|
|
53
|
+
dt = batch[i]
|
54
|
+
|
55
|
+
# Remove the token if it is marked NotRegistered (user deleted the App for example)
|
56
|
+
if ["InvalidRegistration", "NotRegistered"].include? result["error"]
|
57
|
+
dt.destroy
|
58
|
+
# Process canonical IDs
|
59
|
+
elsif result["registration_id"] && Notifiable::DeviceToken.exists?(:token => result["registration_id"])
|
60
|
+
dt.destroy
|
61
|
+
elsif result["registration_id"]
|
62
|
+
dt.update_attribute('token', result["registration_id"])
|
96
63
|
end
|
64
|
+
|
65
|
+
processed(dt, error_code(result["error"]))
|
66
|
+
end
|
67
|
+
|
68
|
+
end
|
69
|
+
|
70
|
+
def error_code(error_message)
|
71
|
+
case error_message
|
72
|
+
when "MissingRegistration"
|
73
|
+
1
|
74
|
+
when "InvalidRegistration"
|
75
|
+
2
|
76
|
+
when "MismatchSenderId"
|
77
|
+
3
|
78
|
+
when "NotRegistered"
|
79
|
+
4
|
80
|
+
when "MessageTooBig"
|
81
|
+
5
|
82
|
+
when "InvalidDataKey"
|
83
|
+
6
|
84
|
+
when "InvalidTtl"
|
85
|
+
7
|
86
|
+
when "Unavailable"
|
87
|
+
8
|
88
|
+
when "InternalServerError"
|
89
|
+
9
|
90
|
+
when "InvalidPackageName"
|
91
|
+
10
|
92
|
+
else
|
93
|
+
0
|
97
94
|
end
|
98
|
-
|
95
|
+
end
|
96
|
+
end
|
99
97
|
end
|
100
98
|
end
|
101
99
|
end
|
@@ -9,8 +9,8 @@ Gem::Specification.new do |spec|
|
|
9
9
|
spec.authors = ["Kamil Kocemba", "Matt Brooke-Smith"]
|
10
10
|
spec.email = ["kamil@futureworkshops.com", "matt@futureworkshops.com"]
|
11
11
|
spec.homepage = "http://www.futureworkshops.com"
|
12
|
-
spec.description = "Plugin to use GCM with Notifiable
|
13
|
-
spec.summary = "Plugin to use GCM with Notifiable
|
12
|
+
spec.description = "Plugin to use GCM with Notifiable"
|
13
|
+
spec.summary = "Plugin to use GCM with Notifiable"
|
14
14
|
spec.license = "Apache 2.0"
|
15
15
|
|
16
16
|
spec.files = `git ls-files`.split($/)
|
@@ -18,15 +18,15 @@ 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", ">=0.
|
22
|
-
spec.add_dependency "gcm",
|
21
|
+
spec.add_dependency "notifiable-rails", ">=0.26.3"
|
22
|
+
spec.add_dependency "gcm", '~> 0.1.1'
|
23
23
|
|
24
24
|
spec.add_development_dependency "bundler", "~> 1.3"
|
25
25
|
spec.add_development_dependency "rake", "~> 10.1.1"
|
26
|
-
spec.add_development_dependency "rspec",
|
26
|
+
spec.add_development_dependency "rspec", '~> 3.7'
|
27
27
|
spec.add_development_dependency "simplecov", "~> 0.8.2"
|
28
28
|
spec.add_development_dependency "simplecov-rcov", "~> 0.2.3"
|
29
|
-
spec.add_development_dependency "sqlite3"
|
29
|
+
spec.add_development_dependency "sqlite3"
|
30
30
|
spec.add_development_dependency "database_cleaner", "~> 1.2.0"
|
31
31
|
spec.add_development_dependency "webmock", "~> 1.17.1"
|
32
32
|
spec.add_development_dependency "byebug"
|
data/spec/batch_spec.rb
CHANGED
@@ -2,89 +2,50 @@ require 'spec_helper'
|
|
2
2
|
|
3
3
|
describe Notifiable::Gcm::Spacialdb::Batch do
|
4
4
|
|
5
|
-
let(:
|
6
|
-
let(:
|
7
|
-
let
|
5
|
+
let(:app_configuration) { {save_notification_statuses: true, gcm: {api_key: 'abc123'}} }
|
6
|
+
let(:a) { Notifiable::App.create gcm_api_key: 'abc123', configuration: app_configuration }
|
7
|
+
let(:n1) { Notifiable::Notification.create(app: a, message: 'Test message', parameters: {flag: true} ) }
|
8
8
|
let(:d) { Notifiable::DeviceToken.create(:token => "ABC123", :provider => :gcm, :app => a, :locale => 'en') }
|
9
|
+
let!(:stubbed_request) { stub_request(:post, "https://gcm-http.googleapis.com/gcm/send").with(body: request_body).to_return(body: response_body) }
|
10
|
+
let(:request_body) { }
|
11
|
+
let(:response_body) { }
|
9
12
|
|
10
|
-
|
11
|
-
|
12
|
-
end
|
13
|
-
|
14
|
-
it "sends a single gcm notification" do
|
15
|
-
stub_request(:post, "https://android.googleapis.com/gcm/send").to_return(:body => '{ "multicast_id": 108, "success": 1, "failure": 0, "canonical_ids": 0, "results": [{ "message_id": "1:08" }]}')
|
13
|
+
describe '#batch' do
|
14
|
+
before(:each) { n1.batch {|n| n.add_device_token(d)} }
|
16
15
|
|
17
|
-
|
18
|
-
|
19
|
-
|
20
|
-
|
21
|
-
|
22
|
-
|
23
|
-
|
24
|
-
|
25
|
-
|
26
|
-
|
16
|
+
context 'single' do
|
17
|
+
let(:request_body) { "{\"registration_ids\":[\"ABC123\"],\"data\":{\"message\":\"Test message\",\"flag\":true,\"n_id\":1}}" }
|
18
|
+
let(:response_body) { '{ "multicast_id": 108, "success": 1, "failure": 0, "canonical_ids": 0, "results": [{ "message_id": "1:08" }]}' }
|
19
|
+
it { expect(Notifiable::NotificationStatus.count).to eq 1 }
|
20
|
+
it { expect(Notifiable::NotificationStatus.first.status).to eq 0 }
|
21
|
+
end
|
22
|
+
|
23
|
+
context 'custom attributes' do
|
24
|
+
let(:request_body) { "{\"registration_ids\":[\"ABC123\"],\"data\":{\"message\":\"Test message\",\"flag\":true,\"n_id\":1}}" }
|
25
|
+
let(:response_body) { '{ "multicast_id": 108, "success": 1, "failure": 0, "canonical_ids": 0, "results": [{ "message_id": "1:08" }]}' }
|
26
|
+
it { expect(Notifiable::NotificationStatus.count).to eq 1 }
|
27
|
+
it { expect(Notifiable::NotificationStatus.first.status).to eq 0 }
|
28
|
+
end
|
29
|
+
|
30
|
+
context 'deletes an unregistered token' do
|
31
|
+
let(:request_body) { "{\"registration_ids\":[\"ABC123\"],\"data\":{\"message\":\"Test message\",\"flag\":true,\"n_id\":1}}" }
|
32
|
+
let(:response_body) { '{ "multicast_id": 108, "success": 0, "failure": 1, "canonical_ids": 0, "results": [{ "error": "NotRegistered" }]}' }
|
33
|
+
it { expect(Notifiable::NotificationStatus.count).to eq 0 }
|
34
|
+
it { expect(Notifiable::DeviceToken.count).to eq 0 }
|
35
|
+
end
|
36
|
+
|
37
|
+
context 'id change' do
|
38
|
+
let(:request_body) { "{\"registration_ids\":[\"ABC123\"],\"data\":{\"message\":\"Test message\",\"flag\":true,\"n_id\":1}}" }
|
39
|
+
let(:response_body) { '{ "multicast_id": 108, "success": 1, "failure": 0, "canonical_ids": 1, "results": [{ "message_id": "1:08", "registration_id": "GHJ12345" }]}' }
|
40
|
+
it { expect(Notifiable::NotificationStatus.count).to eq 1 }
|
41
|
+
it { expect(Notifiable::DeviceToken.count).to eq 1 }
|
42
|
+
it { expect(Notifiable::DeviceToken.first.token).to eq "GHJ12345" }
|
43
|
+
end
|
44
|
+
|
45
|
+
context 'bad key' do
|
46
|
+
let!(:stubbed_request) { stub_request(:post, "https://gcm-http.googleapis.com/gcm/send").to_return(body: '<html>Message</html>', status: 401) }
|
47
|
+
it { expect(Notifiable::NotificationStatus.count).to eq 0 }
|
48
|
+
end
|
27
49
|
|
28
|
-
n1.batch {|n| n.add_device_token(d)}
|
29
|
-
|
30
|
-
|
31
|
-
Notifiable::NotificationStatus.count.should == 1
|
32
|
-
Notifiable::NotificationStatus.first.status = 0
|
33
50
|
end
|
34
|
-
|
35
|
-
it "marks a unregistered token as invalid" do
|
36
|
-
stub_request(:post, "https://android.googleapis.com/gcm/send").to_return(:body => '{ "multicast_id": 108, "success": 0, "failure": 1, "canonical_ids": 0, "results": [{ "error": "NotRegistered" }]}')
|
37
|
-
|
38
|
-
n1.batch {|n| n.add_device_token(d)}
|
39
|
-
|
40
|
-
Notifiable::NotificationStatus.count.should == 1
|
41
|
-
Notifiable::NotificationStatus.first.status = 4
|
42
|
-
d.is_valid.should == false
|
43
|
-
end
|
44
|
-
|
45
|
-
it "marks an invalid token as invalid" do
|
46
|
-
stub_request(:post, "https://android.googleapis.com/gcm/send").to_return(:body => '{ "multicast_id": 108, "success": 0, "failure": 1, "canonical_ids": 0, "results": [{ "error": "InvalidRegistration" }]}')
|
47
|
-
|
48
|
-
n1.batch {|n| n.add_device_token(d)}
|
49
|
-
|
50
|
-
Notifiable::NotificationStatus.count.should == 1
|
51
|
-
Notifiable::NotificationStatus.first.status = 2
|
52
|
-
d.is_valid.should == false
|
53
|
-
end
|
54
|
-
|
55
|
-
it "updates a token to the canonical ID if it does not exist" do
|
56
|
-
stub_request(:post, "https://android.googleapis.com/gcm/send").to_return(:body => '{ "multicast_id": 108, "success": 1, "failure": 0, "canonical_ids": 1, "results": [{ "message_id": "1:08", "registration_id": "GHJ12345" }]}')
|
57
|
-
|
58
|
-
n1.batch {|n| n.add_device_token(d)}
|
59
|
-
|
60
|
-
Notifiable::NotificationStatus.count.should == 1
|
61
|
-
Notifiable::NotificationStatus.first.status = 0
|
62
|
-
Notifiable::DeviceToken.count.should == 1
|
63
|
-
d.token.should eql "GHJ12345"
|
64
|
-
end
|
65
|
-
|
66
|
-
|
67
|
-
# it "marks a token as invalid if the canonical ID already exists" do
|
68
|
-
# Notifiable::DeviceToken.create(:token => "GHJ12345", :provider => :gcm)
|
69
|
-
|
70
|
-
# stub_request(:post, "https://android.googleapis.com/gcm/send").to_return(:body => '{ "multicast_id": 108, "success": 1, "failure": 0, "canonical_ids": 1, "results": [{ "message_id": "1:08", "registration_id": "GHJ12345" }]}')
|
71
|
-
|
72
|
-
# n1.batch do |n|
|
73
|
-
# n.add_device_token(d)
|
74
|
-
# end
|
75
|
-
|
76
|
-
# Notifiable::NotificationStatus.count.should == 1
|
77
|
-
# Notifiable::NotificationStatus.first.status = 0
|
78
|
-
# Notifiable::DeviceToken.count.should == 2
|
79
|
-
# d.is_valid.should be_false
|
80
|
-
# end
|
81
|
-
|
82
|
-
it "deals gracefully with an unauthenticated key" do
|
83
|
-
stub_request(:post, "https://android.googleapis.com/gcm/send").to_return(:body => '<html>Message</html>', :status => 401)
|
84
|
-
|
85
|
-
n1.batch {|n| n.add_device_token(d)}
|
86
|
-
|
87
|
-
Notifiable::NotificationStatus.count.should == 0
|
88
|
-
end
|
89
|
-
|
90
51
|
end
|
data/spec/spec_helper.rb
CHANGED
@@ -17,7 +17,7 @@ require 'byebug'
|
|
17
17
|
require File.expand_path("../../lib/notifiable/gcm/spacialdb", __FILE__)
|
18
18
|
Dir["#{File.dirname(__FILE__)}/support/**/*.rb"].each { |f| require f }
|
19
19
|
|
20
|
-
db_path = 'spec/
|
20
|
+
db_path = 'spec/test.sqlite3'
|
21
21
|
DatabaseCleaner.strategy = :truncation
|
22
22
|
|
23
23
|
Rails.logger = Logger.new(STDOUT)
|
@@ -40,7 +40,8 @@ RSpec.configure do |config|
|
|
40
40
|
)
|
41
41
|
|
42
42
|
ActiveRecord::Migration.verbose = false
|
43
|
-
|
43
|
+
notifiable_rails_path = Gem.loaded_specs['notifiable-rails'].full_gem_path
|
44
|
+
ActiveRecord::Migrator.migrate File.join(notifiable_rails_path, 'db', 'migrate')
|
44
45
|
|
45
46
|
# todo start stub
|
46
47
|
}
|
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: notifiable-gcm-spacialdb
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.
|
4
|
+
version: 0.10.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:
|
12
|
+
date: 2018-03-21 00:00:00.000000000 Z
|
13
13
|
dependencies:
|
14
14
|
- !ruby/object:Gem::Dependency
|
15
15
|
name: notifiable-rails
|
@@ -17,28 +17,28 @@ dependencies:
|
|
17
17
|
requirements:
|
18
18
|
- - ">="
|
19
19
|
- !ruby/object:Gem::Version
|
20
|
-
version: 0.
|
20
|
+
version: 0.26.3
|
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: 0.
|
27
|
+
version: 0.26.3
|
28
28
|
- !ruby/object:Gem::Dependency
|
29
29
|
name: gcm
|
30
30
|
requirement: !ruby/object:Gem::Requirement
|
31
31
|
requirements:
|
32
32
|
- - "~>"
|
33
33
|
- !ruby/object:Gem::Version
|
34
|
-
version: 0.
|
34
|
+
version: 0.1.1
|
35
35
|
type: :runtime
|
36
36
|
prerelease: false
|
37
37
|
version_requirements: !ruby/object:Gem::Requirement
|
38
38
|
requirements:
|
39
39
|
- - "~>"
|
40
40
|
- !ruby/object:Gem::Version
|
41
|
-
version: 0.
|
41
|
+
version: 0.1.1
|
42
42
|
- !ruby/object:Gem::Dependency
|
43
43
|
name: bundler
|
44
44
|
requirement: !ruby/object:Gem::Requirement
|
@@ -73,14 +73,14 @@ dependencies:
|
|
73
73
|
requirements:
|
74
74
|
- - "~>"
|
75
75
|
- !ruby/object:Gem::Version
|
76
|
-
version:
|
76
|
+
version: '3.7'
|
77
77
|
type: :development
|
78
78
|
prerelease: false
|
79
79
|
version_requirements: !ruby/object:Gem::Requirement
|
80
80
|
requirements:
|
81
81
|
- - "~>"
|
82
82
|
- !ruby/object:Gem::Version
|
83
|
-
version:
|
83
|
+
version: '3.7'
|
84
84
|
- !ruby/object:Gem::Dependency
|
85
85
|
name: simplecov
|
86
86
|
requirement: !ruby/object:Gem::Requirement
|
@@ -113,16 +113,16 @@ dependencies:
|
|
113
113
|
name: sqlite3
|
114
114
|
requirement: !ruby/object:Gem::Requirement
|
115
115
|
requirements:
|
116
|
-
- - "
|
116
|
+
- - ">="
|
117
117
|
- !ruby/object:Gem::Version
|
118
|
-
version:
|
118
|
+
version: '0'
|
119
119
|
type: :development
|
120
120
|
prerelease: false
|
121
121
|
version_requirements: !ruby/object:Gem::Requirement
|
122
122
|
requirements:
|
123
|
-
- - "
|
123
|
+
- - ">="
|
124
124
|
- !ruby/object:Gem::Version
|
125
|
-
version:
|
125
|
+
version: '0'
|
126
126
|
- !ruby/object:Gem::Dependency
|
127
127
|
name: database_cleaner
|
128
128
|
requirement: !ruby/object:Gem::Requirement
|
@@ -165,7 +165,7 @@ dependencies:
|
|
165
165
|
- - ">="
|
166
166
|
- !ruby/object:Gem::Version
|
167
167
|
version: '0'
|
168
|
-
description: Plugin to use GCM with Notifiable
|
168
|
+
description: Plugin to use GCM with Notifiable
|
169
169
|
email:
|
170
170
|
- kamil@futureworkshops.com
|
171
171
|
- matt@futureworkshops.com
|
@@ -175,8 +175,6 @@ extra_rdoc_files: []
|
|
175
175
|
files:
|
176
176
|
- ".gitignore"
|
177
177
|
- ".rspec"
|
178
|
-
- ".ruby-gemset"
|
179
|
-
- ".ruby-version"
|
180
178
|
- Gemfile
|
181
179
|
- Gemfile.lock
|
182
180
|
- LICENSE
|
@@ -188,11 +186,6 @@ files:
|
|
188
186
|
- notifiable-gcm-spacialdb.gemspec
|
189
187
|
- spec/batch_spec.rb
|
190
188
|
- spec/spec_helper.rb
|
191
|
-
- spec/support/db/migrate/20131210115648_create_notifiable_apps.rb
|
192
|
-
- spec/support/db/migrate/20131210115649_create_notifiable_device_tokens.rb
|
193
|
-
- spec/support/db/migrate/20131210115650_create_notifiable_notifications.rb
|
194
|
-
- spec/support/db/migrate/20131210115651_create_notifiable_localized_notifications.rb
|
195
|
-
- spec/support/db/migrate/20131210115652_create_notifiable_statuses.rb
|
196
189
|
homepage: http://www.futureworkshops.com
|
197
190
|
licenses:
|
198
191
|
- Apache 2.0
|
@@ -213,15 +206,10 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
213
206
|
version: '0'
|
214
207
|
requirements: []
|
215
208
|
rubyforge_project:
|
216
|
-
rubygems_version: 2.
|
209
|
+
rubygems_version: 2.6.14
|
217
210
|
signing_key:
|
218
211
|
specification_version: 4
|
219
|
-
summary: Plugin to use GCM with Notifiable
|
212
|
+
summary: Plugin to use GCM with Notifiable
|
220
213
|
test_files:
|
221
214
|
- spec/batch_spec.rb
|
222
215
|
- spec/spec_helper.rb
|
223
|
-
- spec/support/db/migrate/20131210115648_create_notifiable_apps.rb
|
224
|
-
- spec/support/db/migrate/20131210115649_create_notifiable_device_tokens.rb
|
225
|
-
- spec/support/db/migrate/20131210115650_create_notifiable_notifications.rb
|
226
|
-
- spec/support/db/migrate/20131210115651_create_notifiable_localized_notifications.rb
|
227
|
-
- spec/support/db/migrate/20131210115652_create_notifiable_statuses.rb
|
data/.ruby-gemset
DELETED
@@ -1 +0,0 @@
|
|
1
|
-
notifiable-gcm-spacialdb
|
data/.ruby-version
DELETED
@@ -1 +0,0 @@
|
|
1
|
-
2.1.6
|
@@ -1,19 +0,0 @@
|
|
1
|
-
class CreateNotifiableDeviceTokens < ActiveRecord::Migration
|
2
|
-
|
3
|
-
def change
|
4
|
-
create_table :notifiable_device_tokens do |t|
|
5
|
-
t.string :token
|
6
|
-
t.string :provider
|
7
|
-
t.string :locale
|
8
|
-
t.boolean :is_valid, :default => true
|
9
|
-
t.integer :user_id
|
10
|
-
t.references :app
|
11
|
-
|
12
|
-
t.timestamps
|
13
|
-
end
|
14
|
-
|
15
|
-
add_index :notifiable_device_tokens, :token, :unique => true
|
16
|
-
add_index :notifiable_device_tokens, :user_id
|
17
|
-
end
|
18
|
-
|
19
|
-
end
|
@@ -1,16 +0,0 @@
|
|
1
|
-
class CreateNotifiableNotifications < ActiveRecord::Migration
|
2
|
-
|
3
|
-
def change
|
4
|
-
create_table :notifiable_notifications do |t|
|
5
|
-
t.references :app
|
6
|
-
|
7
|
-
#stats
|
8
|
-
t.integer :sent_count, :default => 0
|
9
|
-
t.integer :gateway_accepted_count, :default => 0
|
10
|
-
t.integer :opened_count, :default => 0
|
11
|
-
|
12
|
-
t.timestamps
|
13
|
-
end
|
14
|
-
end
|
15
|
-
|
16
|
-
end
|
@@ -1,22 +0,0 @@
|
|
1
|
-
class CreateNotifiableLocalizedNotifications < ActiveRecord::Migration
|
2
|
-
|
3
|
-
def change
|
4
|
-
create_table :notifiable_localized_notifications do |t|
|
5
|
-
t.text :message
|
6
|
-
t.text :params
|
7
|
-
t.string :locale
|
8
|
-
t.references :notification
|
9
|
-
|
10
|
-
# APNS - Optional
|
11
|
-
#t.integer :badge
|
12
|
-
#t.text :sound
|
13
|
-
#t.datetime :expiry
|
14
|
-
|
15
|
-
# MPNS - Optional
|
16
|
-
#t.text :title
|
17
|
-
|
18
|
-
t.timestamps
|
19
|
-
end
|
20
|
-
end
|
21
|
-
|
22
|
-
end
|