firebase-admin 0.1.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- checksums.yaml +7 -0
- data/.gitignore +3 -0
- data/.rubocop.yml +13 -0
- data/.rubocop_todo.yml +49 -0
- data/.tool-versions +1 -0
- data/Gemfile +3 -0
- data/Gemfile.lock +84 -0
- data/LICENSE +21 -0
- data/README.md +22 -0
- data/firebase-admin.gemspec +27 -0
- data/lib/faraday/loud_logger.rb +75 -0
- data/lib/faraday/raise_http_exception.rb +61 -0
- data/lib/firebase-admin.rb +32 -0
- data/lib/firebase-admin/api.rb +29 -0
- data/lib/firebase-admin/client.rb +11 -0
- data/lib/firebase-admin/client/accounts.rb +159 -0
- data/lib/firebase-admin/configuration.rb +78 -0
- data/lib/firebase-admin/connection.rb +30 -0
- data/lib/firebase-admin/error.rb +28 -0
- data/lib/firebase-admin/request.rb +44 -0
- data/lib/firebase-admin/version.rb +3 -0
- data/spec/faraday/raise_http_exceptions_spec.rb +73 -0
- data/spec/firebase-admin/api_spec.rb +134 -0
- data/spec/firebase-admin/client/accounts_spec.rb +23 -0
- data/spec/firebase-admin/client_spec.rb +10 -0
- data/spec/firebase_admin_spec.rb +94 -0
- data/spec/fixtures/400_error.json +13 -0
- data/spec/fixtures/bad_gateway.html +1 -0
- data/spec/fixtures/create_account.json +6 -0
- data/spec/fixtures/gateway_timeout.html +1 -0
- data/spec/spec_helper.rb +72 -0
- metadata +223 -0
checksums.yaml
ADDED
@@ -0,0 +1,7 @@
|
|
1
|
+
---
|
2
|
+
SHA256:
|
3
|
+
metadata.gz: be6f75e823e4cb67948c9e7f421d8ecbf853e67a2d82a327f130e9d885a2647e
|
4
|
+
data.tar.gz: a1875e974a100cd4718add6cf91157717345bb2f722285bb5818556395d98980
|
5
|
+
SHA512:
|
6
|
+
metadata.gz: 9aa236550ed151bf5668751a0981dd80162414418838393da4d0d1e994b1f2e67dd0ad049b3f4faa861842ca376291b87480008c48b26498751947216c26d790
|
7
|
+
data.tar.gz: 64d74c30441e8ba9666d93d21cbab49ecca8c1ba96f391c33bccd8b4b7b98504c60ad11d5d7f9e8022a7808b1121d354380fcefa07a831825ca97c53e6413ec0
|
data/.gitignore
ADDED
data/.rubocop.yml
ADDED
@@ -0,0 +1,13 @@
|
|
1
|
+
inherit_from: .rubocop_todo.yml
|
2
|
+
|
3
|
+
AllCops:
|
4
|
+
Exclude:
|
5
|
+
<% `git status --ignored --porcelain`.lines.grep(/^!! /).each do |path| %>
|
6
|
+
- <%= path.sub(/^!! /, '') %>
|
7
|
+
<% end %>
|
8
|
+
- spec/spec_helper.rb
|
9
|
+
TargetRubyVersion: 2.7
|
10
|
+
NewCops: enable
|
11
|
+
|
12
|
+
Naming/VariableNumber:
|
13
|
+
EnforcedStyle: snake_case
|
data/.rubocop_todo.yml
ADDED
@@ -0,0 +1,49 @@
|
|
1
|
+
# This configuration was generated by
|
2
|
+
# `rubocop --auto-gen-config`
|
3
|
+
# on 2021-02-01 09:18:40 UTC using RuboCop version 1.9.0.
|
4
|
+
# The point is for the user to remove these configuration records
|
5
|
+
# one by one as the offenses are removed from the code base.
|
6
|
+
# Note that changes in the inspected code, or installation of new
|
7
|
+
# versions of RuboCop, may require this file to be generated again.
|
8
|
+
|
9
|
+
# Offense count: 2
|
10
|
+
# Configuration parameters: IgnoredMethods, CountRepeatedAttributes.
|
11
|
+
Metrics/AbcSize:
|
12
|
+
Max: 20
|
13
|
+
|
14
|
+
# Offense count: 6
|
15
|
+
# Configuration parameters: CountComments, CountAsOne, ExcludedMethods, IgnoredMethods.
|
16
|
+
# IgnoredMethods: refine
|
17
|
+
Metrics/BlockLength:
|
18
|
+
Max: 111
|
19
|
+
|
20
|
+
# Offense count: 2
|
21
|
+
# Configuration parameters: IgnoredMethods.
|
22
|
+
Metrics/CyclomaticComplexity:
|
23
|
+
Max: 8
|
24
|
+
|
25
|
+
# Offense count: 2
|
26
|
+
# Configuration parameters: CountComments, CountAsOne, ExcludedMethods, IgnoredMethods.
|
27
|
+
Metrics/MethodLength:
|
28
|
+
Max: 25
|
29
|
+
|
30
|
+
# Offense count: 1
|
31
|
+
# Configuration parameters: IgnoredMethods.
|
32
|
+
Metrics/PerceivedComplexity:
|
33
|
+
Max: 9
|
34
|
+
|
35
|
+
# Offense count: 3
|
36
|
+
Style/Documentation:
|
37
|
+
Exclude:
|
38
|
+
- 'spec/**/*'
|
39
|
+
- 'test/**/*'
|
40
|
+
- 'lib/firebase-admin.rb'
|
41
|
+
- 'lib/firebase-admin/response.rb'
|
42
|
+
- 'lib/firebase-admin/version.rb'
|
43
|
+
|
44
|
+
# Offense count: 18
|
45
|
+
# Cop supports --auto-correct.
|
46
|
+
# Configuration parameters: EnforcedStyle.
|
47
|
+
# SupportedStyles: always, always_true, never
|
48
|
+
Style/FrozenStringLiteralComment:
|
49
|
+
Enabled: false
|
data/.tool-versions
ADDED
@@ -0,0 +1 @@
|
|
1
|
+
ruby 3.0.0
|
data/Gemfile
ADDED
data/Gemfile.lock
ADDED
@@ -0,0 +1,84 @@
|
|
1
|
+
PATH
|
2
|
+
remote: .
|
3
|
+
specs:
|
4
|
+
firebase-admin (0.1.0)
|
5
|
+
addressable (~> 2.7)
|
6
|
+
faraday (~> 1.3)
|
7
|
+
faraday_middleware (~> 1.0)
|
8
|
+
hashie (~> 4.1)
|
9
|
+
jwt (~> 2.2.2)
|
10
|
+
multi_json (~> 1.15)
|
11
|
+
|
12
|
+
GEM
|
13
|
+
remote: https://rubygems.org/
|
14
|
+
specs:
|
15
|
+
addressable (2.7.0)
|
16
|
+
public_suffix (>= 2.0.2, < 5.0)
|
17
|
+
ast (2.4.2)
|
18
|
+
crack (0.4.5)
|
19
|
+
rexml
|
20
|
+
diff-lcs (1.4.4)
|
21
|
+
faraday (1.3.0)
|
22
|
+
faraday-net_http (~> 1.0)
|
23
|
+
multipart-post (>= 1.2, < 3)
|
24
|
+
ruby2_keywords
|
25
|
+
faraday-net_http (1.0.1)
|
26
|
+
faraday_middleware (1.0.0)
|
27
|
+
faraday (~> 1.0)
|
28
|
+
hashdiff (1.0.1)
|
29
|
+
hashie (4.1.0)
|
30
|
+
jwt (2.2.2)
|
31
|
+
multi_json (1.15.0)
|
32
|
+
multipart-post (2.1.1)
|
33
|
+
parallel (1.20.1)
|
34
|
+
parser (3.0.0.0)
|
35
|
+
ast (~> 2.4.1)
|
36
|
+
public_suffix (4.0.6)
|
37
|
+
rainbow (3.0.0)
|
38
|
+
rake (13.0.3)
|
39
|
+
regexp_parser (2.0.3)
|
40
|
+
rexml (3.2.4)
|
41
|
+
rspec (3.10.0)
|
42
|
+
rspec-core (~> 3.10.0)
|
43
|
+
rspec-expectations (~> 3.10.0)
|
44
|
+
rspec-mocks (~> 3.10.0)
|
45
|
+
rspec-core (3.10.1)
|
46
|
+
rspec-support (~> 3.10.0)
|
47
|
+
rspec-expectations (3.10.1)
|
48
|
+
diff-lcs (>= 1.2.0, < 2.0)
|
49
|
+
rspec-support (~> 3.10.0)
|
50
|
+
rspec-mocks (3.10.2)
|
51
|
+
diff-lcs (>= 1.2.0, < 2.0)
|
52
|
+
rspec-support (~> 3.10.0)
|
53
|
+
rspec-support (3.10.2)
|
54
|
+
rubocop (1.9.0)
|
55
|
+
parallel (~> 1.10)
|
56
|
+
parser (>= 3.0.0.0)
|
57
|
+
rainbow (>= 2.2.2, < 4.0)
|
58
|
+
regexp_parser (>= 1.8, < 3.0)
|
59
|
+
rexml
|
60
|
+
rubocop-ast (>= 1.2.0, < 2.0)
|
61
|
+
ruby-progressbar (~> 1.7)
|
62
|
+
unicode-display_width (>= 1.4.0, < 3.0)
|
63
|
+
rubocop-ast (1.4.1)
|
64
|
+
parser (>= 2.7.1.5)
|
65
|
+
ruby-progressbar (1.11.0)
|
66
|
+
ruby2_keywords (0.0.4)
|
67
|
+
unicode-display_width (2.0.0)
|
68
|
+
webmock (3.11.2)
|
69
|
+
addressable (>= 2.3.6)
|
70
|
+
crack (>= 0.3.2)
|
71
|
+
hashdiff (>= 0.4.0, < 2.0.0)
|
72
|
+
|
73
|
+
PLATFORMS
|
74
|
+
x86_64-darwin-20
|
75
|
+
|
76
|
+
DEPENDENCIES
|
77
|
+
firebase-admin!
|
78
|
+
rake (~> 13.0)
|
79
|
+
rspec (~> 3.10)
|
80
|
+
rubocop (~> 1.9)
|
81
|
+
webmock (~> 3.11)
|
82
|
+
|
83
|
+
BUNDLED WITH
|
84
|
+
2.2.6
|
data/LICENSE
ADDED
@@ -0,0 +1,21 @@
|
|
1
|
+
MIT License
|
2
|
+
|
3
|
+
Copyright (c) 2021 Colin Harris
|
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 all
|
13
|
+
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 THE
|
21
|
+
SOFTWARE.
|
data/README.md
ADDED
@@ -0,0 +1,22 @@
|
|
1
|
+
# Firebase Admin
|
2
|
+
|
3
|
+
A ruby wrapper for the Firebase Admin APIs.
|
4
|
+
|
5
|
+
## Example
|
6
|
+
|
7
|
+
```
|
8
|
+
# Initial global configuration
|
9
|
+
FirebaseAdmin.configure do |config|
|
10
|
+
config.project_id = "YOUR_PROJECT_ID"
|
11
|
+
end
|
12
|
+
|
13
|
+
# Client specific configuration
|
14
|
+
client = FirebaseAdmin.client(access_token: "")
|
15
|
+
|
16
|
+
# API call
|
17
|
+
response = client.create_account(
|
18
|
+
email: "",
|
19
|
+
...
|
20
|
+
)
|
21
|
+
|
22
|
+
```
|
@@ -0,0 +1,27 @@
|
|
1
|
+
require File.expand_path('lib/firebase-admin/version', __dir__)
|
2
|
+
|
3
|
+
Gem::Specification.new do |s|
|
4
|
+
s.add_development_dependency('rake', '~> 13.0')
|
5
|
+
s.add_development_dependency('rspec', '~> 3.10')
|
6
|
+
s.add_development_dependency('rubocop', '~> 1.9')
|
7
|
+
s.add_development_dependency('webmock', '~> 3.11')
|
8
|
+
s.add_runtime_dependency('addressable', '~> 2.7')
|
9
|
+
s.add_runtime_dependency('faraday', '~> 1.3')
|
10
|
+
s.add_runtime_dependency('faraday_middleware', '~> 1.0')
|
11
|
+
s.add_runtime_dependency('hashie', '~> 4.1')
|
12
|
+
s.add_runtime_dependency('multi_json', '~> 1.15')
|
13
|
+
s.add_runtime_dependency('jwt', '~> 2.2.2')
|
14
|
+
s.authors = ['Colin Harris']
|
15
|
+
s.description = 'A Ruby wrapper for the Firebase Admin APIs'
|
16
|
+
s.email = ['colin@jiva.ag']
|
17
|
+
s.files = `git ls-files`.split("\n")
|
18
|
+
s.homepage = 'https://github.com/col/firebase-admin'
|
19
|
+
s.license = 'MIT'
|
20
|
+
s.name = 'firebase-admin'
|
21
|
+
s.platform = Gem::Platform::RUBY
|
22
|
+
s.require_paths = ['lib']
|
23
|
+
s.required_ruby_version = '> 2.7'
|
24
|
+
s.summary = 'Ruby wrapper for the Firebase Admin APIs'
|
25
|
+
s.test_files = `git ls-files -- {test,spec,features}/*`.split("\n")
|
26
|
+
s.version = FirebaseAdmin::VERSION.dup
|
27
|
+
end
|
@@ -0,0 +1,75 @@
|
|
1
|
+
require 'faraday'
|
2
|
+
|
3
|
+
# @private
|
4
|
+
module FaradayMiddleware
|
5
|
+
# @private
|
6
|
+
class LoudLogger < Faraday::Middleware
|
7
|
+
extend Forwardable
|
8
|
+
def_delegators :@logger, :debug, :info, :warn, :error, :fatal
|
9
|
+
|
10
|
+
def initialize(app, options = {})
|
11
|
+
super
|
12
|
+
@app = app
|
13
|
+
@logger = options.fetch(:logger) do
|
14
|
+
require 'logger'
|
15
|
+
::Logger.new($stdout)
|
16
|
+
end
|
17
|
+
end
|
18
|
+
|
19
|
+
def call(env)
|
20
|
+
start_time = Time.now
|
21
|
+
info { request_info(env) }
|
22
|
+
debug { request_debug(env) }
|
23
|
+
@app.call(env).on_complete do
|
24
|
+
end_time = Time.now
|
25
|
+
response_time = end_time - start_time
|
26
|
+
info { response_info(env, response_time) }
|
27
|
+
debug { response_debug(env) }
|
28
|
+
end
|
29
|
+
end
|
30
|
+
|
31
|
+
private
|
32
|
+
|
33
|
+
def filter(output)
|
34
|
+
output
|
35
|
+
end
|
36
|
+
|
37
|
+
def request_info(env)
|
38
|
+
format('Started %<method>s request to: %<url>s', method: env[:method].to_s.upcase, url: filter(env[:url]))
|
39
|
+
end
|
40
|
+
|
41
|
+
def response_info(env, response_time)
|
42
|
+
format(
|
43
|
+
'Response from %<method>s; Status: %<status>d; Time: %<time>.1fms',
|
44
|
+
method: env[:method].to_s.upcase,
|
45
|
+
status: env[:status],
|
46
|
+
time: (response_time * 1_000.0)
|
47
|
+
)
|
48
|
+
end
|
49
|
+
|
50
|
+
def request_debug(env)
|
51
|
+
debug_message('Request', env[:request_headers], env[:body])
|
52
|
+
end
|
53
|
+
|
54
|
+
def response_debug(env)
|
55
|
+
debug_message('Response', env[:response_headers], env[:body])
|
56
|
+
end
|
57
|
+
|
58
|
+
def debug_message(name, headers, body)
|
59
|
+
<<-MESSAGE.gsub(/^ +([^ ])/m, '\\1')
|
60
|
+
#{name} Headers:
|
61
|
+
----------------
|
62
|
+
#{format_headers(headers)}
|
63
|
+
|
64
|
+
#{name} Body:
|
65
|
+
-------------
|
66
|
+
#{filter(body)}
|
67
|
+
MESSAGE
|
68
|
+
end
|
69
|
+
|
70
|
+
def format_headers(headers)
|
71
|
+
length = headers.map { |k, _| k.to_s.size }.max
|
72
|
+
headers.map { |name, value| "#{name.to_s.ljust(length)} : #{filter(value)}" }.join("\n")
|
73
|
+
end
|
74
|
+
end
|
75
|
+
end
|
@@ -0,0 +1,61 @@
|
|
1
|
+
require 'faraday'
|
2
|
+
|
3
|
+
# @private
|
4
|
+
module FaradayMiddleware
|
5
|
+
# @private
|
6
|
+
class RaiseHttpException < Faraday::Middleware
|
7
|
+
def call(env)
|
8
|
+
@app.call(env).on_complete do |response|
|
9
|
+
case response[:status].to_i
|
10
|
+
when 400
|
11
|
+
raise FirebaseAdmin::BadRequest,
|
12
|
+
error_message_400(response)
|
13
|
+
when 404
|
14
|
+
raise FirebaseAdmin::NotFound,
|
15
|
+
error_message_400(response)
|
16
|
+
when 429
|
17
|
+
raise FirebaseAdmin::TooManyRequests,
|
18
|
+
error_message_400(response)
|
19
|
+
when 500
|
20
|
+
raise FirebaseAdmin::InternalServerError,
|
21
|
+
error_message_500(response, 'Something is technically wrong.')
|
22
|
+
when 502
|
23
|
+
raise FirebaseAdmin::BadGateway,
|
24
|
+
error_message_500(response, 'The server returned an invalid or incomplete response.')
|
25
|
+
when 503
|
26
|
+
raise FirebaseAdmin::ServiceUnavailable,
|
27
|
+
error_message_500(response, 'Firebase is rate limiting your requests.')
|
28
|
+
when 504
|
29
|
+
raise FirebaseAdmin::GatewayTimeout,
|
30
|
+
error_message_500(response, '504 Gateway Time-out')
|
31
|
+
end
|
32
|
+
end
|
33
|
+
end
|
34
|
+
|
35
|
+
def initialize(app)
|
36
|
+
super app
|
37
|
+
@parser = nil
|
38
|
+
end
|
39
|
+
|
40
|
+
private
|
41
|
+
|
42
|
+
def error_message_400(response)
|
43
|
+
"#{response[:method].to_s.upcase} #{response[:url]}: #{response[:status]}#{error_body(response[:body])}"
|
44
|
+
end
|
45
|
+
|
46
|
+
def error_body(body)
|
47
|
+
# body gets passed as a string, not sure if it is passed as something else from other spots?
|
48
|
+
body = ::JSON.parse(body) if !body.nil? && !body.empty? && body.is_a?(String)
|
49
|
+
|
50
|
+
if body.nil?
|
51
|
+
nil
|
52
|
+
elsif body['error'] && body['error']['message'] && !body['error']['message'].empty?
|
53
|
+
": #{body['error']['message']}"
|
54
|
+
end
|
55
|
+
end
|
56
|
+
|
57
|
+
def error_message_500(response, body = nil)
|
58
|
+
"#{response[:method].to_s.upcase} #{response[:url]}: #{response[:status]}: #{body}"
|
59
|
+
end
|
60
|
+
end
|
61
|
+
end
|
@@ -0,0 +1,32 @@
|
|
1
|
+
require File.expand_path('firebase-admin/error', __dir__)
|
2
|
+
require File.expand_path('firebase-admin/configuration', __dir__)
|
3
|
+
require File.expand_path('firebase-admin/api', __dir__)
|
4
|
+
require File.expand_path('firebase-admin/client', __dir__)
|
5
|
+
|
6
|
+
module FirebaseAdmin
|
7
|
+
extend Configuration
|
8
|
+
|
9
|
+
# Alias for FirebaseAdmin::Client.new
|
10
|
+
#
|
11
|
+
# @return [FirebaseAdmin::Client]
|
12
|
+
def self.client(options = {})
|
13
|
+
FirebaseAdmin::Client.new(options)
|
14
|
+
end
|
15
|
+
|
16
|
+
# Delegate to FirebaseAdmin::Client
|
17
|
+
def self.method_missing(method, *args, &block)
|
18
|
+
return super unless client.respond_to?(method)
|
19
|
+
|
20
|
+
client.send(method, *args, &block)
|
21
|
+
end
|
22
|
+
|
23
|
+
# Delegate to FirebaseAdmin::Client
|
24
|
+
def self.respond_to_missing?(method, include_all)
|
25
|
+
client.respond_to_missing?(method, include_all) || super
|
26
|
+
end
|
27
|
+
|
28
|
+
# Delegate to FirebaseAdmin::Client
|
29
|
+
def self.respond_to?(method, include_all)
|
30
|
+
client.respond_to?(method, include_all) || super
|
31
|
+
end
|
32
|
+
end
|
@@ -0,0 +1,29 @@
|
|
1
|
+
require File.expand_path('connection', __dir__)
|
2
|
+
require File.expand_path('request', __dir__)
|
3
|
+
|
4
|
+
module FirebaseAdmin
|
5
|
+
# @private
|
6
|
+
class API
|
7
|
+
# @private
|
8
|
+
attr_accessor(*Configuration::VALID_OPTIONS_KEYS)
|
9
|
+
|
10
|
+
# Creates a new API
|
11
|
+
def initialize(options = {})
|
12
|
+
options = FirebaseAdmin.options.merge(options)
|
13
|
+
Configuration::VALID_OPTIONS_KEYS.each do |key|
|
14
|
+
send("#{key}=", options[key])
|
15
|
+
end
|
16
|
+
end
|
17
|
+
|
18
|
+
def config
|
19
|
+
conf = {}
|
20
|
+
Configuration::VALID_OPTIONS_KEYS.each do |key|
|
21
|
+
conf[key] = send key
|
22
|
+
end
|
23
|
+
conf
|
24
|
+
end
|
25
|
+
|
26
|
+
include Connection
|
27
|
+
include Request
|
28
|
+
end
|
29
|
+
end
|