andpush 0.1.0 → 0.2.0

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
- SHA1:
3
- metadata.gz: 5906e62af1538446835164d870e6ad5208c273b8
4
- data.tar.gz: 152292ea0800e0ea8b8ea5646fde079488f9a29e
2
+ SHA256:
3
+ metadata.gz: d034631f3463f8f106814846df48e8c5478b3b3fcc93abca065d8119bfa1fec7
4
+ data.tar.gz: ef0c8920fd6c3f67dc530defb3862eee3fc6e72c6b0b66a0fc8460e38cfd7ae8
5
5
  SHA512:
6
- metadata.gz: 1388a7d47b11a593d3bf831be5f95a302aae5abae28c4edde8823575e263f89d7945089cf288d8ada21f88f3c39bfbcbf5089849b2edefa4940a05856b48ddc8
7
- data.tar.gz: 8466478c030432ceeb73bdc59a2314bd5a09a964ccd355d92badc2792bdc76beb77a07ad9f9dbec3664e31956d11a88220878bdb3816dcf837caecab620001c3
6
+ metadata.gz: 3c6c4d56ef8135fee5385d3e94a42e017c9f79f0ea0263a73fb3da70dbae1c4f5c53129c711193cb3b1411335692014723dae8d75ed2107b4e8012d86b93b02c
7
+ data.tar.gz: 121b05f40b5c143a73d495eccbe4469388d41ef5e0d6668671dbfdf0f2d1673cf4e2239e39b4146ffaceab5e72b7ac83bd59dea3ee5ff51fa4aff2e701dad09d
data/.travis.yml CHANGED
@@ -3,16 +3,21 @@ cache: bundler
3
3
  script: bundle exec rake test
4
4
  sudo: false
5
5
 
6
+ before_install:
7
+ - gem update --system
8
+ - gem pristine bundler
9
+
6
10
  rvm:
7
- - 2.2.7
8
- - 2.3.4
9
- - 2.4.1
11
+ - 2.2.9
12
+ - 2.3.6
13
+ - 2.4.3
14
+ - 2.5.0
10
15
  - ruby-head
11
- - jruby-9.1.10.0
16
+ - jruby-9.1.16.0
12
17
  - jruby-head
13
18
 
14
19
  matrix:
15
20
  allow_failures:
16
21
  - rvm: ruby-head
17
- - rvm: jruby-9.1.10.0
22
+ - rvm: jruby-9.1.16.0
18
23
  - rvm: jruby-head
data/CHANGELOG.md ADDED
@@ -0,0 +1,4 @@
1
+ ## [v0.1.0: First release](https://github.com/yuki24/andpush/tree/v0.1.0)
2
+
3
+ _<sup>released on 2017-06-03 02:04:28 UTC</sup>_
4
+
data/README.md CHANGED
@@ -1,6 +1,10 @@
1
- # Andpush
1
+ # Andpush [![Build Status](https://travis-ci.org/yuki24/andpush.svg?branch=master)](https://travis-ci.org/yuki24/andpush)
2
2
 
