firepush 0.1.1
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +7 -0
- data/.gitignore +12 -0
- data/.rspec +3 -0
- data/.travis.yml +15 -0
- data/CODE_OF_CONDUCT.md +74 -0
- data/Gemfile +6 -0
- data/LICENSE.txt +21 -0
- data/README.md +74 -0
- data/Rakefile +6 -0
- data/bin/console +14 -0
- data/bin/setup +8 -0
- data/firepush.gemspec +29 -0
- data/lib/firepush.rb +23 -0
- data/lib/firepush/client.rb +85 -0
- data/lib/firepush/helper_methods.rb +14 -0
- data/lib/firepush/message.rb +53 -0
- data/lib/firepush/message_type/base.rb +25 -0
- data/lib/firepush/message_type/builder.rb +61 -0
- data/lib/firepush/message_type/data.rb +26 -0
- data/lib/firepush/message_type/notification.rb +29 -0
- data/lib/firepush/recipient/base.rb +25 -0
- data/lib/firepush/recipient/builder.rb +61 -0
- data/lib/firepush/recipient/token.rb +26 -0
- data/lib/firepush/recipient/topic.rb +26 -0
- data/lib/firepush/version.rb +5 -0
- metadata +109 -0
checksums.yaml
ADDED
@@ -0,0 +1,7 @@
|
|
1
|
+
---
|
2
|
+
SHA256:
|
3
|
+
metadata.gz: 0c8078baed1b8162b2f74d8dc1484f192956eabd0974194b77a6f4820ce43109
|
4
|
+
data.tar.gz: 7f1c6a033890b6fbf0ba01628cdc048b10931a1f8a2a11754ce2db558727fe20
|
5
|
+
SHA512:
|
6
|
+
metadata.gz: cd7f586d4e875575024bdf5906906af7f291540ec1f3f813c1bba21630ed40cdb1975f1901b7db21d1ac0ebaea81943f3602b1f260d1684de73410c6cfc7731b
|
7
|
+
data.tar.gz: 2493146182414eedaf77abee51133e2a417964ea67b3649736f7ce1874feaf4251c7b4269f47bcc1ece4ab01bb5d286b1b307afc5074d4ac144acd7537072f13
|
data/.gitignore
ADDED
data/.rspec
ADDED
data/.travis.yml
ADDED
data/CODE_OF_CONDUCT.md
ADDED
@@ -0,0 +1,74 @@
|
|
1
|
+
# Contributor Covenant Code of Conduct
|
2
|
+
|
3
|
+
## Our Pledge
|
4
|
+
|
5
|
+
In the interest of fostering an open and welcoming environment, we as
|
6
|
+
contributors and maintainers pledge to making participation in our project and
|
7
|
+
our community a harassment-free experience for everyone, regardless of age, body
|
8
|
+
size, disability, ethnicity, gender identity and expression, level of experience,
|
9
|
+
nationality, personal appearance, race, religion, or sexual identity and
|
10
|
+
orientation.
|
11
|
+
|
12
|
+
## Our Standards
|
13
|
+
|
14
|
+
Examples of behavior that contributes to creating a positive environment
|
15
|
+
include:
|
16
|
+
|
17
|
+
* Using welcoming and inclusive language
|
18
|
+
* Being respectful of differing viewpoints and experiences
|
19
|
+
* Gracefully accepting constructive criticism
|
20
|
+
* Focusing on what is best for the community
|
21
|
+
* Showing empathy towards other community members
|
22
|
+
|
23
|
+
Examples of unacceptable behavior by participants include:
|
24
|
+
|
25
|
+
* The use of sexualized language or imagery and unwelcome sexual attention or
|
26
|
+
advances
|
27
|
+
* Trolling, insulting/derogatory comments, and personal or political attacks
|
28
|
+
* Public or private harassment
|
29
|
+
* Publishing others' private information, such as a physical or electronic
|
30
|
+
address, without explicit permission
|
31
|
+
* Other conduct which could reasonably be considered inappropriate in a
|
32
|
+
professional setting
|
33
|
+
|
34
|
+
## Our Responsibilities
|
35
|
+
|
36
|
+
Project maintainers are responsible for clarifying the standards of acceptable
|
37
|
+
behavior and are expected to take appropriate and fair corrective action in
|
38
|
+
response to any instances of unacceptable behavior.
|
39
|
+
|
40
|
+
Project maintainers have the right and responsibility to remove, edit, or
|
41
|
+
reject comments, commits, code, wiki edits, issues, and other contributions
|
42
|
+
that are not aligned to this Code of Conduct, or to ban temporarily or
|
43
|
+
permanently any contributor for other behaviors that they deem inappropriate,
|
44
|
+
threatening, offensive, or harmful.
|
45
|
+
|
46
|
+
## Scope
|
47
|
+
|
48
|
+
This Code of Conduct applies both within project spaces and in public spaces
|
49
|
+
when an individual is representing the project or its community. Examples of
|
50
|
+
representing a project or community include using an official project e-mail
|
51
|
+
address, posting via an official social media account, or acting as an appointed
|
52
|
+
representative at an online or offline event. Representation of a project may be
|
53
|
+
further defined and clarified by project maintainers.
|
54
|
+
|
55
|
+
## Enforcement
|
56
|
+
|
57
|
+
Instances of abusive, harassing, or otherwise unacceptable behavior may be
|
58
|
+
reported by contacting the project team at TODO: Write your email address. All
|
59
|
+
complaints will be reviewed and investigated and will result in a response that
|
60
|
+
is deemed necessary and appropriate to the circumstances. The project team is
|
61
|
+
obligated to maintain confidentiality with regard to the reporter of an incident.
|
62
|
+
Further details of specific enforcement policies may be posted separately.
|
63
|
+
|
64
|
+
Project maintainers who do not follow or enforce the Code of Conduct in good
|
65
|
+
faith may face temporary or permanent repercussions as determined by other
|
66
|
+
members of the project's leadership.
|
67
|
+
|
68
|
+
## Attribution
|
69
|
+
|
70
|
+
This Code of Conduct is adapted from the [Contributor Covenant][homepage], version 1.4,
|
71
|
+
available at [http://contributor-covenant.org/version/1/4][version]
|
72
|
+
|
73
|
+
[homepage]: http://contributor-covenant.org
|
74
|
+
[version]: http://contributor-covenant.org/version/1/4/
|
data/Gemfile
ADDED
data/LICENSE.txt
ADDED
@@ -0,0 +1,21 @@
|
|
1
|
+
The MIT License (MIT)
|
2
|
+
|
3
|
+
Copyright (c) 2019 TODO: Write your name
|
4
|
+
|
5
|
+
Permission is hereby granted, free of charge, to any person obtaining a copy
|
6
|
+
of this software and associated documentation files (the "Software"), to deal
|
7
|
+
in the Software without restriction, including without limitation the rights
|
8
|
+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
9
|
+
copies of the Software, and to permit persons to whom the Software is
|
10
|
+
furnished to do so, subject to the following conditions:
|
11
|
+
|
12
|
+
The above copyright notice and this permission notice shall be included in
|
13
|
+
all copies or substantial portions of the Software.
|
14
|
+
|
15
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
16
|
+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
17
|
+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
18
|
+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
19
|
+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
20
|
+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
|
21
|
+
THE SOFTWARE.
|
data/README.md
ADDED
@@ -0,0 +1,74 @@
|
|
1
|
+
# Firepush
|
2
|
+
|
3
|
+
[![Build Status](https://travis-ci.org/mmyoji/firepush.svg?branch=master)](https://travis-ci.org/mmyoji/firepush)
|
4
|
+
|
5
|
+
Firepush is [Firebase Cloud Messaging](https://firebase.google.com/docs/cloud-messaging/) client library using [HTTP v1 API](https://firebase.google.com/docs/cloud-messaging/migrate-v1).
|
6
|
+
|
7
|
+
## Installation
|
8
|
+
|
9
|
+
Add this line to your application's Gemfile:
|
10
|
+
|
11
|
+
```ruby
|
12
|
+
gem 'firepush', git: "git://github.com/mmyoji/firepush.git"
|
13
|
+
```
|
14
|
+
|
15
|
+
And then execute:
|
16
|
+
|
17
|
+
$ bundle install
|
18
|
+
|
19
|
+
Or install it yourself as: (This doesn't work now)
|
20
|
+
|
21
|
+
$ gem install firepush
|
22
|
+
|
23
|
+
## Usage
|
24
|
+
|
25
|
+
You can see the following link to understand the FCM messages.
|
26
|
+
|
27
|
+
[About FCM messages | Firebase](https://firebase.google.com/docs/cloud-messaging/concept-options?hl=en)
|
28
|
+
|
29
|
+
```rb
|
30
|
+
require "firepush"
|
31
|
+
|
32
|
+
client = Firepush::Client.new(
|
33
|
+
access_token: "<your Firebase Project Access Token>",
|
34
|
+
project_id: "<your Firebase project ID>",
|
35
|
+
)
|
36
|
+
|
37
|
+
# 1. Notification message to a single device
|
38
|
+
|
39
|
+
client.push(
|
40
|
+
notification: {
|
41
|
+
title: "Some title is required",
|
42
|
+
body: "Some body is required",
|
43
|
+
},
|
44
|
+
token: "<Android Registration ID>",
|
45
|
+
)
|
46
|
+
|
47
|
+
# 2. Data message to a topic
|
48
|
+
|
49
|
+
client.push(
|
50
|
+
data: {
|
51
|
+
key: "some String value is required",
|
52
|
+
key2: "you can set multiple key-value in this section",
|
53
|
+
},
|
54
|
+
topic: "news",
|
55
|
+
)
|
56
|
+
```
|
57
|
+
|
58
|
+
## Development
|
59
|
+
|
60
|
+
After checking out the repo, run `bin/setup` to install dependencies. Then, run `rake spec` to run the tests. You can also run `bin/console` for an interactive prompt that will allow you to experiment.
|
61
|
+
|
62
|
+
To install this gem onto your local machine, run `bundle exec rake install`. To release a new version, update the version number in `version.rb`, and then run `bundle exec rake release`, which will create a git tag for the version, push git commits and tags, and push the `.gem` file to [rubygems.org](https://rubygems.org).
|
63
|
+
|
64
|
+
## Contributing
|
65
|
+
|
66
|
+
Bug reports and pull requests are welcome on GitHub at https://github.com/mmyoji/firepush. This project is intended to be a safe, welcoming space for collaboration, and contributors are expected to adhere to the [Contributor Covenant](http://contributor-covenant.org) code of conduct.
|
67
|
+
|
68
|
+
## License
|
69
|
+
|
70
|
+
The gem is available as open source under the terms of the [MIT License](https://opensource.org/licenses/MIT).
|
71
|
+
|
72
|
+
## Code of Conduct
|
73
|
+
|
74
|
+
Everyone interacting in the Firepush project’s codebases, issue trackers, chat rooms and mailing lists is expected to follow the [code of conduct](https://github.com/mmyoji/firepush/blob/master/CODE_OF_CONDUCT.md).
|
data/Rakefile
ADDED
data/bin/console
ADDED
@@ -0,0 +1,14 @@
|
|
1
|
+
#!/usr/bin/env ruby
|
2
|
+
|
3
|
+
require "bundler/setup"
|
4
|
+
require "firepush"
|
5
|
+
|
6
|
+
# You can add fixtures and/or initialization code here to make experimenting
|
7
|
+
# with your gem easier. You can also use a different console, if you like.
|
8
|
+
|
9
|
+
# (If you use this, don't forget to add pry to your Gemfile!)
|
10
|
+
# require "pry"
|
11
|
+
# Pry.start
|
12
|
+
|
13
|
+
require "irb"
|
14
|
+
IRB.start(__FILE__)
|
data/bin/setup
ADDED
data/firepush.gemspec
ADDED
@@ -0,0 +1,29 @@
|
|
1
|
+
|
2
|
+
lib = File.expand_path("../lib", __FILE__)
|
3
|
+
$LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
|
4
|
+
require "firepush/version"
|
5
|
+
|
6
|
+
Gem::Specification.new do |spec|
|
7
|
+
spec.name = "firepush"
|
8
|
+
spec.version = Firepush::VERSION
|
9
|
+
spec.authors = ["mmyoji"]
|
10
|
+
spec.email = ["mmyoji@gmail.com"]
|
11
|
+
|
12
|
+
spec.summary = %q{Firebase Cloud Messaging Client library.}
|
13
|
+
spec.description = %q{Firebase Cloud Messaging Client library which uses HTTP v1 API.}
|
14
|
+
spec.homepage = "https://github.com/mmyoji/firepush"
|
15
|
+
spec.license = "MIT"
|
16
|
+
|
17
|
+
# Specify which files should be added to the gem when it is released.
|
18
|
+
# The `git ls-files -z` loads the files in the RubyGem that have been added into git.
|
19
|
+
spec.files = Dir.chdir(File.expand_path('..', __FILE__)) do
|
20
|
+
`git ls-files -z`.split("\x0").reject { |f| f.match(%r{^(test|spec|features)/}) }
|
21
|
+
end
|
22
|
+
spec.bindir = "bin"
|
23
|
+
spec.executables = spec.files.grep(%r{^exe/}) { |f| File.basename(f) }
|
24
|
+
spec.require_paths = ["lib"]
|
25
|
+
|
26
|
+
spec.add_development_dependency "bundler", "~> 1.17"
|
27
|
+
spec.add_development_dependency "rake", "~> 10.0"
|
28
|
+
spec.add_development_dependency "rspec", "~> 3.0"
|
29
|
+
end
|
data/lib/firepush.rb
ADDED
@@ -0,0 +1,23 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
module Firepush
|
4
|
+
autoload :Client, "firepush/client"
|
5
|
+
autoload :Message, "firepush/message"
|
6
|
+
|
7
|
+
module MessageType
|
8
|
+
autoload :Base, "firepush/message_type/base"
|
9
|
+
autoload :Builder, "firepush/message_type/builder"
|
10
|
+
autoload :Data, "firepush/message_type/data"
|
11
|
+
autoload :Notification, "firepush/message_type/notification"
|
12
|
+
end
|
13
|
+
|
14
|
+
module Recipient
|
15
|
+
autoload :Base, "firepush/recipient/base"
|
16
|
+
autoload :Builder, "firepush/recipient/builder"
|
17
|
+
autoload :Token, "firepush/recipient/token"
|
18
|
+
autoload :Topic, "firepush/recipient/topic"
|
19
|
+
end
|
20
|
+
|
21
|
+
autoload :HelperMethods, "firepush/helper_methods"
|
22
|
+
autoload :Version, "firepush/version"
|
23
|
+
end
|
@@ -0,0 +1,85 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
require "net/http"
|
4
|
+
|
5
|
+
module Firepush
|
6
|
+
class Client
|
7
|
+
class InvalidAttributes < ::StandardError; end
|
8
|
+
|
9
|
+
include HelperMethods
|
10
|
+
|
11
|
+
BASE_URI = "https://fcm.googleapis.com"
|
12
|
+
BASE_PATH = "/v1/projects"
|
13
|
+
|
14
|
+
attr_accessor :access_token # @return [String]
|
15
|
+
attr_accessor :project_id # @return [String]
|
16
|
+
|
17
|
+
attr_reader :message # @return [String]
|
18
|
+
|
19
|
+
# @param :access_token [String] optional
|
20
|
+
# @param :project_id [String] optional
|
21
|
+
def initialize(access_token: "", project_id: "")
|
22
|
+
self.access_token = access_token
|
23
|
+
self.project_id = project_id
|
24
|
+
end
|
25
|
+
|
26
|
+
# @param message [Hash]
|
27
|
+
def message=(message)
|
28
|
+
@message = Message.new(message)
|
29
|
+
end
|
30
|
+
|
31
|
+
# @param message [Hash] optional
|
32
|
+
#
|
33
|
+
# TODO: Return useful response
|
34
|
+
# @return [Http::Response]
|
35
|
+
#
|
36
|
+
# @raise [Firepush::Client::InvalidAttributes]
|
37
|
+
def push(message = nil)
|
38
|
+
self.message = message unless message.nil?
|
39
|
+
|
40
|
+
raise InvalidAttributes unless valid?
|
41
|
+
|
42
|
+
http.post(path, self.message.to_json, headers)
|
43
|
+
end
|
44
|
+
|
45
|
+
# @return [Boolean]
|
46
|
+
def valid?
|
47
|
+
valid_str?(access_token) && valid_str?(project_id) &&
|
48
|
+
!message.nil? && message.valid?
|
49
|
+
end
|
50
|
+
|
51
|
+
private
|
52
|
+
|
53
|
+
# @private
|
54
|
+
# @return [Hash]
|
55
|
+
def headers
|
56
|
+
{
|
57
|
+
"Content-Type" => "application/json",
|
58
|
+
"Authorization" => "Bearer #{access_token}",
|
59
|
+
}
|
60
|
+
end
|
61
|
+
|
62
|
+
# @private
|
63
|
+
# @return [Net::HTTP]
|
64
|
+
def http
|
65
|
+
@http ||=
|
66
|
+
begin
|
67
|
+
h = ::Net::HTTP.new(uri.host, uri.port)
|
68
|
+
h.use_ssl = true
|
69
|
+
h
|
70
|
+
end
|
71
|
+
end
|
72
|
+
|
73
|
+
# @private
|
74
|
+
# @return [String]
|
75
|
+
def path
|
76
|
+
"#{BASE_PATH}/#{project_id}/messages:send"
|
77
|
+
end
|
78
|
+
|
79
|
+
# @private
|
80
|
+
# @return [URI::HTTPS]
|
81
|
+
def uri
|
82
|
+
@uri ||= ::URI.parse(BASE_URI)
|
83
|
+
end
|
84
|
+
end
|
85
|
+
end
|
@@ -0,0 +1,53 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
require "json"
|
4
|
+
|
5
|
+
module Firepush
|
6
|
+
class Message
|
7
|
+
attr_reader :recipient # @return [Firepush::Recipient::Base]
|
8
|
+
attr_reader :message_type # @return [Firepush::MessageType::Base]
|
9
|
+
|
10
|
+
# TODO: handle extra data in better way.
|
11
|
+
attr_reader :extra # @return [Hash]
|
12
|
+
|
13
|
+
# @param msg [Hash]
|
14
|
+
# @see lib/firepush/{message_type,recipient}/*.rb
|
15
|
+
# @raise [ArgumentError]
|
16
|
+
def initialize(msg)
|
17
|
+
msg = msg.dup
|
18
|
+
|
19
|
+
args = {}
|
20
|
+
args[:topic] = msg.delete(:topic) if msg.key?(:topic)
|
21
|
+
args[:token] = msg.delete(:token) if msg.key?(:token)
|
22
|
+
@recipient = Recipient::Builder.build(args)
|
23
|
+
|
24
|
+
args.clear
|
25
|
+
args[:notification] = msg.delete(:notification) if msg.key?(:notification)
|
26
|
+
args[:data] = msg.delete(:data) if msg.key?(:data)
|
27
|
+
@message_type = MessageType::Builder.build(args)
|
28
|
+
|
29
|
+
@extra = msg
|
30
|
+
end
|
31
|
+
|
32
|
+
# @return [String]
|
33
|
+
def to_json
|
34
|
+
::JSON.generate(message: message)
|
35
|
+
end
|
36
|
+
|
37
|
+
# @return [Boolean]
|
38
|
+
def valid?
|
39
|
+
recipient.valid? && message_type.valid?
|
40
|
+
end
|
41
|
+
|
42
|
+
private
|
43
|
+
|
44
|
+
# @private
|
45
|
+
# @return [Hash]
|
46
|
+
def message
|
47
|
+
{
|
48
|
+
recipient.key => recipient.value,
|
49
|
+
message_type.key => message_type.value,
|
50
|
+
}.merge(extra)
|
51
|
+
end
|
52
|
+
end
|
53
|
+
end
|
@@ -0,0 +1,25 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
module Firepush
|
4
|
+
module MessageType
|
5
|
+
# @abstract
|
6
|
+
class Base
|
7
|
+
include HelperMethods
|
8
|
+
|
9
|
+
# @return [Symbol]
|
10
|
+
def key
|
11
|
+
self.class.name.split("::").last.downcase.intern
|
12
|
+
end
|
13
|
+
|
14
|
+
# @return [Boolean]
|
15
|
+
def valid?
|
16
|
+
raise "#{__method__} is not implemented!"
|
17
|
+
end
|
18
|
+
|
19
|
+
# @return [Hash]
|
20
|
+
def value
|
21
|
+
raise "#{__method__} is not implemented!"
|
22
|
+
end
|
23
|
+
end
|
24
|
+
end
|
25
|
+
end
|
@@ -0,0 +1,61 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
module Firepush
|
4
|
+
module MessageType
|
5
|
+
class Builder
|
6
|
+
# @param args [Hash]
|
7
|
+
# @option args [Hash] :notification
|
8
|
+
# @option args [Hash] :data
|
9
|
+
def self.build(args)
|
10
|
+
new(args).build
|
11
|
+
end
|
12
|
+
|
13
|
+
# @private
|
14
|
+
# @see .build
|
15
|
+
def initialize(args)
|
16
|
+
@_args = args
|
17
|
+
|
18
|
+
check_args!
|
19
|
+
end
|
20
|
+
private_class_method :new
|
21
|
+
|
22
|
+
# @return [Firepush::MessageType::Base]
|
23
|
+
def build
|
24
|
+
case
|
25
|
+
when notification?
|
26
|
+
Notification.new(_args.fetch(:notification))
|
27
|
+
when data?
|
28
|
+
Data.new(_args.fetch(:data))
|
29
|
+
end
|
30
|
+
end
|
31
|
+
|
32
|
+
private
|
33
|
+
|
34
|
+
attr_reader :_args
|
35
|
+
|
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
|
+
# @private
|
49
|
+
# @return [Boolean]
|
50
|
+
def data?
|
51
|
+
_args.key?(:data)
|
52
|
+
end
|
53
|
+
|
54
|
+
# @private
|
55
|
+
# @return [Boolean]
|
56
|
+
def notification?
|
57
|
+
_args.key?(:notification)
|
58
|
+
end
|
59
|
+
end
|
60
|
+
end
|
61
|
+
end
|
@@ -0,0 +1,26 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
module Firepush
|
4
|
+
module MessageType
|
5
|
+
class Data < Base
|
6
|
+
attr_reader :data # @return [Hash<Symbol, String>]
|
7
|
+
|
8
|
+
# @param args [Hash]
|
9
|
+
def initialize(args)
|
10
|
+
@data = args
|
11
|
+
end
|
12
|
+
|
13
|
+
# @override
|
14
|
+
# @return [Boolean]
|
15
|
+
def valid?
|
16
|
+
data.is_a?(::Hash) && data.values.all? { |v| v.is_a?(::String) }
|
17
|
+
end
|
18
|
+
|
19
|
+
# @override
|
20
|
+
# @return [Hash]
|
21
|
+
def value
|
22
|
+
data
|
23
|
+
end
|
24
|
+
end
|
25
|
+
end
|
26
|
+
end
|
@@ -0,0 +1,29 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
module Firepush
|
4
|
+
module MessageType
|
5
|
+
class Notification < Base
|
6
|
+
attr_reader :title # @return [String]
|
7
|
+
attr_reader :body # @return [String]
|
8
|
+
|
9
|
+
# @param :title [String]
|
10
|
+
# @param :body [String]
|
11
|
+
def initialize(title:, body:)
|
12
|
+
@title = title
|
13
|
+
@body = body
|
14
|
+
end
|
15
|
+
|
16
|
+
# @override
|
17
|
+
# @return [Boolean]
|
18
|
+
def valid?
|
19
|
+
valid_str?(title) && valid_str?(body)
|
20
|
+
end
|
21
|
+
|
22
|
+
# @override
|
23
|
+
# @return [Hash]
|
24
|
+
def value
|
25
|
+
{ title: title, body: body }
|
26
|
+
end
|
27
|
+
end
|
28
|
+
end
|
29
|
+
end
|
@@ -0,0 +1,25 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
module Firepush
|
4
|
+
module Recipient
|
5
|
+
# @abstract
|
6
|
+
class Base
|
7
|
+
include HelperMethods
|
8
|
+
|
9
|
+
# @return [Symbol]
|
10
|
+
def key
|
11
|
+
self.class.name.split("::").last.downcase.intern
|
12
|
+
end
|
13
|
+
|
14
|
+
# @return [Boolean]
|
15
|
+
def valid?
|
16
|
+
raise "#{__method__} is not implemented!"
|
17
|
+
end
|
18
|
+
|
19
|
+
# @return [String]
|
20
|
+
def value
|
21
|
+
raise "#{__method__} is not implemented!"
|
22
|
+
end
|
23
|
+
end
|
24
|
+
end
|
25
|
+
end
|
@@ -0,0 +1,61 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
module Firepush
|
4
|
+
module Recipient
|
5
|
+
class Builder
|
6
|
+
# @param args [Hash]
|
7
|
+
# @option args [Hash] :topic
|
8
|
+
# @option args [Hash] :token
|
9
|
+
def self.build(args)
|
10
|
+
new(args).build
|
11
|
+
end
|
12
|
+
|
13
|
+
# @private
|
14
|
+
# @see .build
|
15
|
+
def initialize(args)
|
16
|
+
@_args = args
|
17
|
+
|
18
|
+
check_args!
|
19
|
+
end
|
20
|
+
private_class_method :new
|
21
|
+
|
22
|
+
# @return [Firepush::Recipient::Base]
|
23
|
+
def build
|
24
|
+
case
|
25
|
+
when topic?
|
26
|
+
Topic.new(_args.fetch(:topic))
|
27
|
+
when token?
|
28
|
+
Token.new(_args.fetch(:token))
|
29
|
+
end
|
30
|
+
end
|
31
|
+
|
32
|
+
private
|
33
|
+
|
34
|
+
attr_reader :_args
|
35
|
+
|
36
|
+
# @private
|
37
|
+
# @raise [ArgumentError]
|
38
|
+
def check_args!
|
39
|
+
if topic? && token?
|
40
|
+
raise ::ArgumentError.new("Cannot set both :topic and :token")
|
41
|
+
end
|
42
|
+
|
43
|
+
if !topic? && !token?
|
44
|
+
raise ::ArgumentError.new("Must set either :topic or :token")
|
45
|
+
end
|
46
|
+
end
|
47
|
+
|
48
|
+
# @private
|
49
|
+
# @return [Boolean]
|
50
|
+
def token?
|
51
|
+
_args.key?(:token)
|
52
|
+
end
|
53
|
+
|
54
|
+
# @private
|
55
|
+
# @return [Boolean]
|
56
|
+
def topic?
|
57
|
+
_args.key?(:topic)
|
58
|
+
end
|
59
|
+
end
|
60
|
+
end
|
61
|
+
end
|
@@ -0,0 +1,26 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
module Firepush
|
4
|
+
module Recipient
|
5
|
+
class Token < Base
|
6
|
+
attr_reader :token # @return [String]
|
7
|
+
|
8
|
+
# @param token [String] Android Registration ID
|
9
|
+
def initialize(token)
|
10
|
+
@token = token
|
11
|
+
end
|
12
|
+
|
13
|
+
# @override
|
14
|
+
# @return [Boolean]
|
15
|
+
def valid?
|
16
|
+
valid_str?(token)
|
17
|
+
end
|
18
|
+
|
19
|
+
# @override
|
20
|
+
# @return [String]
|
21
|
+
def value
|
22
|
+
token
|
23
|
+
end
|
24
|
+
end
|
25
|
+
end
|
26
|
+
end
|
@@ -0,0 +1,26 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
module Firepush
|
4
|
+
module Recipient
|
5
|
+
class Topic < Base
|
6
|
+
attr_reader :topic # @return [String]
|
7
|
+
|
8
|
+
# @param topic [String]
|
9
|
+
def initialize(topic)
|
10
|
+
@topic = topic
|
11
|
+
end
|
12
|
+
|
13
|
+
# @override
|
14
|
+
# @return [Boolean]
|
15
|
+
def valid?
|
16
|
+
valid_str?(topic)
|
17
|
+
end
|
18
|
+
|
19
|
+
# @override
|
20
|
+
# @return [String]
|
21
|
+
def value
|
22
|
+
topic
|
23
|
+
end
|
24
|
+
end
|
25
|
+
end
|
26
|
+
end
|
metadata
ADDED
@@ -0,0 +1,109 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: firepush
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
version: 0.1.1
|
5
|
+
platform: ruby
|
6
|
+
authors:
|
7
|
+
- mmyoji
|
8
|
+
autorequire:
|
9
|
+
bindir: bin
|
10
|
+
cert_chain: []
|
11
|
+
date: 2019-02-16 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
|
+
description: Firebase Cloud Messaging Client library which uses HTTP v1 API.
|
56
|
+
email:
|
57
|
+
- mmyoji@gmail.com
|
58
|
+
executables: []
|
59
|
+
extensions: []
|
60
|
+
extra_rdoc_files: []
|
61
|
+
files:
|
62
|
+
- ".gitignore"
|
63
|
+
- ".rspec"
|
64
|
+
- ".travis.yml"
|
65
|
+
- CODE_OF_CONDUCT.md
|
66
|
+
- Gemfile
|
67
|
+
- LICENSE.txt
|
68
|
+
- README.md
|
69
|
+
- Rakefile
|
70
|
+
- bin/console
|
71
|
+
- bin/setup
|
72
|
+
- firepush.gemspec
|
73
|
+
- lib/firepush.rb
|
74
|
+
- lib/firepush/client.rb
|
75
|
+
- lib/firepush/helper_methods.rb
|
76
|
+
- lib/firepush/message.rb
|
77
|
+
- lib/firepush/message_type/base.rb
|
78
|
+
- lib/firepush/message_type/builder.rb
|
79
|
+
- lib/firepush/message_type/data.rb
|
80
|
+
- lib/firepush/message_type/notification.rb
|
81
|
+
- lib/firepush/recipient/base.rb
|
82
|
+
- lib/firepush/recipient/builder.rb
|
83
|
+
- lib/firepush/recipient/token.rb
|
84
|
+
- lib/firepush/recipient/topic.rb
|
85
|
+
- lib/firepush/version.rb
|
86
|
+
homepage: https://github.com/mmyoji/firepush
|
87
|
+
licenses:
|
88
|
+
- MIT
|
89
|
+
metadata: {}
|
90
|
+
post_install_message:
|
91
|
+
rdoc_options: []
|
92
|
+
require_paths:
|
93
|
+
- lib
|
94
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
95
|
+
requirements:
|
96
|
+
- - ">="
|
97
|
+
- !ruby/object:Gem::Version
|
98
|
+
version: '0'
|
99
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
100
|
+
requirements:
|
101
|
+
- - ">="
|
102
|
+
- !ruby/object:Gem::Version
|
103
|
+
version: '0'
|
104
|
+
requirements: []
|
105
|
+
rubygems_version: 3.0.1
|
106
|
+
signing_key:
|
107
|
+
specification_version: 4
|
108
|
+
summary: Firebase Cloud Messaging Client library.
|
109
|
+
test_files: []
|