acts_as_pushable 0.2.0 → 0.3.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/README.md +11 -2
- data/lib/acts_as_pushable.rb +1 -0
- data/lib/acts_as_pushable/apn/notification.rb +28 -26
- data/lib/acts_as_pushable/gcm/notification.rb +20 -19
- data/lib/acts_as_pushable/notification.rb +43 -0
- data/lib/acts_as_pushable/version.rb +1 -1
- metadata +5 -4
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 2f6ba8a11226b1b0d7acde10cbaee82fbf763f07
|
4
|
+
data.tar.gz: b1fb5b1eea5225015c4d41557882537d5429e206
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: e84af18153948d8d53a498405e5801d84ff2a95ad16568899b592ec926e4c11e12e0cae42160889585fe7ab5b8b0815019e91ec353dde4559ed5004115569634
|
7
|
+
data.tar.gz: 55dd800796c96b4f361c28e23d35a3557d4e401e9cc4669d9dff1932b4051792f54335acd45e088fd7dde0402831a78213e5348aedc3140a192c0fc17a518a2c
|
data/README.md
CHANGED
@@ -105,14 +105,23 @@ Sending a push notification to a user will send the message to all of their vali
|
|
105
105
|
case device.platform
|
106
106
|
when "ios"
|
107
107
|
# iOS does not support titles
|
108
|
-
|
108
|
+
device.send_push_notification(message: 'this is a test', options)
|
109
109
|
when "android"
|
110
|
-
|
110
|
+
device.send_push_notification(message: 'this is a test', { title: 'My App' })
|
111
111
|
end
|
112
112
|
```
|
113
113
|
|
114
114
|
> You might want to consider doing this inside a worker.
|
115
115
|
|
116
|
+
## Sending silent push notifications to iOS Devices
|
117
|
+
|
118
|
+
You can send silent push notifications with no message to iOS devices. This is useful when you just want to update the badge count on the home screen.
|
119
|
+
|
120
|
+
```ruby
|
121
|
+
user = User.find(id)
|
122
|
+
user.send_push_notification(title: false, message: false, content_available: false, count: 2)
|
123
|
+
```
|
124
|
+
|
116
125
|
## Apple Feedback Service
|
117
126
|
|
118
127
|
Occasionally you'll want to cleanup old tokens that have been invalidated for various reasons. You can do this by running -
|
data/lib/acts_as_pushable.rb
CHANGED
@@ -2,36 +2,38 @@ require 'houston'
|
|
2
2
|
|
3
3
|
module ActsAsPushable
|
4
4
|
module APN
|
5
|
-
class Notification
|
6
|
-
def
|
7
|
-
|
8
|
-
|
5
|
+
class Notification < ActsAsPushable::Notification
|
6
|
+
def perform
|
7
|
+
client.push(notification)
|
8
|
+
end
|
9
9
|
|
10
|
-
|
11
|
-
production_apn.certificate = ActsAsPushable.configuration.apn_production_certificate_file
|
10
|
+
private
|
12
11
|
|
13
|
-
|
14
|
-
|
15
|
-
|
16
|
-
|
17
|
-
|
18
|
-
popup_ok_button_text: options.fetch('popup_ok_button_text', 'Ok'),
|
19
|
-
popup_cancel_button_text: options.fetch('popup_cancel_button_text', 'Cancel'),
|
20
|
-
navigate_to_view: options.fetch('navigate_to_view', nil),
|
21
|
-
navigate_to_view_as_modal: options.fetch('navigate_to_view_as_modal', true),
|
22
|
-
navigate_to_view_parameters: options.fetch('navigate_to_view_parameters', {}),
|
23
|
-
}
|
12
|
+
def client
|
13
|
+
client = Houston::Client.send(environment)
|
14
|
+
client.certificate = certificate
|
15
|
+
client
|
16
|
+
end
|
24
17
|
|
25
|
-
|
26
|
-
|
27
|
-
|
28
|
-
notification.custom_data = payload
|
18
|
+
def certificate
|
19
|
+
ActsAsPushable.configuration.send("apn_#{environment}_certificate_file")
|
20
|
+
end
|
29
21
|
|
30
|
-
|
31
|
-
|
32
|
-
|
33
|
-
|
34
|
-
|
22
|
+
def content_available
|
23
|
+
options.delete(:content_available) || true
|
24
|
+
end
|
25
|
+
|
26
|
+
def count
|
27
|
+
options.delete(:count)
|
28
|
+
end
|
29
|
+
|
30
|
+
def notification
|
31
|
+
notification = Houston::Notification.new(device: device.token)
|
32
|
+
notification.alert = message
|
33
|
+
notification.badge = count
|
34
|
+
notification.content_available = content_available
|
35
|
+
notification.custom_data = payload
|
36
|
+
notification
|
35
37
|
end
|
36
38
|
end
|
37
39
|
end
|
@@ -2,33 +2,34 @@ require 'gcm'
|
|
2
2
|
|
3
3
|
module ActsAsPushable
|
4
4
|
module GCM
|
5
|
-
class Notification
|
6
|
-
def
|
7
|
-
|
8
|
-
|
9
|
-
|
10
|
-
|
11
|
-
|
12
|
-
|
13
|
-
|
14
|
-
|
15
|
-
navigate_to_view_as_modal: options.fetch("navigate_to_view_as_modal", true),
|
16
|
-
navigate_to_view_parameters: options.fetch("navigate_to_view_parameters", {}),
|
17
|
-
}
|
5
|
+
class Notification < ActsAsPushable::Notification
|
6
|
+
def perform
|
7
|
+
response = client.send([device.token], gcm_options)
|
8
|
+
if response[:not_registered_ids].include? device.token
|
9
|
+
device.update_attribute 'invalidated_at', Time.now
|
10
|
+
end
|
11
|
+
response
|
12
|
+
end
|
13
|
+
|
14
|
+
private
|
18
15
|
|
19
|
-
|
16
|
+
attr_accessor :title
|
20
17
|
|
21
|
-
|
18
|
+
def client
|
19
|
+
::GCM.new(ActsAsPushable.configuration.gcm_key)
|
20
|
+
end
|
21
|
+
|
22
|
+
def gcm_options
|
23
|
+
{
|
22
24
|
data: {
|
23
25
|
title: title,
|
24
26
|
message: message,
|
25
27
|
}.merge(payload)
|
26
28
|
}
|
29
|
+
end
|
27
30
|
|
28
|
-
|
29
|
-
|
30
|
-
device.update_attribute 'invalidated_at', Time.now
|
31
|
-
end
|
31
|
+
def title
|
32
|
+
options.delete(:title)
|
32
33
|
end
|
33
34
|
end
|
34
35
|
end
|
@@ -0,0 +1,43 @@
|
|
1
|
+
module ActsAsPushable
|
2
|
+
class Notification
|
3
|
+
def initialize(device:, message:, **options)
|
4
|
+
@device = device
|
5
|
+
@message = message
|
6
|
+
@options = options
|
7
|
+
end
|
8
|
+
|
9
|
+
def self.send(device:, message:, **options)
|
10
|
+
self.new(device: device, message: message, **options).perform
|
11
|
+
end
|
12
|
+
|
13
|
+
private
|
14
|
+
|
15
|
+
attr_accessor :device, :message, :options
|
16
|
+
|
17
|
+
def default_payload
|
18
|
+
{
|
19
|
+
popup: true,
|
20
|
+
popup_title: nil,
|
21
|
+
popup_body: nil,
|
22
|
+
popup_type: 'alert',
|
23
|
+
popup_ok_button_text: 'Ok',
|
24
|
+
popup_cancel_button_text: 'Cancel',
|
25
|
+
navigate_to_view: nil,
|
26
|
+
navigate_to_view_as_modal: true,
|
27
|
+
navigate_to_view_parameters: {},
|
28
|
+
}
|
29
|
+
end
|
30
|
+
|
31
|
+
def environment
|
32
|
+
device.push_environment
|
33
|
+
end
|
34
|
+
|
35
|
+
def payload
|
36
|
+
payload = default_payload.keys.map do |key|
|
37
|
+
[key, options.delete(key) || default_payload[key]]
|
38
|
+
end.to_h
|
39
|
+
|
40
|
+
payload.merge(options)
|
41
|
+
end
|
42
|
+
end
|
43
|
+
end
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: acts_as_pushable
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.
|
4
|
+
version: 0.3.0
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Adam Butler
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2016-
|
11
|
+
date: 2016-08-04 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: rails
|
@@ -16,7 +16,7 @@ dependencies:
|
|
16
16
|
requirements:
|
17
17
|
- - ">="
|
18
18
|
- !ruby/object:Gem::Version
|
19
|
-
version:
|
19
|
+
version: 4.0.0
|
20
20
|
- - "<"
|
21
21
|
- !ruby/object:Gem::Version
|
22
22
|
version: '5.1'
|
@@ -26,7 +26,7 @@ dependencies:
|
|
26
26
|
requirements:
|
27
27
|
- - ">="
|
28
28
|
- !ruby/object:Gem::Version
|
29
|
-
version:
|
29
|
+
version: 4.0.0
|
30
30
|
- - "<"
|
31
31
|
- !ruby/object:Gem::Version
|
32
32
|
version: '5.1'
|
@@ -159,6 +159,7 @@ files:
|
|
159
159
|
- lib/acts_as_pushable/apn/notification.rb
|
160
160
|
- lib/acts_as_pushable/configuration.rb
|
161
161
|
- lib/acts_as_pushable/gcm/notification.rb
|
162
|
+
- lib/acts_as_pushable/notification.rb
|
162
163
|
- lib/acts_as_pushable/pushable.rb
|
163
164
|
- lib/acts_as_pushable/version.rb
|
164
165
|
- lib/generators/acts_as_pushable/install_generator.rb
|