rtpush 0.0.1 → 0.0.2

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 CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 2c15bf3d99afeda4f5ba4010061796a85599852d
4
- data.tar.gz: 44e6a85f0f7bf53586f3961220b336707626c4ea
3
+ metadata.gz: 75b60d3870317e9767c5c6d5166c19db97d339ad
4
+ data.tar.gz: c75445ce6576e5ba84f302bf38e67c5e88bcf85f
5
5
  SHA512:
6
- metadata.gz: a9561019dd151a5f628aea9817a4567435567633a3a63bd3ac9bed69a3c8868ed9d151490896946d629b9db325d5840c5fc456c98ecddca4b55c56f9755aa1fc
7
- data.tar.gz: 0c7aea244e4128ecc2b89501217b10e432eb8ca320a391275492602b1c4b42010457d8b0a255aabdefa695041acea81e7e8106f40fc18016f6bddad461c6e4f8
6
+ metadata.gz: 2b78987658b519012a369428512f4bdc56509173f1f0082cb994e52e2b19b5bd6ab8a3e7288b3e6fac60d4068bffa8fdcc06d223e375ff4a65a707e612676344
7
+ data.tar.gz: edcf78a472317d3beea585c036e3198a197c3a03232af2ebbffcbb1ffe71d00be361b0891f4c9b0bd1004a2b12d619e6e94482c81ac06d6317d852c184dc6483
data/README.md ADDED
@@ -0,0 +1,3 @@
1
+ # rtpush [![Gem Version](https://badge.fury.io/rb/rtpush.svg)](https://badge.fury.io/rb/rtpush) [![Maintainability](https://api.codeclimate.com/v1/badges/687aec30cf02fad5b6eb/maintainability)](https://codeclimate.com/github/satnami/rtpush/maintainability)
2
+
3
+ TBD
@@ -0,0 +1 @@
1
+ require 'dotenv/load'
@@ -0,0 +1 @@
1
+ require 'fcm'
@@ -0,0 +1 @@
1
+ require 'instapush'
@@ -0,0 +1,3 @@
1
+ require 'redis'
2
+
3
+ Redis.current = Redis.new(url: ENV['REDIS_URL'])
@@ -0,0 +1,137 @@
1
+ require 'rpush'
2
+
3
+ Rpush.configure do |config|
4
+
5
+ # Supported clients are :active_record and :redis
6
+ config.client = :redis
7
+
8
+ # Options passed to Redis.new
9
+ # config.redis_options = {}
10
+
11
+ # Frequency in seconds to check for new notifications.
12
+ config.push_poll = 2
13
+
14
+ # The maximum number of notifications to load from the store every `push_poll` seconds.
15
+ # If some notifications are still enqueued internally, Rpush will load the batch_size less
16
+ # the number enqueued. An exception to this is if the service is able to receive multiple
17
+ # notification payloads over the connection with a single write, such as APNs.
18
+ config.batch_size = 100
19
+
20
+ # Path to write PID file. Relative to current directory unless absolute.
21
+ config.pid_file = 'tmp/rpush.pid'
22
+
23
+ # Path to log file. Relative to current directory unless absolute.
24
+ config.log_file = 'log/rpush.log'
25
+
26
+ config.log_level = ::Logger::Severity::INFO
27
+
28
+ # Define a custom logger.
29
+ # config.logger = MyLogger.new
30
+
31
+ # config.apns.feedback_receiver.enabled = true
32
+ # config.apns.feedback_receiver.frequency = 60
33
+
34
+ end
35
+
36
+ Rpush.reflect do |on|
37
+
38
+ # Called with a Rpush::Apns::Feedback instance when feedback is received
39
+ # from the APNs that a notification has failed to be delivered.
40
+ # Further notifications should not be sent to the device.
41
+ # on.apns_feedback do |feedback|
42
+ # end
43
+
44
+ # Called when a notification is queued internally for delivery.
45
+ # The internal queue for each app runner can be inspected:
46
+ #
47
+ # Rpush::Daemon::AppRunner.runners.each do |app_id, runner|
48
+ # runner.app
49
+ # runner.queue_size
50
+ # end
51
+ #
52
+ # on.notification_enqueued do |notification|
53
+ # end
54
+
55
+ # Called when a notification is successfully delivered.
56
+ # on.notification_delivered do |notification|
57
+ # end
58
+
59
+ # Called when notification delivery failed.
60
+ # Call 'error_code' and 'error_description' on the notification for the cause.
61
+ # on.notification_failed do |notification|
62
+ # end
63
+
64
+ # Called when the notification delivery failed and only the notification ID
65
+ # is present in memory.
66
+ # on.notification_id_failed do |app, notification_id, error_code, error_description|
67
+ # end
68
+
69
+ # Called when a notification will be retried at a later date.
70
+ # Call 'deliver_after' on the notification for the next delivery date
71
+ # and 'retries' for the number of times this notification has been retried.
72
+ # on.notification_will_retry do |notification|
73
+ # end
74
+
75
+ # Called when a notification will be retried and only the notification ID
76
+ # is present in memory.
77
+ # on.notification_id_will_retry do |app, notification_id, retry_after|
78
+ # end
79
+
80
+ # Called when a TCP connection is lost and will be reconnected.
81
+ # on.tcp_connection_lost do |app, error|
82
+ # end
83
+
84
+ # Called for each recipient which successfully receives a notification. This
85
+ # can occur more than once for the same notification when there are multiple
86
+ # recipients.
87
+ # on.gcm_delivered_to_recipient do |notification, registration_id|
88
+ # end
89
+
90
+ # Called for each recipient which fails to receive a notification. This
91
+ # can occur more than once for the same notification when there are multiple
92
+ # recipients. (do not handle invalid registration IDs here)
93
+ # on.gcm_failed_to_recipient do |notification, error, registration_id|
94
+ # end
95
+
96
+ # Called when the GCM returns a canonical registration ID.
97
+ # You will need to replace old_id with canonical_id in your records.
98
+ # on.gcm_canonical_id do |old_id, canonical_id|
99
+ # end
100
+
101
+ # Called when the GCM returns a failure that indicates an invalid registration id.
102
+ # You will need to delete the registration_id from your records.
103
+ # on.gcm_invalid_registration_id do |app, error, registration_id|
104
+ # end
105
+
106
+ # Called when an SSL certificate will expire within 1 month.
107
+ # Implement on.error to catch errors raised when the certificate expires.
108
+ # on.ssl_certificate_will_expire do |app, expiration_time|
109
+ # end
110
+
111
+ # Called when an SSL certificate has been revoked.
112
+ # on.ssl_certificate_revoked do |app, error|
113
+ # end
114
+
115
+ # Called when the ADM returns a canonical registration ID.
116
+ # You will need to replace old_id with canonical_id in your records.
117
+ # on.adm_canonical_id do |old_id, canonical_id|
118
+ # end
119
+
120
+ # Called when Failed to deliver to ADM. Check the 'reason' string for further
121
+ # explanations.
122
+ #
123
+ # If the reason is the string 'Unregistered', you should remove
124
+ # this registration id from your records.
125
+ # on.adm_failed_to_recipient do |notification, registration_id, reason|
126
+ # end
127
+
128
+ # Called when Failed to deliver to WNS. Check the 'reason' string for further
129
+ # explanations.
130
+ # You should remove this uri from your records
131
+ # on.wns_invalid_channel do |notification, uri, reason|
132
+ # end
133
+
134
+ # Called when an exception is raised.
135
+ # on.error do |error|
136
+ # end
137
+ end
@@ -0,0 +1 @@
1
+ require 'slack-notifier'
@@ -0,0 +1 @@
1
+ require 'twilio-ruby'
data/lib/rtpush.rb CHANGED
@@ -1,9 +1,35 @@
1
- class RTPush
2
- def self.push
3
- puts "Push notifications to everywhere!"
1
+ Dir[File.join(__dir__, '/initializers/*.rb')].each { |file| require file }
2
+ Dir[File.join(__dir__, '/services/*.rb')].each { |file| require file }
3
+
4
+ module RTPush
5
+ def self.initialize(options, message)
6
+ push(strategies(options), message)
7
+ end
8
+
9
+ private_class_method
10
+
11
+ def self.push(strategies, message)
12
+ strategies.each do |strategy|
13
+ strategy.push(message)
14
+ end
4
15
  end