3
- Andpush is an HTTP client for FCM (Firebase Cloud Messaging). It implements [Firebase Cloud Messaging HTTP Protocol](https://firebase.google.com/docs/cloud-messaging/http-server-ref).
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
+
5
+ The `andpush` gem performs **about 3.7x faster** than [the fcm gem](https://github.com/spacialdb/fcm) in a single-threaded environment. In a multi-threaded environment, it could perform **10x or even faster!**
6
+
7
+ **If you are thining to send push notifications from Rails, consider using the [pushing gem](https://github.com/yuki24/pushing), a push notification framework that does not hurt.**
4
8
 
5
9
  ## Installation
6
10
 
@@ -10,10 +14,6 @@ Add this line to your application's Gemfile:
10
14
  gem 'andpush'
11
15
  ```
12
16
 
13
- And then execute:
14
-
15
- $ bundle
16
-
17
17
  Or install it yourself as:
18
18
 
19
19
  $ gem install andpush
@@ -28,8 +28,20 @@ require 'andpush'
28
28
  server_key = "..." # Your server key
29
29
  device_token = "..." # The device token of the device you'd like to push a message to
30
30
 
31
- client = Andpush.build(server_key)
32
- response = client.push(to: device_token, notification: { title: "Update", body: "Your weekly summary is ready" }, data: { extra: "data" })
31
+ client = Andpush.new(server_key, pool_size: 25)
32
+ payload = {
33
+ to: device_token,
34
+ notification: {
35
+ title: "Update",
36
+ body: "Your weekly summary is ready"
37
+ },
38
+ data: { extra: "data" }
39
+ }
40
+
41
+ response = client.push(payload)
42
+
43
+ headers = response.headers
44
+ headers['Retry-After'] # => returns 'Retry-After'
33
45
 
34
46
  json = response.json
35
47
  json[:canonical_ids] # => 0
@@ -42,6 +54,38 @@ result[:error] # => nil, "InvalidRegistration" or something else
42
54
  result[:registration_id] # => nil
43
55
  ```
44
56
 
57
+ ### Topic Messaging:
58
+
59
+ ```ruby
60
+ topic = "/topics/foo-bar"
61
+ payload = {
62
+ to: topic,
63
+ data: {
64
+ message: "This is a Firebase Cloud Messaging Topic Message!",
65
+ }
66
+ }
67
+
68
+ response = client.push(payload) # => sends a message to the topic
69
+ ```
70
+
71
+ ## Performance
72
+
73
+ 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:
74
+
75
+ ```sh
76
+ $ ruby bench.rb
77
+ Warming up --------------------------------------
78
+ andpush 2.000 i/100ms
79
+ fcm 1.000 i/100ms
80
+ Calculating -------------------------------------
81
+ andpush 28.009 (± 7.1%) i/s - 140.000 in 5.019399s
82
+ fcm 7.452 (±13.4%) i/s - 37.000 in 5.023139s
83
+
84
+ Comparison:
85
+ andpush: 28.0 i/s
86
+ fcm: 7.5 i/s - 3.76x slower
87
+ ```
88
+
45
89
  ## Contributing
46
90
 
47
91
  Bug reports and pull requests are welcome on GitHub at https://github.com/yuki24/andpush. 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.
data/andpush.gemspec CHANGED
@@ -15,7 +15,7 @@ Gem::Specification.new do |spec|
15
15
  spec.files = `git ls-files -z`.split("\x0").reject {|f| f.match(%r{^(test)/}) }
16
16
  spec.require_paths = ["lib"]
17
17
 
18
- spec.add_dependency 'net-http-persistent'
18
+ spec.add_dependency 'net-http-persistent', '>= 3.0.0'
19
19
 
20
20
  spec.add_development_dependency "bundler"
21
21
  spec.add_development_dependency "rake"
data/lib/andpush.rb CHANGED
@@ -6,10 +6,13 @@ require 'andpush/client'
6
6
  module Andpush
7
7
  DOMAIN = 'https://fcm.googleapis.com'.freeze
8
8
 
9
- def self.build(server_key, domain: nil, request_handler: ConnectionPool.new)
10
- ::Andpush::Client
11
- .new(domain || DOMAIN, request_handler: request_handler)
12
- .register_interceptor(Authenticator.new(server_key))
9
+ class << self
10
+ def build(server_key, domain: nil, name: nil, proxy: nil, pool_size: Net::HTTP::Persistent::DEFAULT_POOL_SIZE)
11
+ ::Andpush::Client
12
+ .new(domain || DOMAIN, request_handler: ConnectionPool.new(name: name, proxy: proxy, pool_size: pool_size))
13
+ .register_interceptor(Authenticator.new(server_key))
14
+ end
15
+ alias new build
13
16
  end
14
17
 
15
18
  class Authenticator
@@ -1,3 +1,3 @@
1
1
  module Andpush
2
- VERSION = '0.1.0'.freeze
2
+ VERSION = '0.2.0'.freeze
3
3
  end
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.1.0
4
+ version: 0.2.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Yuki Nishijima
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2017-05-29 00:00:00.000000000 Z
11
+ date: 2018-03-08 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: net-http-persistent
@@ -16,14 +16,14 @@ dependencies:
16
16
  requirements:
17
17
  - - ">="
18
18
  - !ruby/object:Gem::Version
19
- version: '0'
19
+ version: 3.0.0
20
20
  type: :runtime
21
21
  prerelease: false
22
22
  version_requirements: !ruby/object:Gem::Requirement
23
23
  requirements:
24
24
  - - ">="
25
25
  - !ruby/object:Gem::Version
26
- version: '0'
26
+ version: 3.0.0
27
27
  - !ruby/object:Gem::Dependency
28
28
  name: bundler
29
29
  requirement: !ruby/object:Gem::Requirement
@@ -75,6 +75,7 @@ extra_rdoc_files: []
75
75
  files:
76
76
  - ".gitignore"
77
77
  - ".travis.yml"
78
+ - CHANGELOG.md
78
79
  - CODE_OF_CONDUCT.md
79
80
  - Gemfile
80
81
  - LICENSE.txt
@@ -110,7 +111,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
110
111
  version: '0'
111
112
  requirements: []
112
113
  rubyforge_project:
113
- rubygems_version: 2.6.12
114
+ rubygems_version: 2.7.6
114
115
  signing_key:
115
116
  specification_version: 4
116
117
  summary: FCM HTTP client