firepush 0.1.1 → 0.2.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/.dockerignore +6 -0
- data/.rubocop.yml +8 -0
- data/.travis.yml +3 -3
- data/Dockerfile +17 -0
- data/README.md +29 -8
- data/firepush.gemspec +1 -0
- data/lib/firepush.rb +8 -6
- data/lib/firepush/client.rb +1 -1
- data/lib/firepush/message.rb +14 -13
- data/lib/firepush/message_type/builder.rb +3 -14
- data/lib/firepush/message_types.rb +32 -0
- data/lib/firepush/recipient/builder.rb +16 -5
- data/lib/firepush/recipient/condition.rb +28 -0
- data/lib/firepush/version.rb +1 -1
- metadata +21 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: e7d7d6a2b469b0123ac7bafea8198f40b8a739548d45ab4940ebbc16f8316170
|
4
|
+
data.tar.gz: b9d2d7d2998108930f1f120747486e8ee057adf2213b91a7f4e8ea2557248c66
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 6549b9cb0afb7b808dcbda164c5f257cae152af884cc94501280b39b31e3bacdcfd7edaf92530aa0edcaf1f52e1a0627e5aa55a18014c46da90304c8824710b8
|
7
|
+
data.tar.gz: 37e9c3654f5dce4b50cb02f2de10589225eb7bc768d61985c23c5d2ae05ab9357c78062623832b70f3bbeca3bceebd27840a0568eb23f6c275e56302f07eaa98
|
data/.dockerignore
ADDED
data/.rubocop.yml
ADDED
data/.travis.yml
CHANGED
data/Dockerfile
ADDED
@@ -0,0 +1,17 @@
|
|
1
|
+
FROM ruby:2.6.1-alpine
|
2
|
+
|
3
|
+
RUN apk add \
|
4
|
+
gcc \
|
5
|
+
git \
|
6
|
+
libc-dev \
|
7
|
+
make
|
8
|
+
|
9
|
+
WORKDIR /app
|
10
|
+
|
11
|
+
COPY firepush.gemspec /app/firepush.gemspec
|
12
|
+
COPY Gemfile /app/Gemfile
|
13
|
+
COPY lib/firepush/version.rb /app/lib/firepush/version.rb
|
14
|
+
|
15
|
+
RUN bundle install
|
16
|
+
|
17
|
+
COPY . /app
|
data/README.md
CHANGED
@@ -9,14 +9,14 @@ Firepush is [Firebase Cloud Messaging](https://firebase.google.com/docs/cloud-me
|
|
9
9
|
Add this line to your application's Gemfile:
|
10
10
|
|
11
11
|
```ruby
|
12
|
-
gem 'firepush'
|
12
|
+
gem 'firepush'
|
13
13
|
```
|
14
14
|
|
15
15
|
And then execute:
|
16
16
|
|
17
17
|
$ bundle install
|
18
18
|
|
19
|
-
Or install it yourself as:
|
19
|
+
Or install it yourself as:
|
20
20
|
|
21
21
|
$ gem install firepush
|
22
22
|
|
@@ -35,24 +35,45 @@ client = Firepush::Client.new(
|
|
35
35
|
)
|
36
36
|
|
37
37
|
# 1. Notification message to a single device
|
38
|
-
|
39
38
|
client.push(
|
40
39
|
notification: {
|
41
|
-
title: "
|
42
|
-
body:
|
40
|
+
title: "Hello",
|
41
|
+
body: "from firepush!",
|
43
42
|
},
|
44
|
-
token: "<
|
43
|
+
token: "<client token>",
|
45
44
|
)
|
46
45
|
|
47
46
|
# 2. Data message to a topic
|
47
|
+
client.push(
|
48
|
+
data: {
|
49
|
+
key: "foo",
|
50
|
+
key2: "bar",
|
51
|
+
},
|
52
|
+
topic: "news",
|
53
|
+
)
|
48
54
|
|
55
|
+
# 3. You can set both Notification/Data message types
|
49
56
|
client.push(
|
57
|
+
notification: {
|
58
|
+
title: "Hello",
|
59
|
+
body: "from firepush!",
|
60
|
+
},
|
50
61
|
data: {
|
51
|
-
key:
|
52
|
-
key2: "
|
62
|
+
key: "foo",
|
63
|
+
key2: "bar",
|
53
64
|
},
|
54
65
|
topic: "news",
|
55
66
|
)
|
67
|
+
|
68
|
+
# or you can set message beforehand.
|
69
|
+
client.message = {
|
70
|
+
notification: {
|
71
|
+
title: "hey"
|
72
|
+
body: "siri",
|
73
|
+
},
|
74
|
+
topic: "apple",
|
75
|
+
}
|
76
|
+
client.push
|
56
77
|
```
|
57
78
|
|
58
79
|
## Development
|
data/firepush.gemspec
CHANGED
data/lib/firepush.rb
CHANGED
@@ -1,8 +1,9 @@
|
|
1
1
|
# frozen_string_literal: true
|
2
2
|
|
3
3
|
module Firepush
|
4
|
-
autoload :Client,
|
5
|
-
autoload :Message,
|
4
|
+
autoload :Client, "firepush/client"
|
5
|
+
autoload :Message, "firepush/message"
|
6
|
+
autoload :MessageTypes, "firepush/message_types"
|
6
7
|
|
7
8
|
module MessageType
|
8
9
|
autoload :Base, "firepush/message_type/base"
|
@@ -12,10 +13,11 @@ module Firepush
|
|
12
13
|
end
|
13
14
|
|
14
15
|
module Recipient
|
15
|
-
autoload :Base,
|
16
|
-
autoload :Builder,
|
17
|
-
autoload :
|
18
|
-
autoload :
|
16
|
+
autoload :Base, "firepush/recipient/base"
|
17
|
+
autoload :Builder, "firepush/recipient/builder"
|
18
|
+
autoload :Condition, "firepush/recipient/condition"
|
19
|
+
autoload :Token, "firepush/recipient/token"
|
20
|
+
autoload :Topic, "firepush/recipient/topic"
|
19
21
|
end
|
20
22
|
|
21
23
|
autoload :HelperMethods, "firepush/helper_methods"
|
data/lib/firepush/client.rb
CHANGED
data/lib/firepush/message.rb
CHANGED
@@ -4,27 +4,29 @@ require "json"
|
|
4
4
|
|
5
5
|
module Firepush
|
6
6
|
class Message
|
7
|
-
attr_reader :recipient
|
8
|
-
attr_reader :
|
7
|
+
attr_reader :recipient # @return [Firepush::Recipient::Base]
|
8
|
+
attr_reader :message_types # @return [Firepush::MessageTypes]
|
9
9
|
|
10
10
|
# TODO: handle extra data in better way.
|
11
11
|
attr_reader :extra # @return [Hash]
|
12
12
|
|
13
13
|
# @param msg [Hash]
|
14
|
-
# @see lib/firepush/{
|
14
|
+
# @see lib/firepush/{recipient/*,message_types}.rb
|
15
15
|
# @raise [ArgumentError]
|
16
16
|
def initialize(msg)
|
17
17
|
msg = msg.dup
|
18
18
|
|
19
19
|
args = {}
|
20
|
-
|
21
|
-
|
20
|
+
Recipient::TYPES.each do |type|
|
21
|
+
args[type] = msg.delete(type) if msg.key?(type)
|
22
|
+
end
|
22
23
|
@recipient = Recipient::Builder.build(args)
|
23
24
|
|
24
25
|
args.clear
|
25
|
-
|
26
|
-
|
27
|
-
|
26
|
+
MessageType::TYPES.each do |type|
|
27
|
+
args[type] = msg.delete(type) if msg.key?(type)
|
28
|
+
end
|
29
|
+
@message_types = MessageTypes.new(args)
|
28
30
|
|
29
31
|
@extra = msg
|
30
32
|
end
|
@@ -36,7 +38,7 @@ module Firepush
|
|
36
38
|
|
37
39
|
# @return [Boolean]
|
38
40
|
def valid?
|
39
|
-
recipient.valid? &&
|
41
|
+
recipient.valid? && message_types.valid?
|
40
42
|
end
|
41
43
|
|
42
44
|
private
|
@@ -44,10 +46,9 @@ module Firepush
|
|
44
46
|
# @private
|
45
47
|
# @return [Hash]
|
46
48
|
def message
|
47
|
-
{
|
48
|
-
recipient.key
|
49
|
-
|
50
|
-
}.merge(extra)
|
49
|
+
message_types.message.merge({
|
50
|
+
recipient.key => recipient.value
|
51
|
+
}.merge(extra))
|
51
52
|
end
|
52
53
|
end
|
53
54
|
end
|
@@ -2,6 +2,9 @@
|
|
2
2
|
|
3
3
|
module Firepush
|
4
4
|
module MessageType
|
5
|
+
# TODO: support :android, :webpush and :apns
|
6
|
+
TYPES = %i(notification data)
|
7
|
+
|
5
8
|
class Builder
|
6
9
|
# @param args [Hash]
|
7
10
|
# @option args [Hash] :notification
|
@@ -14,8 +17,6 @@ module Firepush
|
|
14
17
|
# @see .build
|
15
18
|
def initialize(args)
|
16
19
|
@_args = args
|
17
|
-
|
18
|
-
check_args!
|
19
20
|
end
|
20
21
|
private_class_method :new
|
21
22
|
|
@@ -33,18 +34,6 @@ module Firepush
|
|
33
34
|
|
34
35
|
attr_reader :_args
|
35
36
|
|
36
|
-
# @private
|
37
|
-
# @raise [ArgumentError]
|
38
|
-
def check_args!
|
39
|
-
if notification? && data?
|
40
|
-
raise ::ArgumentError.new("Cannot set both :notification and :data")
|
41
|
-
end
|
42
|
-
|
43
|
-
if !notification? && !data?
|
44
|
-
raise ::ArgumentError.new("Must set either :notification or :data")
|
45
|
-
end
|
46
|
-
end
|
47
|
-
|
48
37
|
# @private
|
49
38
|
# @return [Boolean]
|
50
39
|
def data?
|
@@ -0,0 +1,32 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
module Firepush
|
4
|
+
class MessageTypes
|
5
|
+
attr_reader :types # @return [Array<Firepush::MessageType::Base>]
|
6
|
+
|
7
|
+
# @param args [Hash]
|
8
|
+
# @option args [Hash] :notification
|
9
|
+
# @option args [Hash] :data
|
10
|
+
def initialize(args)
|
11
|
+
valid_types = MessageType::TYPES.reduce([]) do |acc, type|
|
12
|
+
acc.push(type => args[type]) if args.key?(type)
|
13
|
+
acc
|
14
|
+
end
|
15
|
+
|
16
|
+
@types = valid_types.map { |type| MessageType::Builder.build(type) }
|
17
|
+
end
|
18
|
+
|
19
|
+
# @return [Hash]
|
20
|
+
def message
|
21
|
+
types.reduce({}) do |acc, type|
|
22
|
+
acc[type.key] = type.value
|
23
|
+
acc
|
24
|
+
end
|
25
|
+
end
|
26
|
+
|
27
|
+
# @return [Boolean]
|
28
|
+
def valid?
|
29
|
+
types.count > 0 && types.all?(&:valid?)
|
30
|
+
end
|
31
|
+
end
|
32
|
+
end
|
@@ -2,10 +2,13 @@
|
|
2
2
|
|
3
3
|
module Firepush
|
4
4
|
module Recipient
|
5
|
+
TYPES = %i(topic token condition)
|
6
|
+
|
5
7
|
class Builder
|
6
8
|
# @param args [Hash]
|
7
9
|
# @option args [Hash] :topic
|
8
10
|
# @option args [Hash] :token
|
11
|
+
# @option args [Hash] :condition
|
9
12
|
def self.build(args)
|
10
13
|
new(args).build
|
11
14
|
end
|
@@ -26,6 +29,8 @@ module Firepush
|
|
26
29
|
Topic.new(_args.fetch(:topic))
|
27
30
|
when token?
|
28
31
|
Token.new(_args.fetch(:token))
|
32
|
+
when condition?
|
33
|
+
Condition.new(_args.fetch(:condition))
|
29
34
|
end
|
30
35
|
end
|
31
36
|
|
@@ -36,13 +41,19 @@ module Firepush
|
|
36
41
|
# @private
|
37
42
|
# @raise [ArgumentError]
|
38
43
|
def check_args!
|
39
|
-
|
40
|
-
|
44
|
+
count = TYPES.reduce(0) do |sum, type|
|
45
|
+
sum += 1 if _args.key?(type)
|
46
|
+
sum
|
41
47
|
end
|
48
|
+
return if count == 1
|
42
49
|
|
43
|
-
|
44
|
-
|
45
|
-
|
50
|
+
raise ::ArgumentError.new("Have to set one of :topic, :token, or :condition")
|
51
|
+
end
|
52
|
+
|
53
|
+
# @private
|
54
|
+
# @return [Boolean]
|
55
|
+
def condition?
|
56
|
+
_args.key?(:condition)
|
46
57
|
end
|
47
58
|
|
48
59
|
# @private
|
@@ -0,0 +1,28 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
module Firepush
|
4
|
+
module Recipient
|
5
|
+
class Condition < Base
|
6
|
+
attr_reader :condition # @return [String]
|
7
|
+
|
8
|
+
# @param condition [String]
|
9
|
+
def initialize(condition)
|
10
|
+
@condition = condition
|
11
|
+
end
|
12
|
+
|
13
|
+
# @override
|
14
|
+
# @return [Boolean]
|
15
|
+
# @see https://firebase.google.com/docs/cloud-messaging/send-message?hl=en
|
16
|
+
# @note Doesn't add parser for the condition string because it can be mess
|
17
|
+
def valid?
|
18
|
+
valid_str?(condition)
|
19
|
+
end
|
20
|
+
|
21
|
+
# @override
|
22
|
+
# @return [String]
|
23
|
+
def value
|
24
|
+
condition
|
25
|
+
end
|
26
|
+
end
|
27
|
+
end
|
28
|
+
end
|
data/lib/firepush/version.rb
CHANGED
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: firepush
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.
|
4
|
+
version: 0.2.0
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- mmyoji
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2019-02-
|
11
|
+
date: 2019-02-24 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: bundler
|
@@ -52,6 +52,20 @@ dependencies:
|
|
52
52
|
- - "~>"
|
53
53
|
- !ruby/object:Gem::Version
|
54
54
|
version: '3.0'
|
55
|
+
- !ruby/object:Gem::Dependency
|
56
|
+
name: rubocop
|
57
|
+
requirement: !ruby/object:Gem::Requirement
|
58
|
+
requirements:
|
59
|
+
- - "~>"
|
60
|
+
- !ruby/object:Gem::Version
|
61
|
+
version: '0.64'
|
62
|
+
type: :development
|
63
|
+
prerelease: false
|
64
|
+
version_requirements: !ruby/object:Gem::Requirement
|
65
|
+
requirements:
|
66
|
+
- - "~>"
|
67
|
+
- !ruby/object:Gem::Version
|
68
|
+
version: '0.64'
|
55
69
|
description: Firebase Cloud Messaging Client library which uses HTTP v1 API.
|
56
70
|
email:
|
57
71
|
- mmyoji@gmail.com
|
@@ -59,10 +73,13 @@ executables: []
|
|
59
73
|
extensions: []
|
60
74
|
extra_rdoc_files: []
|
61
75
|
files:
|
76
|
+
- ".dockerignore"
|
62
77
|
- ".gitignore"
|
63
78
|
- ".rspec"
|
79
|
+
- ".rubocop.yml"
|
64
80
|
- ".travis.yml"
|
65
81
|
- CODE_OF_CONDUCT.md
|
82
|
+
- Dockerfile
|
66
83
|
- Gemfile
|
67
84
|
- LICENSE.txt
|
68
85
|
- README.md
|
@@ -78,8 +95,10 @@ files:
|
|
78
95
|
- lib/firepush/message_type/builder.rb
|
79
96
|
- lib/firepush/message_type/data.rb
|
80
97
|
- lib/firepush/message_type/notification.rb
|
98
|
+
- lib/firepush/message_types.rb
|
81
99
|
- lib/firepush/recipient/base.rb
|
82
100
|
- lib/firepush/recipient/builder.rb
|
101
|
+
- lib/firepush/recipient/condition.rb
|
83
102
|
- lib/firepush/recipient/token.rb
|
84
103
|
- lib/firepush/recipient/topic.rb
|
85
104
|
- lib/firepush/version.rb
|