5
16
 
6
- def self.notify
7
- puts "Send notifications to everywhere!"
17
+ def self.strategies(options)
18
+ strategies = []
19
+ options.each do |option|
20
+ case option
21
+ when 'sms'
22
+ strategies << RTPush::TwilioService
23
+ when 'mobile'
24
+ strategies << RTPush::FcmService
25
+ when 'insta'
26
+ strategies << RTPush::InstapushService
27
+ when 'slack'
28
+ strategies << RTPush::SlackService
29
+ else
30
+ #
31
+ end
32
+ end
33
+ strategies
8
34
  end
9
35
  end
@@ -0,0 +1,30 @@
1
+ module RTPush
2
+ class FcmService
3
+ class << self
4
+ def push(message)
5
+ registration_ids = [ENV['GCM_ANDROID_DEVICE_TOKEN']]
6
+ options = {
7
+ notification: {
8
+ title: ENV['NOTIFICATION_TITLE'],
9
+ body: message,
10
+ icon: '',
11
+ click_action: ''
12
+ }.reject { |_k, v| v.nil? || v.empty? },
13
+ data: {
14
+ message: message,
15
+ picture: ''
16
+ }.reject { |_k, v| v.nil? || v.empty? }
17
+ }.reject { |_k, v| v.nil? || v.empty? }
18
+ client.send(registration_ids, options)
19
+ rescue StandardError => _
20
+ nil
21
+ end
22
+
23
+ private
24
+
25
+ def client
26
+ @client ||= FCM.new(ENV['GCM_AUTH_KEY'])
27
+ end
28
+ end
29
+ end
30
+ end
@@ -0,0 +1,19 @@
1
+ module RTPush
2
+ class InstapushService
3
+ class << self
4
+ def push(message)
5
+ event = Instapush::Event.new ENV['INSTAPUSH_APP_EVENT']
6
+ event.tracker = { message: message, version: '0.9.0' }
7
+ client.push event
8
+ rescue StandardError => _
9
+ nil
10
+ end
11
+
12
+ private
13
+
14
+ def client
15
+ @client ||= Instapush::Application.new ENV['INSTAPUSH_APP_ID'], ENV['INSTAPUSH_APP_SECRET']
16
+ end
17
+ end
18
+ end
19
+ end
@@ -0,0 +1,46 @@
1
+ module RTPush
2
+ class RpushService
3
+ class << self
4
+ def push(message)
5
+ gcm_push(message)
6
+ apn_push(message)
7
+ rescue StandardError => _
8
+ nil
9
+ end
10
+
11
+ private
12
+
13
+ def gcm_push(message)
14
+ notification = Rpush::Gcm::Notification.new
15
+ notification.app = gcm_client
16
+ notification.priority = ENV['GCM_PRIORITY']
17
+ notification.registration_ids = [ENV['GCM_ANDROID_DEVICE_TOKEN']]
18
+ notification.notification = {
19
+ title: ENV['TITLE_NOTIFICATION'],
20
+ body: message,
21
+ icon: ''
22
+ }.reject { |_k, v| v.nil? || v.empty? }
23
+ notification.data = { message: message }
24
+ notification.save!
25
+ end
26
+
27
+ def apn_push(message); end
28
+
29
+ def gcm_client
30
+ @gcm_client = Rpush::Gcm::App.where(name: ENV['GCM_ANDROID_APP_NAME']).first
31
+ unless @gcm_client
32
+ @gcm_client = Rpush::Gcm::App.new
33
+ @gcm_client.name = ENV['GCM_ANDROID_APP_NAME']
34
+ @gcm_client.auth_key = ENV['GCM_AUTH_KEY']
35
+ @gcm_client.connections = 1
36
+ @gcm_client.save!
37
+ end
38
+ @gcm_client
39
+ end
40
+
41
+ def apn_client
42
+ @apn_client = nil
43
+ end
44
+ end
45
+ end
46
+ end
@@ -0,0 +1,18 @@
1
+ module RTPush
2
+ class SlackService
3
+ class << self
4
+ def push(message)
5
+ data = %(*#{ENV['NOTIFICATION_TITLE']}*\n`#{message}`)
6
+ client.ping(data)
7
+ rescue StandardError => _
8
+ nil
9
+ end
10
+
11
+ private
12
+
13
+ def client
14
+ @client ||= Slack::Notifier.new(ENV['SLACK_WEBHOOK'])
15
+ end
16
+ end
17
+ end
18
+ end
@@ -0,0 +1,21 @@
1
+ module RTPush
2
+ class TwilioService
3
+ class << self
4
+ def push(message)
5
+ client.messages.create(
6
+ from: ENV['TWILIO_FROM_NUMBER'],
7
+ to: ENV['TWILIO_TO_NUMBER'],
8
+ body: message
9
+ )
10
+ rescue StandardError => _
11
+ nil
12
+ end
13
+
14
+ private
15
+
16
+ def client
17
+ @client ||= Twilio::REST::Client.new ENV['TWILIO_ACCOUNT_SID'], ENV['TWILIO_AUTH_TOKEN']
18
+ end
19
+ end
20
+ end
21
+ end
metadata CHANGED
@@ -1,22 +1,209 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: rtpush
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.0.1
4
+ version: 0.0.2
5
5
  platform: ruby
6
6
  authors:
7
7
  - Mhd Sami AlMouhtaseb
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2018-01-02 00:00:00.000000000 Z
12
- dependencies: []
11
+ date: 2018-01-07 00:00:00.000000000 Z
12
+ dependencies:
13
+ - !ruby/object:Gem::Dependency
14
+ name: dotenv
15
+ requirement: !ruby/object:Gem::Requirement
16
+ requirements:
17
+ - - "~>"
18
+ - !ruby/object:Gem::Version
19
+ version: '2.2'
20
+ - - ">="
21
+ - !ruby/object:Gem::Version
22
+ version: 2.2.1
23
+ type: :runtime
24
+ prerelease: false
25
+ version_requirements: !ruby/object:Gem::Requirement
26
+ requirements:
27
+ - - "~>"
28
+ - !ruby/object:Gem::Version
29
+ version: '2.2'
30
+ - - ">="
31
+ - !ruby/object:Gem::Version
32
+ version: 2.2.1
33
+ - !ruby/object:Gem::Dependency
34
+ name: fcm
35
+ requirement: !ruby/object:Gem::Requirement
36
+ requirements:
37
+ - - "~>"
38
+ - !ruby/object:Gem::Version
39
+ version: 0.0.2
40
+ - - ">="
41
+ - !ruby/object:Gem::Version
42
+ version: 0.0.2
43
+ type: :runtime
44
+ prerelease: false
45
+ version_requirements: !ruby/object:Gem::Requirement
46
+ requirements:
47
+ - - "~>"
48
+ - !ruby/object:Gem::Version
49
+ version: 0.0.2
50
+ - - ">="
51
+ - !ruby/object:Gem::Version
52
+ version: 0.0.2
53
+ - !ruby/object:Gem::Dependency
54
+ name: instapush-api
55
+ requirement: !ruby/object:Gem::Requirement
56
+ requirements:
57
+ - - "~>"
58
+ - !ruby/object:Gem::Version
59
+ version: '0.1'
60
+ - - ">="
61
+ - !ruby/object:Gem::Version
62
+ version: 0.1.0
63
+ type: :runtime
64
+ prerelease: false
65
+ version_requirements: !ruby/object:Gem::Requirement
66
+ requirements:
67
+ - - "~>"
68
+ - !ruby/object:Gem::Version
69
+ version: '0.1'
70
+ - - ">="
71
+ - !ruby/object:Gem::Version
72
+ version: 0.1.0
73
+ - !ruby/object:Gem::Dependency
74
+ name: redis
75
+ requirement: !ruby/object:Gem::Requirement
76
+ requirements:
77
+ - - "~>"
78
+ - !ruby/object:Gem::Version
79
+ version: '4.0'
80
+ - - ">="
81
+ - !ruby/object:Gem::Version
82
+ version: 4.0.1
83
+ type: :runtime
84
+ prerelease: false
85
+ version_requirements: !ruby/object:Gem::Requirement
86
+ requirements:
87
+ - - "~>"
88
+ - !ruby/object:Gem::Version
89
+ version: '4.0'
90
+ - - ">="
91
+ - !ruby/object:Gem::Version
92
+ version: 4.0.1
93
+ - !ruby/object:Gem::Dependency
94
+ name: rpush
95
+ requirement: !ruby/object:Gem::Requirement
96
+ requirements:
97
+ - - "~>"
98
+ - !ruby/object:Gem::Version
99
+ version: '3.0'
100
+ - - ">="
101
+ - !ruby/object:Gem::Version
102
+ version: 3.0.1
103
+ type: :runtime
104
+ prerelease: false
105
+ version_requirements: !ruby/object:Gem::Requirement
106
+ requirements:
107
+ - - "~>"
108
+ - !ruby/object:Gem::Version
109
+ version: '3.0'
110
+ - - ">="
111
+ - !ruby/object:Gem::Version
112
+ version: 3.0.1
113
+ - !ruby/object:Gem::Dependency
114
+ name: rpush-redis
115
+ requirement: !ruby/object:Gem::Requirement
116
+ requirements:
117
+ - - "~>"
118
+ - !ruby/object:Gem::Version
119
+ version: '0.4'
120
+ - - ">="
121
+ - !ruby/object:Gem::Version
122
+ version: 0.4.1
123
+ type: :runtime
124
+ prerelease: false
125
+ version_requirements: !ruby/object:Gem::Requirement
126
+ requirements:
127
+ - - "~>"
128
+ - !ruby/object:Gem::Version
129
+ version: '0.4'
130
+ - - ">="
131
+ - !ruby/object:Gem::Version
132
+ version: 0.4.1
133
+ - !ruby/object:Gem::Dependency
134
+ name: slack-notifier
135
+ requirement: !ruby/object:Gem::Requirement
136
+ requirements:
137
+ - - "~>"
138
+ - !ruby/object:Gem::Version
139
+ version: '2.3'
140
+ - - ">="
141
+ - !ruby/object:Gem::Version
142
+ version: 2.3.1
143
+ type: :runtime
144
+ prerelease: false
145
+ version_requirements: !ruby/object:Gem::Requirement
146
+ requirements:
147
+ - - "~>"
148
+ - !ruby/object:Gem::Version
149
+ version: '2.3'
150
+ - - ">="
151
+ - !ruby/object:Gem::Version
152
+ version: 2.3.1
153
+ - !ruby/object:Gem::Dependency
154
+ name: twilio-ruby
155
+ requirement: !ruby/object:Gem::Requirement
156
+ requirements:
157
+ - - "~>"
158
+ - !ruby/object:Gem::Version
159
+ version: '5.6'
160
+ - - ">="
161
+ - !ruby/object:Gem::Version
162
+ version: 5.6.0
163
+ type: :runtime
164
+ prerelease: false
165
+ version_requirements: !ruby/object:Gem::Requirement
166
+ requirements:
167
+ - - "~>"
168
+ - !ruby/object:Gem::Version
169
+ version: '5.6'
170
+ - - ">="
171
+ - !ruby/object:Gem::Version
172
+ version: 5.6.0
173
+ - !ruby/object:Gem::Dependency
174
+ name: rspec
175
+ requirement: !ruby/object:Gem::Requirement
176
+ requirements:
177
+ - - "~>"
178
+ - !ruby/object:Gem::Version
179
+ version: '0'
180
+ type: :development
181
+ prerelease: false
182
+ version_requirements: !ruby/object:Gem::Requirement
183
+ requirements:
184
+ - - "~>"
185
+ - !ruby/object:Gem::Version
186
+ version: '0'
13
187
  description: terminal push notification service for ruby.
14
188
  email: mssatnami@gmail.com
15
189
  executables: []
16
190
  extensions: []
17
191
  extra_rdoc_files: []
18
192
  files:
193
+ - README.md
194
+ - lib/initializers/dotenv.rb
195
+ - lib/initializers/fcm.rb
196
+ - lib/initializers/instapush.rb
197
+ - lib/initializers/redis.rb
198
+ - lib/initializers/rpush.rb
199
+ - lib/initializers/slack.rb
200
+ - lib/initializers/twilio.rb
19
201
  - lib/rtpush.rb
202
+ - lib/services/fcm_service.rb
203
+ - lib/services/instapush_service.rb
204
+ - lib/services/rpush_service.rb
205
+ - lib/services/slack_service.rb
206
+ - lib/services/twilio_service.rb
20
207
  homepage: https://github.com/satnami/rtpush
21
208
  licenses:
22
209
  - MIT