andpush 0.2.0 → 0.2.1
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/.travis.yml +8 -7
- data/CHANGELOG.md +9 -0
- data/Gemfile +1 -0
- data/README.md +27 -2
- data/andpush.gemspec +2 -2
- data/assets/curl-version.png +0 -0
- data/lib/andpush.rb +62 -1
- data/lib/andpush/version.rb +1 -1
- metadata +6 -4
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: df7b5f9eef2464f5682ffa020acd74acbbd353c482ee6442f3c4a01dcd77ebf2
|
4
|
+
data.tar.gz: 7c83817fcf0ea6035e1cbad68acaaab6ecb29fc4482c5e2c3154c597c50c58dc
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: d7918679620e77e3394684d7af5a2386223b9a7a514698b0cb7e645d374c67ae8de054aa58a87c7c5522d0137d1396bead19b83d03c2893a5a4cfe50baebf280
|
7
|
+
data.tar.gz: efe30498a620f7cc0504626751fe175e3b28f1cd648af0ac7ae469542e3aa0daf327e6640a5d5b40333270e50710deebefb06fa1b6b307c7fad1a468fea02613
|
data/.travis.yml
CHANGED
@@ -5,19 +5,20 @@ sudo: false
|
|
5
5
|
|
6
6
|
before_install:
|
7
7
|
- gem update --system
|
8
|
-
- gem
|
8
|
+
- gem install bundler
|
9
9
|
|
10
10
|
rvm:
|
11
|
-
- 2.2.
|
12
|
-
- 2.3.
|
13
|
-
- 2.4.
|
14
|
-
- 2.5.
|
11
|
+
- 2.2.10
|
12
|
+
- 2.3.8
|
13
|
+
- 2.4.5
|
14
|
+
- 2.5.3
|
15
|
+
- 2.6.0
|
15
16
|
- ruby-head
|
16
|
-
- jruby-9.
|
17
|
+
- jruby-9.2.5.0
|
17
18
|
- jruby-head
|
18
19
|
|
19
20
|
matrix:
|
20
21
|
allow_failures:
|
21
22
|
- rvm: ruby-head
|
22
|
-
- rvm: jruby-9.
|
23
|
+
- rvm: jruby-9.2.5.0
|
23
24
|
- rvm: jruby-head
|
data/CHANGELOG.md
CHANGED
@@ -1,3 +1,12 @@
|
|
1
|
+
## [v0.2.0](https://github.com/yuki24/andpush/tree/v0.2.0)
|
2
|
+
|
3
|
+
_<sup>released on 2018-03-08 01:33:21 UTC</sup>_
|
4
|
+
|
5
|
+
#### New Features
|
6
|
+
|
7
|
+
- Add support for Ruby 2.5.0
|
8
|
+
- Add the ability to pass in the `name`, `proxy` and`pool_size` options to the `Android.new` method to configure connection pool
|
9
|
+
|
1
10
|
## [v0.1.0: First release](https://github.com/yuki24/andpush/tree/v0.1.0)
|
2
11
|
|
3
12
|
_<sup>released on 2017-06-03 02:04:28 UTC</sup>_
|
data/Gemfile
CHANGED
data/README.md
CHANGED
@@ -2,9 +2,9 @@
|
|
2
2
|
|
3
3
|
Andpush is an HTTP client for FCM (Firebase Cloud Messaging). It implements [the Firebase Cloud Messaging HTTP Protocol](https://firebase.google.com/docs/cloud-messaging/http-server-ref).
|
4
4
|
|
5
|
-
The `andpush` gem performs **about 3.7x faster** than [the fcm gem](https://github.com/spacialdb/fcm) in a single-threaded environment.
|
5
|
+
The `andpush` gem performs **about 3.7x faster** than [the fcm gem](https://github.com/spacialdb/fcm) in a single-threaded environment.
|
6
6
|
|
7
|
-
**If you are
|
7
|
+
**If you are thinking to send push notifications from Rails, consider using the [pushing gem](https://github.com/yuki24/pushing), a push notification framework that does not hurt.**
|
8
8
|
|
9
9
|
## Installation
|
10
10
|
|
@@ -68,6 +68,31 @@ payload = {
|
|
68
68
|
response = client.push(payload) # => sends a message to the topic
|
69
69
|
```
|
70
70
|
|
71
|
+
## Using HTTP/2 (Experimental)
|
72
|
+
|
73
|
+
The current GitHub master branch ships with experimental support for HTTP/2. It takes advantage of the fantastic library, [libcurl](https://curl.haxx.se/libcurl/). In order to use it, replace `Andpush.new(...)` with `Andpush.http2(...)`:
|
74
|
+
|
75
|
+
```diff
|
76
|
+
+# Do not forget to add the curb gem to your Gemfile
|
77
|
+
+require 'curb'
|
78
|
+
|
79
|
+
-client = Andpush.new(server_key, pool_size: 25)
|
80
|
+
+client = Andpush.http2(server_key) # no need to specify the `pool_size' as HTTP/2 maintains a single connection
|
81
|
+
```
|
82
|
+
|
83
|
+
### Prerequisites
|
84
|
+
|
85
|
+
* [libcurl](https://curl.haxx.se/download.html) 7.43.0 or later
|
86
|
+
* [nghttp2](https://nghttp2.org/blog/) 1.0 or later
|
87
|
+
|
88
|
+
**Make sure that your production environment has the compatible versions installed. If you are not sure what version of libcurl you are using, try running `curl --version` and make sure it has `HTTP2` listed in the Features:**
|
89
|
+
|
90
|
+
![Curl version](assets/curl-version.png "Curl version")
|
91
|
+
|
92
|
+
**If you wish to use the HTTP/2 client in heroku, make sure you are using [the `Heroku-18` stack](https://devcenter.heroku.com/articles/heroku-18-stack). Older stacks, such as `Heroku-16` and `Cedar-14` do not ship with a version of libcurl that has support for HTTP/2.**
|
93
|
+
|
94
|
+
If you are using an older version of libcurl that doesn't support HTTP/2, don't worry. It will just fall back to HTTP 1.1 (of course without header compression and multiplexing.)
|
95
|
+
|
71
96
|
## Performance
|
72
97
|
|
73
98
|
The andpush gem uses [HTTP persistent connections](https://en.wikipedia.org/wiki/HTTP_persistent_connection) to improve performance. This is done by [the net-http-persistent gem](https://github.com/drbrain/net-http-persistent). [A simple benchmark](https://gist.github.com/yuki24/e0db97e887b8b6eb1932c41b4cea4a99) shows that the andpush gem performs at least 3x faster than the fcm gem:
|
data/andpush.gemspec
CHANGED
@@ -8,8 +8,8 @@ Gem::Specification.new do |spec|
|
|
8
8
|
spec.version = Andpush::VERSION
|
9
9
|
spec.authors = ["Yuki Nishijima"]
|
10
10
|
spec.email = ["mail@yukinishijima.net"]
|
11
|
-
spec.summary = %q{FCM
|
12
|
-
spec.description = %q{
|
11
|
+
spec.summary = %q{Simple, fast, high-quality client for FCM (Firebase Cloud Messaging)}
|
12
|
+
spec.description = %q{Android Push Notification in Ruby: simple, fast, high-quality client for FCM (Firebase Cloud Messaging)}
|
13
13
|
spec.homepage = "https://github.com/yuki24/andpush"
|
14
14
|
spec.license = "MIT"
|
15
15
|
spec.files = `git ls-files -z`.split("\x0").reject {|f| f.match(%r{^(test)/}) }
|
Binary file
|
data/lib/andpush.rb
CHANGED
@@ -13,6 +13,22 @@ module Andpush
|
|
13
13
|
.register_interceptor(Authenticator.new(server_key))
|
14
14
|
end
|
15
15
|
alias new build
|
16
|
+
|
17
|
+
def http2(server_key, domain: nil)
|
18
|
+
begin
|
19
|
+
require 'curb' if !defined?(Curl)
|
20
|
+
rescue LoadError => error
|
21
|
+
raise LoadError, "Could not load the curb gem. Make sure to install the gem by running:\n\n" \
|
22
|
+
" $ gem i curb\n\n" \
|
23
|
+
"Or the Gemfile has the following declaration:\n\n" \
|
24
|
+
" gem 'curb'\n\n" \
|
25
|
+
" (#{error.class}: #{error.message})"
|
26
|
+
end
|
27
|
+
|
28
|
+
::Andpush::Client
|
29
|
+
.new(domain || DOMAIN, request_handler: Http2RequestHandler.new)
|
30
|
+
.register_interceptor(Authenticator.new(server_key))
|
31
|
+
end
|
16
32
|
end
|
17
33
|
|
18
34
|
class Authenticator
|
@@ -42,5 +58,50 @@ module Andpush
|
|
42
58
|
end
|
43
59
|
end
|
44
60
|
|
45
|
-
|
61
|
+
class Http2RequestHandler
|
62
|
+
BY_HEADER_LINE = /[\r\n]+/.freeze
|
63
|
+
HEADER_VALUE = /^(\S+): (.+)/.freeze
|
64
|
+
EMPTY_HEADERS = {}.freeze
|
65
|
+
|
66
|
+
attr_reader :multi
|
67
|
+
|
68
|
+
def initialize(max_connects: 100)
|
69
|
+
@multi = Curl::Multi.new
|
70
|
+
|
71
|
+
@multi.pipeline = Curl::CURLPIPE_MULTIPLEX if defined?(Curl::CURLPIPE_MULTIPLEX)
|
72
|
+
@multi.max_connects = max_connects
|
73
|
+
end
|
74
|
+
|
75
|
+
def call(request_class, uri, headers, body, *_)
|
76
|
+
easy = Curl::Easy.new(uri.to_s)
|
77
|
+
|
78
|
+
easy.multi = @multi
|
79
|
+
easy.headers = headers || EMPTY_HEADERS
|
80
|
+
easy.post_body = body if request_class::REQUEST_HAS_BODY
|
81
|
+
|
82
|
+
if defined?(Curl::CURLPIPE_MULTIPLEX)
|
83
|
+
# This ensures libcurl waits for the connection to reveal if it is
|
84
|
+
# possible to pipeline/multiplex on before it continues.
|
85
|
+
easy.setopt(Curl::CURLOPT_PIPEWAIT, 1)
|
86
|
+
easy.version = Curl::HTTP_2_0
|
87
|
+
end
|
88
|
+
|
89
|
+
easy.public_send(:"http_#{request_class::METHOD.downcase}")
|
90
|
+
|
91
|
+
Response.new(
|
92
|
+
Hash[easy.header_str.split(BY_HEADER_LINE).flat_map {|s| s.scan(HEADER_VALUE) }],
|
93
|
+
easy.body,
|
94
|
+
easy.response_code.to_s, # to_s for compatibility with Net::HTTP
|
95
|
+
easy,
|
96
|
+
).freeze
|
97
|
+
end
|
98
|
+
|
99
|
+
Response = Struct.new(:headers, :body, :code, :raw_response) do
|
100
|
+
alias to_hash headers
|
101
|
+
end
|
102
|
+
|
103
|
+
private_constant :BY_HEADER_LINE, :HEADER_VALUE, :Response
|
104
|
+
end
|
105
|
+
|
106
|
+
private_constant :Authenticator, :ConnectionPool, :Http2RequestHandler
|
46
107
|
end
|
data/lib/andpush/version.rb
CHANGED
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: andpush
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.2.
|
4
|
+
version: 0.2.1
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Yuki Nishijima
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2018-
|
11
|
+
date: 2018-12-26 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: net-http-persistent
|
@@ -66,7 +66,8 @@ dependencies:
|
|
66
66
|
- - ">="
|
67
67
|
- !ruby/object:Gem::Version
|
68
68
|
version: '0'
|
69
|
-
description:
|
69
|
+
description: 'Android Push Notification in Ruby: simple, fast, high-quality client
|
70
|
+
for FCM (Firebase Cloud Messaging)'
|
70
71
|
email:
|
71
72
|
- mail@yukinishijima.net
|
72
73
|
executables: []
|
@@ -82,6 +83,7 @@ files:
|
|
82
83
|
- README.md
|
83
84
|
- Rakefile
|
84
85
|
- andpush.gemspec
|
86
|
+
- assets/curl-version.png
|
85
87
|
- bin/console
|
86
88
|
- bin/setup
|
87
89
|
- fcm.apispec
|
@@ -114,5 +116,5 @@ rubyforge_project:
|
|
114
116
|
rubygems_version: 2.7.6
|
115
117
|
signing_key:
|
116
118
|
specification_version: 4
|
117
|
-
summary: FCM
|
119
|
+
summary: Simple, fast, high-quality client for FCM (Firebase Cloud Messaging)
|
118
120
|
test_files: []
|