fcmpush 0.1.1 → 0.1.2
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/.travis.yml +7 -2
- data/Gemfile.lock +1 -1
- data/README.md +2 -2
- data/lib/fcmpush.rb +5 -122
- data/lib/fcmpush/exceptions.rb +100 -0
- data/lib/fcmpush/json_response.rb +22 -0
- data/lib/fcmpush/version.rb +1 -1
- metadata +4 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: eff608513cb7687d9cca8c68084dcfd5be1ca90c4037d62988bbd641bf988387
|
4
|
+
data.tar.gz: 6a48e86e369b7aa8864be4106ea0914a59d6d10c72d0d3c7399061686f7fdad2
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 71a1906f8a7abe5f8d84144ff4bbc37d635224448563aac8b619383751f2a9fed4bdb71fedcc909e63fe4f590b2cdc6d42c12b641f6d33492b3885485f5ce286
|
7
|
+
data.tar.gz: 0f451566f5ca7174c72f3434f15b541b8ae44136202d7e211f684a869aa6e2d979a55dbb26339adfd2ba05e019c00ecb1565feaba4c4962a3dfa6d10c1d523be
|
data/.travis.yml
CHANGED
@@ -1,7 +1,12 @@
|
|
1
|
-
---
|
2
1
|
sudo: false
|
3
2
|
language: ruby
|
4
3
|
cache: bundler
|
4
|
+
script: bundle exec rspec
|
5
5
|
rvm:
|
6
|
-
- 2.
|
6
|
+
- 2.4.9
|
7
|
+
- 2.5.7
|
8
|
+
- 2.6.5
|
7
9
|
before_install: gem install bundler -v 2.0.2
|
10
|
+
notifications:
|
11
|
+
slack:
|
12
|
+
secure: Uckm/iIr1N6dvkzJeGes8yARAQSHLFGWjAw7CsNGiU5KERf0a/WWo+8OoWAqBtgcnqVDdBcNm0aUax+5JbfyLg0q8YW1wtYuAE2Gqocvs5TPt8XwyEQv6sYyN1mqrcJWl4FO22DCxF+Oetju1wEjpjSVYs6uzDrj7U6HzuJON/yd+lUjJWOD1OOaRJUYjI9uU7x7RRscECGU8p0ffjeiGOkM2EuJ/osA/CeDlDd93hlUpseZqxceQGdsSZHscbqV0eWVDexoPtUOIK08VFgCk3FIA4vfO8XDaBibSiqiTYUPGPQILjMhGKmB/dmz2LyxdWGdCBOjH1CnD1LXNq9yPhquDXm/2u4cVWIV7bgOHDZ6ylRz0u+AUWVMI/VJOd27YOkZCGgqbb12Y7sBh0m9KalU/fqfIafOvt24j5o2abjJCKHoTUgdESpbLYqnZvK00uRjjOp0H0yQnXicaFE4lByAGbxmpxWZ3fs1OZkppYOl8dF9AQWB6Uty4KraTpUB6fGHoE7/IPeUNsENXWPUqITsRDPFjCTWED/YvKfUi+xTA+K1vJZympsPevT6xcL82TXGDtdHA4U52MLiAuizXP/+R3XhO2PzBSyLbEMus2iJYwXsIac157uhcDrECQfIkm9DMtSHKP83ABf/Flj73NKayWYP0OsigBdUYVgs5aQ=
|
data/Gemfile.lock
CHANGED
data/README.md
CHANGED
@@ -1,4 +1,4 @@
|
|
1
|
-
# Fcmpush
|
1
|
+
# Fcmpush [![Build Status](https://travis-ci.org/miyataka/fcmpush.svg?branch=master)](https://travis-ci.org/miyataka/fcmpush)
|
2
2
|
|
3
3
|
Fcmpush is an Firebase Cloud Messaging(FCM) Client. It implements [FCM HTTP v1 API](https://firebase.google.com/docs/reference/fcm/rest/v1/projects.messages).
|
4
4
|
This gem supports HTTP v1 API only, **NOT supported [legacy HTTP protocol](https://firebase.google.com/docs/cloud-messaging/http-server-ref)**, because both authentication method is different.
|
@@ -52,7 +52,7 @@ payload = { # ref. https://firebase.google.com/docs/reference/fcm/rest/v1/projec
|
|
52
52
|
notification: {
|
53
53
|
title: "this is title",
|
54
54
|
body: "this is message body"
|
55
|
-
|
55
|
+
}
|
56
56
|
}
|
57
57
|
}
|
58
58
|
|
data/lib/fcmpush.rb
CHANGED
@@ -1,10 +1,11 @@
|
|
1
|
-
require 'fcmpush/configuration'
|
2
|
-
require 'fcmpush/version'
|
3
|
-
|
4
1
|
require 'net/http/persistent'
|
5
|
-
require 'json'
|
6
2
|
require 'googleauth'
|
7
3
|
|
4
|
+
require 'fcmpush/configuration'
|
5
|
+
require 'fcmpush/version'
|
6
|
+
require 'fcmpush/exceptions'
|
7
|
+
require 'fcmpush/json_response'
|
8
|
+
|
8
9
|
module Fcmpush
|
9
10
|
class Error < StandardError; end
|
10
11
|
DOMAIN = 'https://fcm.googleapis.com'.freeze
|
@@ -85,122 +86,4 @@ module Fcmpush
|
|
85
86
|
response
|
86
87
|
end
|
87
88
|
end
|
88
|
-
|
89
|
-
class JsonResponse < DelegateClass(Net::HTTPResponse)
|
90
|
-
alias response __getobj__
|
91
|
-
alias headers to_hash
|
92
|
-
HAS_SYMBOL_GC = RUBY_VERSION > '2.2.0'
|
93
|
-
|
94
|
-
def json
|
95
|
-
parsable? ? JSON.parse(body, symbolize_names: HAS_SYMBOL_GC) : nil
|
96
|
-
end
|
97
|
-
|
98
|
-
def inspect
|
99
|
-
"#<JsonResponse response: #{response.inspect}, json: #{json}>"
|
100
|
-
end
|
101
|
-
alias to_s inspect
|
102
|
-
|
103
|
-
def parsable?
|
104
|
-
!body.nil? && !body.empty?
|
105
|
-
end
|
106
|
-
end
|
107
|
-
|
108
|
-
class APIError < StandardError; end
|
109
|
-
class NetworkError < APIError; end
|
110
|
-
|
111
|
-
class HttpError < APIError
|
112
|
-
attr_reader :response
|
113
|
-
|
114
|
-
def initialize(message, response)
|
115
|
-
super(message)
|
116
|
-
@response = response
|
117
|
-
end
|
118
|
-
end
|
119
|
-
|
120
|
-
class ClientError < HttpError; end
|
121
|
-
|
122
|
-
class BadRequest < ClientError; end # status: 400
|
123
|
-
class Unauthorized < ClientError; end # status: 401
|
124
|
-
class PaymentRequired < ClientError; end # status: 402
|
125
|
-
class Forbidden < ClientError; end # status: 403
|
126
|
-
class NotFound < ClientError; end # status: 404
|
127
|
-
class MethodNotAllowed < ClientError; end # status: 405
|
128
|
-
class NotAcceptable < ClientError; end # status: 406
|
129
|
-
class ProxyAuthenticationRequired < ClientError; end # status: 407
|
130
|
-
class RequestTimeout < ClientError; end # status: 408
|
131
|
-
class Conflict < ClientError; end # status: 409
|
132
|
-
class Gone < ClientError; end # status: 410
|
133
|
-
class LengthRequired < ClientError; end # status: 411
|
134
|
-
class PreconditionFailed < ClientError; end # status: 412
|
135
|
-
class PayloadTooLarge < ClientError; end # status: 413
|
136
|
-
class URITooLong < ClientError; end # status: 414
|
137
|
-
class UnsupportedMediaType < ClientError; end # status: 415
|
138
|
-
class RangeNotSatisfiable < ClientError; end # status: 416
|
139
|
-
class ExpectationFailed < ClientError; end # status: 417
|
140
|
-
class ImaTeapot < ClientError; end # status: 418
|
141
|
-
class MisdirectedRequest < ClientError; end # status: 421
|
142
|
-
class UnprocessableEntity < ClientError; end # status: 422
|
143
|
-
class Locked < ClientError; end # status: 423
|
144
|
-
class FailedDependency < ClientError; end # status: 424
|
145
|
-
class UpgradeRequired < ClientError; end # status: 426
|
146
|
-
class PreconditionRequired < ClientError; end # status: 428
|
147
|
-
class TooManyRequests < ClientError; end # status: 429
|
148
|
-
class RequestHeaderFieldsTooLarge < ClientError; end # status: 431
|
149
|
-
class UnavailableForLegalReasons < ClientError; end # status: 451
|
150
|
-
|
151
|
-
class ServerError < HttpError; end
|
152
|
-
|
153
|
-
class InternalServerError < ServerError; end # status: 500
|
154
|
-
class NotImplemented < ServerError; end # status: 501
|
155
|
-
class BadGateway < ServerError; end # status: 502
|
156
|
-
class ServiceUnavailable < ServerError; end # status: 503
|
157
|
-
class GatewayTimeout < ServerError; end # status: 504
|
158
|
-
class HTTPVersionNotSupported < ServerError; end # status: 505
|
159
|
-
class VariantAlsoNegotiates < ServerError; end # status: 506
|
160
|
-
class InsufficientStorage < ServerError; end # status: 507
|
161
|
-
class LoopDetected < ServerError; end # status: 508
|
162
|
-
class NotExtended < ServerError; end # status: 510
|
163
|
-
class NetworkAuthenticationRequired < ServerError; end # status: 511
|
164
|
-
|
165
|
-
STATUS_TO_EXCEPTION_MAPPING = {
|
166
|
-
'400' => BadRequest,
|
167
|
-
'401' => Unauthorized,
|
168
|
-
'402' => PaymentRequired,
|
169
|
-
'403' => Forbidden,
|
170
|
-
'404' => NotFound,
|
171
|
-
'405' => MethodNotAllowed,
|
172
|
-
'406' => NotAcceptable,
|
173
|
-
'407' => ProxyAuthenticationRequired,
|
174
|
-
'408' => RequestTimeout,
|
175
|
-
'409' => Conflict,
|
176
|
-
'410' => Gone,
|
177
|
-
'411' => LengthRequired,
|
178
|
-
'412' => PreconditionFailed,
|
179
|
-
'413' => PayloadTooLarge,
|
180
|
-
'414' => URITooLong,
|
181
|
-
'415' => UnsupportedMediaType,
|
182
|
-
'416' => RangeNotSatisfiable,
|
183
|
-
'417' => ExpectationFailed,
|
184
|
-
'418' => ImaTeapot,
|
185
|
-
'421' => MisdirectedRequest,
|
186
|
-
'422' => UnprocessableEntity,
|
187
|
-
'423' => Locked,
|
188
|
-
'424' => FailedDependency,
|
189
|
-
'426' => UpgradeRequired,
|
190
|
-
'428' => PreconditionRequired,
|
191
|
-
'429' => TooManyRequests,
|
192
|
-
'431' => RequestHeaderFieldsTooLarge,
|
193
|
-
'451' => UnavailableForLegalReasons,
|
194
|
-
'500' => InternalServerError,
|
195
|
-
'501' => NotImplemented,
|
196
|
-
'502' => BadGateway,
|
197
|
-
'503' => ServiceUnavailable,
|
198
|
-
'504' => GatewayTimeout,
|
199
|
-
'505' => HTTPVersionNotSupported,
|
200
|
-
'506' => VariantAlsoNegotiates,
|
201
|
-
'507' => InsufficientStorage,
|
202
|
-
'508' => LoopDetected,
|
203
|
-
'510' => NotExtended,
|
204
|
-
'511' => NetworkAuthenticationRequired
|
205
|
-
}.freeze
|
206
89
|
end
|
@@ -0,0 +1,100 @@
|
|
1
|
+
module Fcmpush
|
2
|
+
class APIError < StandardError; end
|
3
|
+
class NetworkError < APIError; end
|
4
|
+
|
5
|
+
class HttpError < APIError
|
6
|
+
attr_reader :response
|
7
|
+
|
8
|
+
def initialize(message, response)
|
9
|
+
super(message)
|
10
|
+
@response = response
|
11
|
+
end
|
12
|
+
end
|
13
|
+
|
14
|
+
class ClientError < HttpError; end
|
15
|
+
|
16
|
+
class BadRequest < ClientError; end # status: 400
|
17
|
+
class Unauthorized < ClientError; end # status: 401
|
18
|
+
class PaymentRequired < ClientError; end # status: 402
|
19
|
+
class Forbidden < ClientError; end # status: 403
|
20
|
+
class NotFound < ClientError; end # status: 404
|
21
|
+
class MethodNotAllowed < ClientError; end # status: 405
|
22
|
+
class NotAcceptable < ClientError; end # status: 406
|
23
|
+
class ProxyAuthenticationRequired < ClientError; end # status: 407
|
24
|
+
class RequestTimeout < ClientError; end # status: 408
|
25
|
+
class Conflict < ClientError; end # status: 409
|
26
|
+
class Gone < ClientError; end # status: 410
|
27
|
+
class LengthRequired < ClientError; end # status: 411
|
28
|
+
class PreconditionFailed < ClientError; end # status: 412
|
29
|
+
class PayloadTooLarge < ClientError; end # status: 413
|
30
|
+
class URITooLong < ClientError; end # status: 414
|
31
|
+
class UnsupportedMediaType < ClientError; end # status: 415
|
32
|
+
class RangeNotSatisfiable < ClientError; end # status: 416
|
33
|
+
class ExpectationFailed < ClientError; end # status: 417
|
34
|
+
class ImaTeapot < ClientError; end # status: 418
|
35
|
+
class MisdirectedRequest < ClientError; end # status: 421
|
36
|
+
class UnprocessableEntity < ClientError; end # status: 422
|
37
|
+
class Locked < ClientError; end # status: 423
|
38
|
+
class FailedDependency < ClientError; end # status: 424
|
39
|
+
class UpgradeRequired < ClientError; end # status: 426
|
40
|
+
class PreconditionRequired < ClientError; end # status: 428
|
41
|
+
class TooManyRequests < ClientError; end # status: 429
|
42
|
+
class RequestHeaderFieldsTooLarge < ClientError; end # status: 431
|
43
|
+
class UnavailableForLegalReasons < ClientError; end # status: 451
|
44
|
+
|
45
|
+
class ServerError < HttpError; end
|
46
|
+
|
47
|
+
class InternalServerError < ServerError; end # status: 500
|
48
|
+
class NotImplemented < ServerError; end # status: 501
|
49
|
+
class BadGateway < ServerError; end # status: 502
|
50
|
+
class ServiceUnavailable < ServerError; end # status: 503
|
51
|
+
class GatewayTimeout < ServerError; end # status: 504
|
52
|
+
class HTTPVersionNotSupported < ServerError; end # status: 505
|
53
|
+
class VariantAlsoNegotiates < ServerError; end # status: 506
|
54
|
+
class InsufficientStorage < ServerError; end # status: 507
|
55
|
+
class LoopDetected < ServerError; end # status: 508
|
56
|
+
class NotExtended < ServerError; end # status: 510
|
57
|
+
class NetworkAuthenticationRequired < ServerError; end # status: 511
|
58
|
+
|
59
|
+
STATUS_TO_EXCEPTION_MAPPING = {
|
60
|
+
'400' => BadRequest,
|
61
|
+
'401' => Unauthorized,
|
62
|
+
'402' => PaymentRequired,
|
63
|
+
'403' => Forbidden,
|
64
|
+
'404' => NotFound,
|
65
|
+
'405' => MethodNotAllowed,
|
66
|
+
'406' => NotAcceptable,
|
67
|
+
'407' => ProxyAuthenticationRequired,
|
68
|
+
'408' => RequestTimeout,
|
69
|
+
'409' => Conflict,
|
70
|
+
'410' => Gone,
|
71
|
+
'411' => LengthRequired,
|
72
|
+
'412' => PreconditionFailed,
|
73
|
+
'413' => PayloadTooLarge,
|
74
|
+
'414' => URITooLong,
|
75
|
+
'415' => UnsupportedMediaType,
|
76
|
+
'416' => RangeNotSatisfiable,
|
77
|
+
'417' => ExpectationFailed,
|
78
|
+
'418' => ImaTeapot,
|
79
|
+
'421' => MisdirectedRequest,
|
80
|
+
'422' => UnprocessableEntity,
|
81
|
+
'423' => Locked,
|
82
|
+
'424' => FailedDependency,
|
83
|
+
'426' => UpgradeRequired,
|
84
|
+
'428' => PreconditionRequired,
|
85
|
+
'429' => TooManyRequests,
|
86
|
+
'431' => RequestHeaderFieldsTooLarge,
|
87
|
+
'451' => UnavailableForLegalReasons,
|
88
|
+
'500' => InternalServerError,
|
89
|
+
'501' => NotImplemented,
|
90
|
+
'502' => BadGateway,
|
91
|
+
'503' => ServiceUnavailable,
|
92
|
+
'504' => GatewayTimeout,
|
93
|
+
'505' => HTTPVersionNotSupported,
|
94
|
+
'506' => VariantAlsoNegotiates,
|
95
|
+
'507' => InsufficientStorage,
|
96
|
+
'508' => LoopDetected,
|
97
|
+
'510' => NotExtended,
|
98
|
+
'511' => NetworkAuthenticationRequired
|
99
|
+
}.freeze
|
100
|
+
end
|
@@ -0,0 +1,22 @@
|
|
1
|
+
require 'json'
|
2
|
+
|
3
|
+
module Fcmpush
|
4
|
+
class JsonResponse < DelegateClass(Net::HTTPResponse)
|
5
|
+
alias response __getobj__
|
6
|
+
alias headers to_hash
|
7
|
+
HAS_SYMBOL_GC = RUBY_VERSION > '2.2.0'
|
8
|
+
|
9
|
+
def json
|
10
|
+
parsable? ? JSON.parse(body, symbolize_names: HAS_SYMBOL_GC) : nil
|
11
|
+
end
|
12
|
+
|
13
|
+
def inspect
|
14
|
+
"#<JsonResponse response: #{response.inspect}, json: #{json}>"
|
15
|
+
end
|
16
|
+
alias to_s inspect
|
17
|
+
|
18
|
+
def parsable?
|
19
|
+
!body.nil? && !body.empty?
|
20
|
+
end
|
21
|
+
end
|
22
|
+
end
|
data/lib/fcmpush/version.rb
CHANGED
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: fcmpush
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.1.
|
4
|
+
version: 0.1.2
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Takayuki Miyahara
|
8
8
|
autorequire:
|
9
9
|
bindir: exe
|
10
10
|
cert_chain: []
|
11
|
-
date: 2019-10-
|
11
|
+
date: 2019-10-15 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: googleauth
|
@@ -101,6 +101,8 @@ files:
|
|
101
101
|
- fcmpush.gemspec
|
102
102
|
- lib/fcmpush.rb
|
103
103
|
- lib/fcmpush/configuration.rb
|
104
|
+
- lib/fcmpush/exceptions.rb
|
105
|
+
- lib/fcmpush/json_response.rb
|
104
106
|
- lib/fcmpush/version.rb
|
105
107
|
homepage: https://github.com/miyataka/fcmpush
|
106
108
|
licenses:
|