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 CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: a3cf52438238f0a1ecc519c79d1e0c109e2aa3b3
4
- data.tar.gz: e0050a1abd40c76018e755af5c972c6df8949c03
3
+ metadata.gz: 2f6ba8a11226b1b0d7acde10cbaee82fbf763f07
4
+ data.tar.gz: b1fb5b1eea5225015c4d41557882537d5429e206
5
5
  SHA512:
6
- metadata.gz: 85e0b91b69df6f7b34a3dbf0acdccf8e5ab1ffa6e6a3ada051fe55edd6dd953e616dff1f1957d8409bffddeeb7909ab3272c04ca1249679138813edfcfd122a6
7
- data.tar.gz: 775bf5cd462bceaad998e312409039f5942e294b9ee76359f931f8b767380e4946e99d1cc6c35e4e23ce88747e619e9e2aaf923a2fcc272e0edaa872cb701129
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
- user.send_push_notification(message: 'this is a test', options)
108
+ device.send_push_notification(message: 'this is a test', options)
109
109
  when "android"
110
- user.send_push_notification(message: 'this is a test', options)
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 -
@@ -2,6 +2,7 @@ require 'acts_as_pushable/version'
2
2
  require 'acts_as_pushable/configuration'
3
3
 
4
4
  require 'acts_as_pushable/active_record/device.rb'
5
+ require 'acts_as_pushable/notification'
5
6
  require 'acts_as_pushable/pushable'
6
7
 
7
8
  require 'acts_as_pushable/apn/notification'
@@ -2,36 +2,38 @@ require 'houston'
2
2
 
3
3
  module ActsAsPushable
4
4
  module APN
5
- class Notification
6
- def self.send(device:, message:, **options)
7
- development_apn = Houston::Client.development
8
- production_apn = Houston::Client.production
5
+ class Notification < ActsAsPushable::Notification
6
+ def perform
7
+ client.push(notification)
8
+ end
9
9
 
10
- development_apn.certificate = ActsAsPushable.configuration.apn_development_certificate_file
11
- production_apn.certificate = ActsAsPushable.configuration.apn_production_certificate_file
10
+ private
12
11
 
13
- payload = {
14
- popup: options.fetch('popup', true),
15
- popup_title: options.fetch('popup_title', nil),
16
- popup_body: options.fetch('popup_body', nil),
17
- popup_type: options.fetch('popup_type', 'alert'),
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
- notification = Houston::Notification.new(device: device.token)
26
- notification.alert = message
27
- notification.badge = options.fetch('count', nil)
28
- notification.custom_data = payload
18
+ def certificate
19
+ ActsAsPushable.configuration.send("apn_#{environment}_certificate_file")
20
+ end
29
21
 
30
- if device.push_environment == 'development'
31
- development_apn.push(notification)
32
- else
33
- production_apn.push(notification)
34
- end
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 self.send(device:, title:, message:, **options)
7
- payload = {
8
- popup: options.fetch("popup", true),
9
- popup_title: options.fetch("popup_title", nil),
10
- popup_body: options.fetch("popup_body", nil),
11
- popup_type: options.fetch("popup_type", 'alert'),
12
- popup_ok_button_text: options.fetch("popup_ok_button_text", 'Ok'),
13
- popup_cancel_button_text: options.fetch("popup_cancel_button_text", 'Cancel'),
14
- navigate_to_view: options.fetch("navigate_to_view", nil),
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
- gcm = ::GCM.new(ActsAsPushable.configuration.gcm_key)
16
+ attr_accessor :title
20
17
 
21
- gcm_options = {
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
- response = gcm.send([device.token], gcm_options)
29
- if response[:not_registered_ids].include? device.token
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
@@ -1,3 +1,3 @@
1
1
  module ActsAsPushable
2
- VERSION = '0.2.0'
2
+ VERSION = '0.3.0'
3
3
  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.2.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-06-07 00:00:00.000000000 Z
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: 5.0.0.beta4
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: 5.0.0.beta4
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