rtpush 0.0.5 → 0.0.6
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/README.md +20 -4
- data/lib/rtpush.rb +10 -7
- data/lib/rtpush/adapters/base_adapter.rb +60 -0
- data/lib/{services/fcm_service.rb → rtpush/adapters/fcm_adapter.rb} +3 -3
- data/lib/{services/instapush_service.rb → rtpush/adapters/instapush_adapter.rb} +3 -3
- data/lib/{services/rpush_service.rb → rtpush/adapters/rpush_adapter.rb} +3 -3
- data/lib/{services/slack_service.rb → rtpush/adapters/slack_adapter.rb} +3 -3
- data/lib/{services/twilio_service.rb → rtpush/adapters/twilio_adapter.rb} +3 -3
- data/lib/rtpush/errors.rb +24 -0
- data/lib/{initializers → rtpush/initializers}/dotenv.rb +0 -0
- data/lib/{initializers → rtpush/initializers}/fcm.rb +0 -0
- data/lib/{initializers → rtpush/initializers}/instapush.rb +0 -0
- data/lib/{initializers → rtpush/initializers}/redis.rb +0 -0
- data/lib/{initializers → rtpush/initializers}/rpush.rb +0 -0
- data/lib/{initializers → rtpush/initializers}/slack.rb +0 -0
- data/lib/{initializers → rtpush/initializers}/twilio.rb +0 -0
- data/lib/rtpush/version.rb +7 -0
- metadata +19 -16
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 527594e7040fdbf77900607cc5fdedf846a802aa
|
4
|
+
data.tar.gz: 3872d494fffe02eea561a6292c1e20a6e0e21dff
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 55b6580d7e19d59c246b4f69bd7ab22264bdec49f5a1a75ebcd207512eeb8ba50e799d6bda59a5cb0d5cda065f501cc4c78cb669ba0264de4848a9a1808c52cc
|
7
|
+
data.tar.gz: de85e0f7851ad3a9f4b36ea3fadb5e0c403d1a80074bfa0033f289f787617cddbbd7dd89c325178e0e15a6ee936094663aa7b39e289a9b7d06a64eeb80d61348
|
data/README.md
CHANGED
@@ -1,12 +1,28 @@
|
|
1
|
-
|
1
|
+
[![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
2
|
|
3
|
+
# RTPush. The terminal push notification service for Ruby.
|
4
|
+
|
5
|
+
## Supported Services
|
6
|
+
* [**FCM Push Notification Service**](https://firebase.google.com/docs/cloud-messaging/)
|
7
|
+
* [**Instapush Notification Service**](https://instapush.im/)
|
8
|
+
* [**Slack Notification Service**](https://api.slack.com/incoming-webhooks)
|
9
|
+
* [**Twilio Messaging Service**](https://www.twilio.com/docs/api/messaging/)
|
10
|
+
|
3
11
|
## Installation
|
4
12
|
```
|
5
13
|
$ gem install rtpush
|
6
14
|
```
|
7
15
|
|
8
|
-
##
|
9
|
-
|
16
|
+
## Configuring
|
17
|
+
You can use [dotenv](https://github.com/bkeepers/dotenv), which is included in the Gemfile,
|
18
|
+
to fill in any values that you can't or won't supply through the environment.
|
19
|
+
|
20
|
+
In order of precedence RTPush uses:
|
21
|
+
1. Environment variables (for example MY_VALUE=abc)
|
22
|
+
2. Values provided in a .env file
|
23
|
+
3. Default values from .env.default
|
24
|
+
|
25
|
+
## Configuration Parameters
|
10
26
|
```
|
11
27
|
NOTIFICATION_TITLE=XX
|
12
28
|
|
@@ -48,4 +64,4 @@ rspec spec
|
|
48
64
|
## Improvement
|
49
65
|
```
|
50
66
|
TBD
|
51
|
-
```
|
67
|
+
```
|
data/lib/rtpush.rb
CHANGED
@@ -1,8 +1,11 @@
|
|
1
|
-
Dir[File.join(__dir__, '/
|
2
|
-
Dir[File.join(__dir__, '/
|
1
|
+
Dir[File.join(__dir__, '/rtpush/*.rb')].each { |file| require file }
|
2
|
+
Dir[File.join(__dir__, '/rtpush/initializers/*.rb')].each { |file| require file }
|
3
|
+
Dir[File.join(__dir__, '/rtpush/adapters/*.rb')].each { |file| require file }
|
3
4
|
|
4
5
|
module RTPush
|
5
6
|
def self.initialize(options, message)
|
7
|
+
raise ArgumentError, 'Missing Message param' if message.to_s.empty?
|
8
|
+
raise ArgumentError, 'Missing Arguments params' if options.empty?
|
6
9
|
push(strategies(options), message)
|
7
10
|
end
|
8
11
|
|
@@ -19,15 +22,15 @@ module RTPush
|
|
19
22
|
options.each do |option|
|
20
23
|
case option
|
21
24
|
when 'sms'
|
22
|
-
strategies << RTPush::
|
25
|
+
strategies << RTPush::TwilioAdapter
|
23
26
|
when 'mobile'
|
24
|
-
strategies << RTPush::
|
27
|
+
strategies << RTPush::FcmAdapter
|
25
28
|
when 'insta'
|
26
|
-
strategies << RTPush::
|
29
|
+
strategies << RTPush::InstapushAdapter
|
27
30
|
when 'slack'
|
28
|
-
strategies << RTPush::
|
31
|
+
strategies << RTPush::SlackAdapter
|
29
32
|
else
|
30
|
-
#
|
33
|
+
raise Errors::NotImplementedStrategyError, "Unknown strategy #{option}"
|
31
34
|
end
|
32
35
|
end
|
33
36
|
strategies
|
@@ -0,0 +1,60 @@
|
|
1
|
+
module RTPush
|
2
|
+
class BaseAdapter
|
3
|
+
attr_accessor :errors
|
4
|
+
@@_validators = []
|
5
|
+
|
6
|
+
def initialize
|
7
|
+
@errors = []
|
8
|
+
end
|
9
|
+
|
10
|
+
def self.validates_presence_of(attribute)
|
11
|
+
@@_validators << PresenceValidator.new(attribute)
|
12
|
+
end
|
13
|
+
|
14
|
+
def self.validates_existence_of(attribute)
|
15
|
+
@@_validators << PresenceValidator.new(attribute)
|
16
|
+
end
|
17
|
+
|
18
|
+
def valid?
|
19
|
+
@@_validators.each do |v|
|
20
|
+
v.validate(self)
|
21
|
+
end
|
22
|
+
@errors.empty?
|
23
|
+
end
|
24
|
+
|
25
|
+
def exist?
|
26
|
+
@@_validators.each do |v|
|
27
|
+
v.exist(self)
|
28
|
+
end
|
29
|
+
@errors.empty?
|
30
|
+
end
|
31
|
+
end
|
32
|
+
|
33
|
+
class PresenceValidator
|
34
|
+
attr_reader :attributes
|
35
|
+
|
36
|
+
def initialize(*attributes)
|
37
|
+
@attributes = attributes
|
38
|
+
end
|
39
|
+
|
40
|
+
def validate(record)
|
41
|
+
begin
|
42
|
+
@attributes.each do |attribute|
|
43
|
+
data = record.send(attribute)
|
44
|
+
if data.nil? || data.empty?
|
45
|
+
record.errors << ["#{attribute} can't be blank"]
|
46
|
+
end
|
47
|
+
end
|
48
|
+
end
|
49
|
+
end
|
50
|
+
|
51
|
+
def exist(record)
|
52
|
+
@attributes.each do |attribute|
|
53
|
+
data = ENV[attribute.to_s]
|
54
|
+
if data.nil? || data.empty?
|
55
|
+
record.errors << ["#{attribute} can't be empty"]
|
56
|
+
end
|
57
|
+
end
|
58
|
+
end
|
59
|
+
end
|
60
|
+
end
|
@@ -1,5 +1,5 @@
|
|
1
1
|
module RTPush
|
2
|
-
class
|
2
|
+
class FcmAdapter < RTPush::BaseAdapter
|
3
3
|
class << self
|
4
4
|
def push(message)
|
5
5
|
registration_ids = [ENV['GCM_ANDROID_DEVICE_TOKEN']]
|
@@ -16,8 +16,8 @@ module RTPush
|
|
16
16
|
}.reject { |_k, v| v.nil? || v.empty? }
|
17
17
|
}.reject { |_k, v| v.nil? || v.empty? }
|
18
18
|
client.send(registration_ids, options)
|
19
|
-
rescue StandardError =>
|
20
|
-
|
19
|
+
rescue StandardError => e
|
20
|
+
raise Errors::AdapterError, e.message
|
21
21
|
end
|
22
22
|
|
23
23
|
private
|
@@ -1,12 +1,12 @@
|
|
1
1
|
module RTPush
|
2
|
-
class
|
2
|
+
class InstapushAdapter < RTPush::BaseAdapter
|
3
3
|
class << self
|
4
4
|
def push(message)
|
5
5
|
event = Instapush::Event.new ENV['INSTAPUSH_APP_EVENT']
|
6
6
|
event.tracker = { message: message, version: '0.9.0' }
|
7
7
|
client.push event
|
8
|
-
rescue StandardError =>
|
9
|
-
|
8
|
+
rescue StandardError => e
|
9
|
+
raise Errors::AdapterError, e.message
|
10
10
|
end
|
11
11
|
|
12
12
|
private
|
@@ -1,11 +1,11 @@
|
|
1
1
|
module RTPush
|
2
|
-
class
|
2
|
+
class RpushAdapter < RTPush::BaseAdapter
|
3
3
|
class << self
|
4
4
|
def push(message)
|
5
5
|
gcm_push(message)
|
6
6
|
apn_push(message)
|
7
|
-
rescue StandardError =>
|
8
|
-
|
7
|
+
rescue StandardError => e
|
8
|
+
raise Errors::AdapterError, e.message
|
9
9
|
end
|
10
10
|
|
11
11
|
private
|
@@ -1,11 +1,11 @@
|
|
1
1
|
module RTPush
|
2
|
-
class
|
2
|
+
class SlackAdapter < RTPush::BaseAdapter
|
3
3
|
class << self
|
4
4
|
def push(message)
|
5
5
|
data = %(*#{ENV['NOTIFICATION_TITLE']}*\n`#{message}`)
|
6
6
|
client.ping(data)
|
7
|
-
rescue StandardError =>
|
8
|
-
|
7
|
+
rescue StandardError => e
|
8
|
+
raise Errors::AdapterError, e.message
|
9
9
|
end
|
10
10
|
|
11
11
|
private
|
@@ -1,5 +1,5 @@
|
|
1
1
|
module RTPush
|
2
|
-
class
|
2
|
+
class TwilioAdapter < RTPush::BaseAdapter
|
3
3
|
class << self
|
4
4
|
def push(message)
|
5
5
|
client.messages.create(
|
@@ -7,8 +7,8 @@ module RTPush
|
|
7
7
|
to: ENV['TWILIO_TO_NUMBER'],
|
8
8
|
body: message
|
9
9
|
)
|
10
|
-
rescue StandardError =>
|
11
|
-
|
10
|
+
rescue StandardError => e
|
11
|
+
raise Errors::AdapterError, e.message
|
12
12
|
end
|
13
13
|
|
14
14
|
private
|
@@ -0,0 +1,24 @@
|
|
1
|
+
module Errors
|
2
|
+
class Error < StandardError
|
3
|
+
def initialize(msg = nil)
|
4
|
+
@message = msg
|
5
|
+
end
|
6
|
+
|
7
|
+
def message
|
8
|
+
@message
|
9
|
+
end
|
10
|
+
end
|
11
|
+
|
12
|
+
class NotImplementedStrategyError < Error
|
13
|
+
def message
|
14
|
+
super
|
15
|
+
end
|
16
|
+
end
|
17
|
+
|
18
|
+
class AdapterError < Error
|
19
|
+
def message
|
20
|
+
super
|
21
|
+
end
|
22
|
+
end
|
23
|
+
|
24
|
+
end
|
File without changes
|
File without changes
|
File without changes
|
File without changes
|
File without changes
|
File without changes
|
File without changes
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: rtpush
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.0.
|
4
|
+
version: 0.0.6
|
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-
|
11
|
+
date: 2018-03-08 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: dotenv
|
@@ -184,7 +184,7 @@ dependencies:
|
|
184
184
|
- - "~>"
|
185
185
|
- !ruby/object:Gem::Version
|
186
186
|
version: '0'
|
187
|
-
description: terminal push notification service for
|
187
|
+
description: The terminal push notification service for Ruby.
|
188
188
|
email: mssatnami@gmail.com
|
189
189
|
executables:
|
190
190
|
- rtpush
|
@@ -194,19 +194,22 @@ files:
|
|
194
194
|
- LICENSE
|
195
195
|
- README.md
|
196
196
|
- bin/rtpush
|
197
|
-
- lib/initializers/dotenv.rb
|
198
|
-
- lib/initializers/fcm.rb
|
199
|
-
- lib/initializers/instapush.rb
|
200
|
-
- lib/initializers/redis.rb
|
201
|
-
- lib/initializers/rpush.rb
|
202
|
-
- lib/initializers/slack.rb
|
203
|
-
- lib/initializers/twilio.rb
|
204
197
|
- lib/rtpush.rb
|
205
|
-
- lib/
|
206
|
-
- lib/
|
207
|
-
- lib/
|
208
|
-
- lib/
|
209
|
-
- lib/
|
198
|
+
- lib/rtpush/adapters/base_adapter.rb
|
199
|
+
- lib/rtpush/adapters/fcm_adapter.rb
|
200
|
+
- lib/rtpush/adapters/instapush_adapter.rb
|
201
|
+
- lib/rtpush/adapters/rpush_adapter.rb
|
202
|
+
- lib/rtpush/adapters/slack_adapter.rb
|
203
|
+
- lib/rtpush/adapters/twilio_adapter.rb
|
204
|
+
- lib/rtpush/errors.rb
|
205
|
+
- lib/rtpush/initializers/dotenv.rb
|
206
|
+
- lib/rtpush/initializers/fcm.rb
|
207
|
+
- lib/rtpush/initializers/instapush.rb
|
208
|
+
- lib/rtpush/initializers/redis.rb
|
209
|
+
- lib/rtpush/initializers/rpush.rb
|
210
|
+
- lib/rtpush/initializers/slack.rb
|
211
|
+
- lib/rtpush/initializers/twilio.rb
|
212
|
+
- lib/rtpush/version.rb
|
210
213
|
homepage: https://github.com/satnami/rtpush
|
211
214
|
licenses:
|
212
215
|
- MIT
|
@@ -228,7 +231,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
228
231
|
version: '0'
|
229
232
|
requirements: []
|
230
233
|
rubyforge_project:
|
231
|
-
rubygems_version: 2.5.1
|
234
|
+
rubygems_version: 2.5.2.1
|
232
235
|
signing_key:
|
233
236
|
specification_version: 4
|
234
237
|
summary: Ruby terminal push notification service.
|