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
@@ -0,0 +1,22 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
module ActionPush
|
4
|
+
module Delivery
|
5
|
+
class Memory
|
6
|
+
class << self
|
7
|
+
include Enumerable
|
8
|
+
extend Forwardable
|
9
|
+
|
10
|
+
def_delegators :pushes, :each, :clear, :last, :first, :size, :[]
|
11
|
+
|
12
|
+
def call(push)
|
13
|
+
pushes.push(push)
|
14
|
+
end
|
15
|
+
|
16
|
+
def pushes
|
17
|
+
@pushes ||= []
|
18
|
+
end
|
19
|
+
end
|
20
|
+
end
|
21
|
+
end
|
22
|
+
end
|
@@ -0,0 +1,47 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
module ActionPush
|
4
|
+
# envelope = ActionPush::Envelope.new(title: 'Alert', body: 'You ave 2 messages')
|
5
|
+
# envelope.add(:ios, ActionPush::Ios::Message.new)
|
6
|
+
#
|
7
|
+
# envelope.for(:ios) do |ios|
|
8
|
+
# ios.sound = 'wow.mp3'
|
9
|
+
# end
|
10
|
+
class Envelope
|
11
|
+
attr_accessor :title
|
12
|
+
attr_accessor :body
|
13
|
+
attr_accessor :payload
|
14
|
+
|
15
|
+
def initialize(params = {})
|
16
|
+
params.each { |name, value| public_send("#{name}=", value) }
|
17
|
+
|
18
|
+
yield(self) if block_given?
|
19
|
+
end
|
20
|
+
|
21
|
+
def add(provider, push)
|
22
|
+
pushes[provider] = push
|
23
|
+
end
|
24
|
+
|
25
|
+
def for(provider)
|
26
|
+
push = pushes.fetch(provider) do
|
27
|
+
raise ArgumentError, "provider with name <#{provider}> was not registered"
|
28
|
+
end
|
29
|
+
|
30
|
+
block_given? ? yield(push) : push
|
31
|
+
end
|
32
|
+
|
33
|
+
alias_method :[], :for
|
34
|
+
|
35
|
+
def pushes
|
36
|
+
@pushes ||= {}
|
37
|
+
end
|
38
|
+
|
39
|
+
def deliver
|
40
|
+
pushes.each do |_name, push|
|
41
|
+
push.deliver if push.scheduled
|
42
|
+
end
|
43
|
+
|
44
|
+
nil
|
45
|
+
end
|
46
|
+
end
|
47
|
+
end
|
@@ -0,0 +1,50 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
module ActionPush
|
4
|
+
module Ios
|
5
|
+
# @refs https://developer.apple.com/library/archive/documentation/NetworkingInternet/Conceptual/RemoteNotificationsPG/PayloadKeyReference.html#//apple_ref/doc/uid/TP40008194-CH17-SW5
|
6
|
+
class Alert
|
7
|
+
# [String]
|
8
|
+
# A short string describing the purpose of the notification.
|
9
|
+
# Apple Watch displays this string as part of the notification interface.
|
10
|
+
# This string is displayed only briefly and should be crafted so that
|
11
|
+
# it can be understood quickly.
|
12
|
+
attr_accessor :title
|
13
|
+
|
14
|
+
# [String]
|
15
|
+
# The text of the alert message
|
16
|
+
attr_accessor :body
|
17
|
+
|
18
|
+
# [String, nil]
|
19
|
+
# The key to a title string in the Localizable.strings file for the current localization.
|
20
|
+
# The key string can be formatted with %@ and %n$@ specifiers to take the variables specified in
|
21
|
+
# the title-loc-args array
|
22
|
+
attr_accessor :title_loc_key
|
23
|
+
|
24
|
+
# [Array<String>, nil]
|
25
|
+
# Variable string values to appear in place of the format specifiers in title-loc-key
|
26
|
+
attr_accessor :title_loc_args
|
27
|
+
|
28
|
+
# [String, nil]
|
29
|
+
# If a string is specified, the system displays an alert that includes the Close and View buttons.
|
30
|
+
# The string is used as a key to get a localized string in the current localization to use for the
|
31
|
+
# right button’s title instead of “View”
|
32
|
+
attr_accessor :action_loc_key
|
33
|
+
|
34
|
+
# [String]
|
35
|
+
# A key to an alert-message string in a Localizable.strings file for the current localization
|
36
|
+
# (which is set by the user’s language preference). The key string can be formatted with
|
37
|
+
# %@ and %n$@ specifiers to take the variables specified in the loc-args array
|
38
|
+
attr_accessor :loc_key
|
39
|
+
|
40
|
+
# [Array<String>]
|
41
|
+
# Variable string values to appear in place of the format specifiers in loc-key.
|
42
|
+
attr_accessor :loc_args
|
43
|
+
|
44
|
+
# [String]
|
45
|
+
# The filename of an image file in the app bundle, with or without the filename extension.
|
46
|
+
# The image is used as the launch image when users tap the action button or move the action slider
|
47
|
+
attr_accessor :launch_image
|
48
|
+
end
|
49
|
+
end
|
50
|
+
end
|
@@ -0,0 +1,64 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
module ActionPush
|
4
|
+
module Ios
|
5
|
+
# @refs https://developer.apple.com/library/archive/documentation/NetworkingInternet/Conceptual/RemoteNotificationsPG/PayloadKeyReference.html#//apple_ref/doc/uid/TP40008194-CH17-SW5
|
6
|
+
class Message < Provider::Base
|
7
|
+
# [Integer]
|
8
|
+
# Include this key when you want the system to modify the badge of your app icon.
|
9
|
+
# If this key is not included in the dictionary, the badge is not changed.
|
10
|
+
# To remove the badge, set the value of this key to 0.
|
11
|
+
attr_accessor :badge
|
12
|
+
|
13
|
+
# [String]
|
14
|
+
# Include this key when you want the system to play a sound.
|
15
|
+
# The value of this key is the name of a sound file in your app’s main bundle or in the Library/Sounds
|
16
|
+
attr_accessor :sound
|
17
|
+
|
18
|
+
# [Integer]
|
19
|
+
# Include this key with a value of 1 to configure a background update notification.
|
20
|
+
# When this key is present, the system wakes up your app in the background and delivers the
|
21
|
+
# notification to its app delegate
|
22
|
+
attr_accessor :content_available
|
23
|
+
|
24
|
+
# [String]
|
25
|
+
# Provide this key with a string value that represents the notification’s type.
|
26
|
+
# This value corresponds to the value in the identifier
|
27
|
+
attr_accessor :category
|
28
|
+
|
29
|
+
# [String]
|
30
|
+
# Provide this key with a string value that represents the app-specific identifier
|
31
|
+
# for grouping notifications
|
32
|
+
attr_accessor :thread_id
|
33
|
+
|
34
|
+
def alert=(alert)
|
35
|
+
unless alert.is_a?(Alert)
|
36
|
+
raise ArgumentError, "alert should be an instance of #{Alert}, got: <#{alert.class}>"
|
37
|
+
end
|
38
|
+
|
39
|
+
@alert = alert
|
40
|
+
end
|
41
|
+
|
42
|
+
def alert
|
43
|
+
@alert ||= Alert.new
|
44
|
+
block_given? ? yield(@alert) : @alert
|
45
|
+
end
|
46
|
+
|
47
|
+
def title=(value)
|
48
|
+
alert.title = value
|
49
|
+
end
|
50
|
+
|
51
|
+
def body=(value)
|
52
|
+
alert.body = value
|
53
|
+
end
|
54
|
+
|
55
|
+
def title
|
56
|
+
alert.title
|
57
|
+
end
|
58
|
+
|
59
|
+
def body
|
60
|
+
alert.body
|
61
|
+
end
|
62
|
+
end
|
63
|
+
end
|
64
|
+
end
|
@@ -0,0 +1,64 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
module ActionPush
|
4
|
+
module Provider
|
5
|
+
class Base
|
6
|
+
# [Boolean]
|
7
|
+
# If the PUSH message scheduled to deliver
|
8
|
+
attr_accessor :scheduled
|
9
|
+
|
10
|
+
# [String]
|
11
|
+
# Device token
|
12
|
+
attr_accessor :token
|
13
|
+
|
14
|
+
# extra data (JSON) to sent with a PUSH
|
15
|
+
# message as a payload
|
16
|
+
attr_accessor :payload
|
17
|
+
|
18
|
+
# [Proc]
|
19
|
+
# object which is responds to #call
|
20
|
+
attr_accessor :delivery_method
|
21
|
+
|
22
|
+
# [any]
|
23
|
+
# response from the delivery gate
|
24
|
+
attr_accessor :delivery_response
|
25
|
+
|
26
|
+
# [Boolean]
|
27
|
+
# +true+ if push was successfully sent to the delivery gate
|
28
|
+
attr_accessor :delivered
|
29
|
+
|
30
|
+
def initialize(params = {})
|
31
|
+
assign(params)
|
32
|
+
|
33
|
+
yield(self) if block_given?
|
34
|
+
end
|
35
|
+
|
36
|
+
# @return [Self]
|
37
|
+
def assign(params = {})
|
38
|
+
params.each { |key, value| public_send("#{key}=", value) }
|
39
|
+
|
40
|
+
self
|
41
|
+
end
|
42
|
+
|
43
|
+
def title=(_value)
|
44
|
+
raise NotImplementedError, __method__
|
45
|
+
end
|
46
|
+
|
47
|
+
def body=(_value)
|
48
|
+
raise NotImplementedError, __method__
|
49
|
+
end
|
50
|
+
|
51
|
+
def title
|
52
|
+
raise NotImplementedError, __method__
|
53
|
+
end
|
54
|
+
|
55
|
+
def body
|
56
|
+
raise NotImplementedError, __method__
|
57
|
+
end
|
58
|
+
|
59
|
+
def deliver
|
60
|
+
delivery_method.call(self)
|
61
|
+
end
|
62
|
+
end
|
63
|
+
end
|
64
|
+
end
|
@@ -0,0 +1,20 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
module ActionPush
|
4
|
+
module Util
|
5
|
+
module_function
|
6
|
+
|
7
|
+
# @copy https://apidock.com/rails/ActiveSupport/Inflector/underscore
|
8
|
+
def underscore(camel_cased_word)
|
9
|
+
return camel_cased_word unless /[A-Z-]|::/.match?(camel_cased_word)
|
10
|
+
|
11
|
+
word = camel_cased_word.to_s.gsub('::', '/')
|
12
|
+
word.gsub!(/([A-Z\d]+)([A-Z][a-z])/, '\1_\2')
|
13
|
+
word.gsub!(/([a-z\d])([A-Z])/, '\1_\2')
|
14
|
+
word.tr!('-', '_')
|
15
|
+
word.downcase!
|
16
|
+
|
17
|
+
word
|
18
|
+
end
|
19
|
+
end
|
20
|
+
end
|
metadata
ADDED
@@ -0,0 +1,190 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: action_push
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
version: 0.1.0
|
5
|
+
platform: ruby
|
6
|
+
authors:
|
7
|
+
- Aliaksandr Shylau
|
8
|
+
autorequire:
|
9
|
+
bindir: exe
|
10
|
+
cert_chain: []
|
11
|
+
date: 2020-01-30 00:00:00.000000000 Z
|
12
|
+
dependencies:
|
13
|
+
- !ruby/object:Gem::Dependency
|
14
|
+
name: bundler
|
15
|
+
requirement: !ruby/object:Gem::Requirement
|
16
|
+
requirements:
|
17
|
+
- - "~>"
|
18
|
+
- !ruby/object:Gem::Version
|
19
|
+
version: '1.17'
|
20
|
+
type: :development
|
21
|
+
prerelease: false
|
22
|
+
version_requirements: !ruby/object:Gem::Requirement
|
23
|
+
requirements:
|
24
|
+
- - "~>"
|
25
|
+
- !ruby/object:Gem::Version
|
26
|
+
version: '1.17'
|
27
|
+
- !ruby/object:Gem::Dependency
|
28
|
+
name: rake
|
29
|
+
requirement: !ruby/object:Gem::Requirement
|
30
|
+
requirements:
|
31
|
+
- - "~>"
|
32
|
+
- !ruby/object:Gem::Version
|
33
|
+
version: '10.0'
|
34
|
+
type: :development
|
35
|
+
prerelease: false
|
36
|
+
version_requirements: !ruby/object:Gem::Requirement
|
37
|
+
requirements:
|
38
|
+
- - "~>"
|
39
|
+
- !ruby/object:Gem::Version
|
40
|
+
version: '10.0'
|
41
|
+
- !ruby/object:Gem::Dependency
|
42
|
+
name: rspec
|
43
|
+
requirement: !ruby/object:Gem::Requirement
|
44
|
+
requirements:
|
45
|
+
- - "~>"
|
46
|
+
- !ruby/object:Gem::Version
|
47
|
+
version: '3.0'
|
48
|
+
type: :development
|
49
|
+
prerelease: false
|
50
|
+
version_requirements: !ruby/object:Gem::Requirement
|
51
|
+
requirements:
|
52
|
+
- - "~>"
|
53
|
+
- !ruby/object:Gem::Version
|
54
|
+
version: '3.0'
|
55
|
+
- !ruby/object:Gem::Dependency
|
56
|
+
name: pry
|
57
|
+
requirement: !ruby/object:Gem::Requirement
|
58
|
+
requirements:
|
59
|
+
- - ">="
|
60
|
+
- !ruby/object:Gem::Version
|
61
|
+
version: '0'
|
62
|
+
type: :development
|
63
|
+
prerelease: false
|
64
|
+
version_requirements: !ruby/object:Gem::Requirement
|
65
|
+
requirements:
|
66
|
+
- - ">="
|
67
|
+
- !ruby/object:Gem::Version
|
68
|
+
version: '0'
|
69
|
+
- !ruby/object:Gem::Dependency
|
70
|
+
name: rubocop
|
71
|
+
requirement: !ruby/object:Gem::Requirement
|
72
|
+
requirements:
|
73
|
+
- - ">="
|
74
|
+
- !ruby/object:Gem::Version
|
75
|
+
version: '0'
|
76
|
+
type: :development
|
77
|
+
prerelease: false
|
78
|
+
version_requirements: !ruby/object:Gem::Requirement
|
79
|
+
requirements:
|
80
|
+
- - ">="
|
81
|
+
- !ruby/object:Gem::Version
|
82
|
+
version: '0'
|
83
|
+
- !ruby/object:Gem::Dependency
|
84
|
+
name: rubocop-performance
|
85
|
+
requirement: !ruby/object:Gem::Requirement
|
86
|
+
requirements:
|
87
|
+
- - ">="
|
88
|
+
- !ruby/object:Gem::Version
|
89
|
+
version: '0'
|
90
|
+
type: :development
|
91
|
+
prerelease: false
|
92
|
+
version_requirements: !ruby/object:Gem::Requirement
|
93
|
+
requirements:
|
94
|
+
- - ">="
|
95
|
+
- !ruby/object:Gem::Version
|
96
|
+
version: '0'
|
97
|
+
- !ruby/object:Gem::Dependency
|
98
|
+
name: webmock
|
99
|
+
requirement: !ruby/object:Gem::Requirement
|
100
|
+
requirements:
|
101
|
+
- - ">="
|
102
|
+
- !ruby/object:Gem::Version
|
103
|
+
version: '0'
|
104
|
+
type: :development
|
105
|
+
prerelease: false
|
106
|
+
version_requirements: !ruby/object:Gem::Requirement
|
107
|
+
requirements:
|
108
|
+
- - ">="
|
109
|
+
- !ruby/object:Gem::Version
|
110
|
+
version: '0'
|
111
|
+
- !ruby/object:Gem::Dependency
|
112
|
+
name: i18n
|
113
|
+
requirement: !ruby/object:Gem::Requirement
|
114
|
+
requirements:
|
115
|
+
- - ">="
|
116
|
+
- !ruby/object:Gem::Version
|
117
|
+
version: '0'
|
118
|
+
type: :development
|
119
|
+
prerelease: false
|
120
|
+
version_requirements: !ruby/object:Gem::Requirement
|
121
|
+
requirements:
|
122
|
+
- - ">="
|
123
|
+
- !ruby/object:Gem::Version
|
124
|
+
version: '0'
|
125
|
+
description: It includes includes built-in support for the GORUSH gateway
|
126
|
+
email:
|
127
|
+
- alex.shilov.by@gmail.com
|
128
|
+
executables: []
|
129
|
+
extensions: []
|
130
|
+
extra_rdoc_files: []
|
131
|
+
files:
|
132
|
+
- ".gitignore"
|
133
|
+
- ".rspec"
|
134
|
+
- ".rubocop.yml"
|
135
|
+
- ".travis.yml"
|
136
|
+
- Gemfile
|
137
|
+
- Gemfile.lock
|
138
|
+
- LICENSE.txt
|
139
|
+
- Makefile
|
140
|
+
- README.md
|
141
|
+
- Rakefile
|
142
|
+
- action_push.gemspec
|
143
|
+
- bin/console
|
144
|
+
- bin/release
|
145
|
+
- bin/setup
|
146
|
+
- docker-compose.yml
|
147
|
+
- gorush.ci.yml
|
148
|
+
- gorush.example.yml
|
149
|
+
- gorush.yml
|
150
|
+
- lib/action_push.rb
|
151
|
+
- lib/action_push/base.rb
|
152
|
+
- lib/action_push/concerns/class_method_delivery.rb
|
153
|
+
- lib/action_push/concerns/register_default.rb
|
154
|
+
- lib/action_push/concerns/register_delivery_method.rb
|
155
|
+
- lib/action_push/delivery/explosion.rb
|
156
|
+
- lib/action_push/delivery/gorush.rb
|
157
|
+
- lib/action_push/delivery/memory.rb
|
158
|
+
- lib/action_push/envelope.rb
|
159
|
+
- lib/action_push/errors.rb
|
160
|
+
- lib/action_push/ios/alert.rb
|
161
|
+
- lib/action_push/ios/message.rb
|
162
|
+
- lib/action_push/provider/base.rb
|
163
|
+
- lib/action_push/provider/test.rb
|
164
|
+
- lib/action_push/util.rb
|
165
|
+
- lib/action_push/version.rb
|
166
|
+
homepage: https://github.com/shlima/action_push
|
167
|
+
licenses:
|
168
|
+
- MIT
|
169
|
+
metadata: {}
|
170
|
+
post_install_message:
|
171
|
+
rdoc_options: []
|
172
|
+
require_paths:
|
173
|
+
- lib
|
174
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
175
|
+
requirements:
|
176
|
+
- - ">="
|
177
|
+
- !ruby/object:Gem::Version
|
178
|
+
version: '0'
|
179
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
180
|
+
requirements:
|
181
|
+
- - ">="
|
182
|
+
- !ruby/object:Gem::Version
|
183
|
+
version: '0'
|
184
|
+
requirements: []
|
185
|
+
rubygems_version: 3.0.6
|
186
|
+
signing_key:
|
187
|
+
specification_version: 4
|
188
|
+
summary: ActionPush is a lightweight tool which allows you to organize Push notifications
|
189
|
+
the same way Action Mailer does
|
190
|
+
test_files: []
|