action_push 0.1.0
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 +7 -0
- data/.gitignore +15 -0
- data/.rspec +3 -0
- data/.rubocop.yml +124 -0
- data/.travis.yml +11 -0
- data/Gemfile +8 -0
- data/Gemfile.lock +76 -0
- data/LICENSE.txt +21 -0
- data/Makefile +12 -0
- data/README.md +180 -0
- data/Rakefile +8 -0
- data/action_push.gemspec +35 -0
- data/bin/console +7 -0
- data/bin/release +5 -0
- data/bin/setup +8 -0
- data/docker-compose.yml +14 -0
- data/gorush.ci.yml +63 -0
- data/gorush.example.yml +63 -0
- data/lib/action_push.rb +33 -0
- data/lib/action_push/base.rb +64 -0
- data/lib/action_push/concerns/class_method_delivery.rb +36 -0
- data/lib/action_push/concerns/register_default.rb +23 -0
- data/lib/action_push/concerns/register_delivery_method.rb +15 -0
- data/lib/action_push/delivery/explosion.rb +15 -0
- data/lib/action_push/delivery/gorush.rb +91 -0
- data/lib/action_push/delivery/memory.rb +22 -0
- data/lib/action_push/envelope.rb +47 -0
- data/lib/action_push/errors.rb +5 -0
- data/lib/action_push/ios/alert.rb +50 -0
- data/lib/action_push/ios/message.rb +64 -0
- data/lib/action_push/provider/base.rb +64 -0
- data/lib/action_push/provider/test.rb +9 -0
- data/lib/action_push/util.rb +20 -0
- data/lib/action_push/version.rb +5 -0
- metadata +190 -0
data/Rakefile
ADDED
data/action_push.gemspec
ADDED
@@ -0,0 +1,35 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
lib = File.expand_path('../lib', __FILE__)
|
4
|
+
$LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
|
5
|
+
require 'action_push/version'
|
6
|
+
|
7
|
+
Gem::Specification.new do |spec|
|
8
|
+
spec.name = 'action_push'
|
9
|
+
spec.version = ActionPush::VERSION
|
10
|
+
spec.authors = ['Aliaksandr Shylau']
|
11
|
+
spec.email = %w[alex.shilov.by@gmail.com]
|
12
|
+
|
13
|
+
spec.summary = 'ActionPush is a lightweight tool which allows you to organize Push notifications the same way Action Mailer does'
|
14
|
+
spec.description = 'It includes includes built-in support for the GORUSH gateway'
|
15
|
+
spec.homepage = 'https://github.com/shlima/action_push'
|
16
|
+
spec.license = 'MIT'
|
17
|
+
|
18
|
+
# Specify which files should be added to the gem when it is released.
|
19
|
+
# The `git ls-files -z` loads the files in the RubyGem that have been added into git.
|
20
|
+
spec.files = Dir.chdir(File.expand_path('..', __FILE__)) do
|
21
|
+
`git ls-files -z`.split("\x0").reject { |f| f.match(%r{^(test|spec|features)/}) }
|
22
|
+
end
|
23
|
+
spec.bindir = 'exe'
|
24
|
+
spec.executables = spec.files.grep(%r{^exe/}) { |f| File.basename(f) }
|
25
|
+
spec.require_paths = %w[lib]
|
26
|
+
|
27
|
+
spec.add_development_dependency 'bundler', '~> 1.17'
|
28
|
+
spec.add_development_dependency 'rake', '~> 10.0'
|
29
|
+
spec.add_development_dependency 'rspec', '~> 3.0'
|
30
|
+
spec.add_development_dependency 'pry'
|
31
|
+
spec.add_development_dependency 'rubocop'
|
32
|
+
spec.add_development_dependency 'rubocop-performance'
|
33
|
+
spec.add_development_dependency 'webmock'
|
34
|
+
spec.add_development_dependency 'i18n'
|
35
|
+
end
|
data/bin/console
ADDED
data/bin/release
ADDED
data/bin/setup
ADDED
data/docker-compose.yml
ADDED
data/gorush.ci.yml
ADDED
@@ -0,0 +1,63 @@
|
|
1
|
+
core:
|
2
|
+
enabled: true # enabale httpd server
|
3
|
+
address: "" # ip address to bind (default: any)
|
4
|
+
port: "8088" # ignore this port number if auto_tls is enabled (listen 443).
|
5
|
+
worker_num: 0 # default worker number is runtime.NumCPU()
|
6
|
+
queue_num: 0 # default queue number is 8192
|
7
|
+
max_notification: 100
|
8
|
+
sync: false # set true if you need get error message from fail push notification in API response.
|
9
|
+
feedback_hook_url: "" # set a hook url if you need get error message asynchronously from fail push notification in API response.
|
10
|
+
mode: "release"
|
11
|
+
ssl: false
|
12
|
+
cert_path: "cert.pem"
|
13
|
+
key_path: "key.pem"
|
14
|
+
cert_base64: ""
|
15
|
+
key_base64: ""
|
16
|
+
http_proxy: "" # only working for FCM server
|
17
|
+
pid:
|
18
|
+
enabled: false
|
19
|
+
path: "gorush.pid"
|
20
|
+
override: true
|
21
|
+
auto_tls:
|
22
|
+
enabled: false # Automatically install TLS certificates from Let's Encrypt.
|
23
|
+
folder: ".cache" # folder for storing TLS certificates
|
24
|
+
host: "" # which domains the Let's Encrypt will attempt
|
25
|
+
|
26
|
+
grpc:
|
27
|
+
enabled: false # enabale gRPC server
|
28
|
+
port: 9000
|
29
|
+
|
30
|
+
api:
|
31
|
+
push_uri: "/api/push"
|
32
|
+
stat_go_uri: "/api/stat/go"
|
33
|
+
stat_app_uri: "/api/stat/app"
|
34
|
+
config_uri: "/api/config"
|
35
|
+
sys_stat_uri: "/sys/stats"
|
36
|
+
metric_uri: "/metrics"
|
37
|
+
health_uri: "/healthz"
|
38
|
+
|
39
|
+
android:
|
40
|
+
enabled: false
|
41
|
+
apikey: ""
|
42
|
+
max_retry: 0 # resend fail notification, default value zero is disabled
|
43
|
+
|
44
|
+
ios:
|
45
|
+
enabled: true
|
46
|
+
key_base64: "MIIMaQIBAzCCDDAGCSqGSIb3DQEHAaCCDCEEggwdMIIMGTCCBp8GCSqGSIb3\nDQEHBqCCBpAwggaMAgEAMIIGhQYJKoZIhvcNAQcBMBwGCiqGSIb3DQEMAQYw\nDgQIg4ykTc02M7wCAggAgIIGWEvnnMpYMBd4LJpWXWqkIK4rw/blZeuDmizd\nHPj8X8q2B1bKky+MaRXVpbkp+UIEJfVElKC/I2FhhP7fr+7yC7rgHt67ZgBN\nfip/09SmCCStjfqGX1rr77rNtLoYbfZdqT6y+zksP6k064Whu9ySc24CI1dp\niP9GI8Ofea/LYtYiDrFzfo4hT/o22RCviiJ1XvlJA9Hsc6dcg5AUsSEwELH1\ndS5tTEZgTc4h7Vq8R3b0Rr4Ms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8Api25tSEyaZ\nV7ekLykJqFsmgaP92eDNkApu3MDIVjd2TyKedKrQ1v1MuyK/OF/kcSaM+vl6\ncX+EikA6FXc99jhZpNqBVB2EQp/ieTEERzxUhouR6i6Be+nxrfv25ImhUkfd\n0aKTwh8qhGV1rTyEcnom8p903hHmpHd2+feuJAwuKiem5KXatXXciRMYT9y4\n7y+xq5vrIQMp/2aJXDZsaIVPB4boGnHeycKCAdtNDpTacs0GeCDu/bwn8/Uq\nPH4l9WcK4Ub3cRoJ4TcET7AMDgI5s+TDuG6LWQTS3xzaz1pxg6ELz+RF7PPC\noxT/1WnrC4F35SrdYvO4+CV2QG7KbllSW6NvRm67rV7pt3wohp0wNLixpzfo\nm4DYzCpRm3se+EPDkI+WLqTmRNPxOLnt7rWL1w8oW1lWqMEXCcM1DbRJ+VEa\nL5l5QZygvkeLb6lYkEVD6mcKi1m7pYYwjkOFap8PPiVqtrcYjMyxAS4EyTBl\ngnh6HojzFtrvud6tHzdD87YTY10B3ubDipscUDFWMC8GCSqGSIb3DQEJFDEi\nHiAEFAQ8BDgEQgRABDgEOQAgBBMEPgQ9BEcENQQ9BDoEPjAjBgkqhkiG9w0B\nCRUxFgQUMCl5eNLZn3NrLN4OhU4j3rv+chswMDAhMAkGBSsOAwIaBQAEFHbe\n9PHdNOlRMsIKgXj54VUejst+BAi09C/pGD/jgAIBAQ==\n"
|
47
|
+
key_type: "p12" # could be pem, p12 or p8 type
|
48
|
+
password: "" # certificate password, default as empty string.
|
49
|
+
production: true
|
50
|
+
max_retry: 0 # resend fail notification, default value zero is disabled
|
51
|
+
key_id: "" # KeyID from developer account (Certificates, Identifiers & Profiles -> Keys)
|
52
|
+
team_id: "" # TeamID from developer account (View Account -> Membership)
|
53
|
+
|
54
|
+
log:
|
55
|
+
format: "string" # string or json
|
56
|
+
access_log: "stdout" # stdout: output to console, or define log path like "log/access_log"
|
57
|
+
access_level: "debug"
|
58
|
+
error_log: "stderr" # stderr: output to console, or define log path like "log/error_log"
|
59
|
+
error_level: "error"
|
60
|
+
hide_token: true
|
61
|
+
|
62
|
+
stat:
|
63
|
+
engine: "memory" # support memory, redis, boltdb, buntdb or leveldb
|
data/gorush.example.yml
ADDED
@@ -0,0 +1,63 @@
|
|
1
|
+
core:
|
2
|
+
enabled: true # enabale httpd server
|
3
|
+
address: "" # ip address to bind (default: any)
|
4
|
+
port: "8088" # ignore this port number if auto_tls is enabled (listen 443).
|
5
|
+
worker_num: 0 # default worker number is runtime.NumCPU()
|
6
|
+
queue_num: 0 # default queue number is 8192
|
7
|
+
max_notification: 100
|
8
|
+
sync: false # set true if you need get error message from fail push notification in API response.
|
9
|
+
feedback_hook_url: "" # set a hook url if you need get error message asynchronously from fail push notification in API response.
|
10
|
+
mode: "release"
|
11
|
+
ssl: false
|
12
|
+
cert_path: "cert.pem"
|
13
|
+
key_path: "key.pem"
|
14
|
+
cert_base64: ""
|
15
|
+
key_base64: ""
|
16
|
+
http_proxy: "" # only working for FCM server
|
17
|
+
pid:
|
18
|
+
enabled: false
|
19
|
+
path: "gorush.pid"
|
20
|
+
override: true
|
21
|
+
auto_tls:
|
22
|
+
enabled: false # Automatically install TLS certificates from Let's Encrypt.
|
23
|
+
folder: ".cache" # folder for storing TLS certificates
|
24
|
+
host: "" # which domains the Let's Encrypt will attempt
|
25
|
+
|
26
|
+
grpc:
|
27
|
+
enabled: false # enabale gRPC server
|
28
|
+
port: 9000
|
29
|
+
|
30
|
+
api:
|
31
|
+
push_uri: "/api/push"
|
32
|
+
stat_go_uri: "/api/stat/go"
|
33
|
+
stat_app_uri: "/api/stat/app"
|
34
|
+
config_uri: "/api/config"
|
35
|
+
sys_stat_uri: "/sys/stats"
|
36
|
+
metric_uri: "/metrics"
|
37
|
+
health_uri: "/healthz"
|
38
|
+
|
39
|
+
android:
|
40
|
+
enabled: false
|
41
|
+
apikey: ""
|
42
|
+
max_retry: 0 # resend fail notification, default value zero is disabled
|
43
|
+
|
44
|
+
ios:
|
45
|
+
enabled: true
|
46
|
+
key_base64: "MIIM+QIBAzCCDMAGCS==\n"
|
47
|
+
key_type: "p12" # could be pem, p12 or p8 type
|
48
|
+
password: "123" # certificate password, default as empty string.
|
49
|
+
production: true
|
50
|
+
max_retry: 0 # resend fail notification, default value zero is disabled
|
51
|
+
key_id: "" # KeyID from developer account (Certificates, Identifiers & Profiles -> Keys)
|
52
|
+
team_id: "" # TeamID from developer account (View Account -> Membership)
|
53
|
+
|
54
|
+
log:
|
55
|
+
format: "string" # string or json
|
56
|
+
access_log: "stdout" # stdout: output to console, or define log path like "log/access_log"
|
57
|
+
access_level: "debug"
|
58
|
+
error_log: "stderr" # stderr: output to console, or define log path like "log/error_log"
|
59
|
+
error_level: "error"
|
60
|
+
hide_token: true
|
61
|
+
|
62
|
+
stat:
|
63
|
+
engine: "memory" # support memory, redis, boltdb, buntdb or leveldb
|
data/lib/action_push.rb
ADDED
@@ -0,0 +1,33 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
require 'forwardable'
|
4
|
+
require 'action_push/version'
|
5
|
+
require 'action_push/errors'
|
6
|
+
|
7
|
+
module ActionPush
|
8
|
+
autoload :Base, 'action_push/base'
|
9
|
+
autoload :Envelope, 'action_push/envelope'
|
10
|
+
autoload :Util, 'action_push/util'
|
11
|
+
|
12
|
+
module Concerns
|
13
|
+
autoload :ClassMethodDelivery, 'action_push/concerns/class_method_delivery'
|
14
|
+
autoload :RegisterDefault, 'action_push/concerns/register_default'
|
15
|
+
autoload :RegisterDeliveryMethod, 'action_push/concerns/register_delivery_method'
|
16
|
+
end
|
17
|
+
|
18
|
+
module Delivery
|
19
|
+
autoload :Explosion, 'action_push/delivery/explosion'
|
20
|
+
autoload :Gorush, 'action_push/delivery/gorush'
|
21
|
+
autoload :Memory, 'action_push/delivery/memory'
|
22
|
+
end
|
23
|
+
|
24
|
+
module Provider
|
25
|
+
autoload :Base, 'action_push/provider/base'
|
26
|
+
autoload :Test, 'action_push/provider/test'
|
27
|
+
end
|
28
|
+
|
29
|
+
module Ios
|
30
|
+
autoload :Message, 'action_push/ios/message'
|
31
|
+
autoload :Alert, 'action_push/ios/alert'
|
32
|
+
end
|
33
|
+
end
|
@@ -0,0 +1,64 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
module ActionPush
|
4
|
+
class Base
|
5
|
+
extend Concerns::ClassMethodDelivery
|
6
|
+
extend Concerns::RegisterDefault
|
7
|
+
extend Concerns::RegisterDeliveryMethod
|
8
|
+
|
9
|
+
register_default :ios, Ios::Message.new
|
10
|
+
|
11
|
+
attr_accessor :action_name
|
12
|
+
|
13
|
+
def self.inherited(subclass)
|
14
|
+
super
|
15
|
+
|
16
|
+
defaults.each do |name, placeholder|
|
17
|
+
subclass.register_default name, placeholder.clone
|
18
|
+
end
|
19
|
+
|
20
|
+
delivery_methods.each do |name, handler|
|
21
|
+
subclass.register_delivery_method(name, handler)
|
22
|
+
end
|
23
|
+
end
|
24
|
+
|
25
|
+
def initialize(action_name: nil)
|
26
|
+
@action_name = action_name
|
27
|
+
end
|
28
|
+
|
29
|
+
def envelope
|
30
|
+
@envelope ||= Envelope.new do |env|
|
31
|
+
self.class.defaults.each do |name, placeholder|
|
32
|
+
env.add(name, placeholder.dup)
|
33
|
+
end
|
34
|
+
end
|
35
|
+
end
|
36
|
+
|
37
|
+
# @return [Provider::Envelope]
|
38
|
+
def push(provider, attributes = {})
|
39
|
+
push = envelope.for(provider)
|
40
|
+
|
41
|
+
push.title = envelope.title if envelope.title
|
42
|
+
push.body = envelope.body if envelope.body
|
43
|
+
push.payload = envelope.payload if envelope.payload
|
44
|
+
push.scheduled = true
|
45
|
+
push.delivery_method = self.class.delivery_methods.fetch(provider, Delivery::Explosion)
|
46
|
+
|
47
|
+
# after all
|
48
|
+
push.assign(attributes)
|
49
|
+
yield(push) if block_given?
|
50
|
+
|
51
|
+
envelope
|
52
|
+
end
|
53
|
+
|
54
|
+
def translate(key, options = {})
|
55
|
+
I18n.translate(key, { scope: i18n_scope }.merge(options))
|
56
|
+
end
|
57
|
+
|
58
|
+
def i18n_scope
|
59
|
+
"#{Util.underscore(self.class.to_s)}.#{action_name}"
|
60
|
+
end
|
61
|
+
|
62
|
+
alias_method :t, :translate
|
63
|
+
end
|
64
|
+
end
|
@@ -0,0 +1,36 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
module ActionPush
|
4
|
+
module Concerns
|
5
|
+
module ClassMethodDelivery
|
6
|
+
# Acts like ActionMailer::Base
|
7
|
+
#
|
8
|
+
# class ApplePush < ActionPush
|
9
|
+
# def welcome
|
10
|
+
# # ....
|
11
|
+
# end
|
12
|
+
# end
|
13
|
+
#
|
14
|
+
# ApplePush.new.welcome will build PUSH message, but not send it
|
15
|
+
# ApplePush.welcome will build PUSH message and DELIVER it
|
16
|
+
#
|
17
|
+
# @return [Envelope]
|
18
|
+
def method_missing(method, *argv, &block)
|
19
|
+
return super unless action_methods.include?(method)
|
20
|
+
|
21
|
+
instance = new(action_name: method)
|
22
|
+
instance.public_send(method, *argv, &block)
|
23
|
+
instance.envelope.deliver
|
24
|
+
instance.envelope
|
25
|
+
end
|
26
|
+
|
27
|
+
def respond_to_missing?(method_name, include_private = false)
|
28
|
+
action_methods.include?(method_name) || super
|
29
|
+
end
|
30
|
+
|
31
|
+
def action_methods
|
32
|
+
@action_methods ||= public_instance_methods(false).to_set
|
33
|
+
end
|
34
|
+
end
|
35
|
+
end
|
36
|
+
end
|
@@ -0,0 +1,23 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
module ActionPush
|
4
|
+
module Concerns
|
5
|
+
module RegisterDefault
|
6
|
+
def defaults
|
7
|
+
@defaults ||= {}
|
8
|
+
end
|
9
|
+
|
10
|
+
def register_default(provider, placeholder)
|
11
|
+
defaults[provider] = placeholder.dup.freeze
|
12
|
+
end
|
13
|
+
|
14
|
+
def default(provider)
|
15
|
+
placeholder = defaults[provider].dup
|
16
|
+
|
17
|
+
yield(placeholder) if block_given?
|
18
|
+
|
19
|
+
register_default(provider, placeholder)
|
20
|
+
end
|
21
|
+
end
|
22
|
+
end
|
23
|
+
end
|
@@ -0,0 +1,15 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
module ActionPush
|
4
|
+
module Concerns
|
5
|
+
module RegisterDeliveryMethod
|
6
|
+
def delivery_methods
|
7
|
+
@delivery_methods ||= {}
|
8
|
+
end
|
9
|
+
|
10
|
+
def register_delivery_method(name, handler)
|
11
|
+
delivery_methods[name] = handler
|
12
|
+
end
|
13
|
+
end
|
14
|
+
end
|
15
|
+
end
|
@@ -0,0 +1,91 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
require 'json'
|
4
|
+
require 'net/http'
|
5
|
+
|
6
|
+
module ActionPush
|
7
|
+
module Delivery
|
8
|
+
# cli = ActionPush::Delivery::Gorush.new(url: 'http://localhost:8088/api/push', topic: 'com.app.id')
|
9
|
+
#
|
10
|
+
# push = ActionPush::Ios::Message.new do |p|
|
11
|
+
# p.title = 'Title'
|
12
|
+
# p.thread_id = 'comments'
|
13
|
+
# p.badge = 10
|
14
|
+
# p.body = 'Body'
|
15
|
+
# p.token = '4589***A938'
|
16
|
+
# end
|
17
|
+
#
|
18
|
+
# cli.send_to_apple(push)
|
19
|
+
class Gorush
|
20
|
+
attr_accessor :url
|
21
|
+
attr_accessor :logger
|
22
|
+
attr_accessor :topic
|
23
|
+
|
24
|
+
def initialize(params = {})
|
25
|
+
params.each { |key, value| public_send("#{key}=", value) }
|
26
|
+
yield(self) if block_given?
|
27
|
+
end
|
28
|
+
|
29
|
+
# @param [Ios::Message]
|
30
|
+
# @return [Net::HTTPResponse]
|
31
|
+
# rubocop:disable Metrics/MethodLength
|
32
|
+
def send_to_apple(push)
|
33
|
+
alert = push.alert
|
34
|
+
|
35
|
+
notification = {
|
36
|
+
tokens: [push.token],
|
37
|
+
platform: 1,
|
38
|
+
'thread-id': push.thread_id,
|
39
|
+
content_available: push.content_available,
|
40
|
+
topic: topic,
|
41
|
+
badge: push.badge,
|
42
|
+
category: push.category,
|
43
|
+
data: push.payload,
|
44
|
+
sound: {
|
45
|
+
name: push.sound
|
46
|
+
},
|
47
|
+
alert: {
|
48
|
+
title: alert.title,
|
49
|
+
body: alert.body,
|
50
|
+
'action-loc-key': alert.action_loc_key,
|
51
|
+
'launch-image': alert.launch_image,
|
52
|
+
'loc-args': alert.loc_args,
|
53
|
+
'loc-key': alert.loc_key,
|
54
|
+
'title-loc-args': alert.title_loc_args,
|
55
|
+
'title-loc-key': alert.title_loc_key
|
56
|
+
}
|
57
|
+
}
|
58
|
+
|
59
|
+
response = post(notifications: [notification])
|
60
|
+
|
61
|
+
push.delivery_response = response
|
62
|
+
push.delivered = response.is_a?(Net::HTTPSuccess)
|
63
|
+
|
64
|
+
response
|
65
|
+
end
|
66
|
+
# rubocop:enable Metrics/MethodLength
|
67
|
+
|
68
|
+
private
|
69
|
+
|
70
|
+
def uri
|
71
|
+
@uri ||= URI(url)
|
72
|
+
end
|
73
|
+
|
74
|
+
def post(json = {})
|
75
|
+
req = Net::HTTP::Post.new(uri.path, 'Content-Type' => 'application/json')
|
76
|
+
req.body = json.to_json
|
77
|
+
transport.start do |h|
|
78
|
+
h.request(req)
|
79
|
+
end
|
80
|
+
end
|
81
|
+
|
82
|
+
def transport
|
83
|
+
@transport ||= begin
|
84
|
+
http = Net::HTTP.new(uri.host, uri.port)
|
85
|
+
http.set_debug_output(logger) if logger
|
86
|
+
http
|
87
|
+
end
|
88
|
+
end
|
89
|
+
end
|
90
|
+
end
|
91
|
+
end
|