firebase-ruby 0.1.0 → 0.2.0.1

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
2
  SHA1:
3
- metadata.gz: 71129a24564dba1985fd02873accf5e6d3546d5e
4
- data.tar.gz: 5e7ce2fcef94d65b4c841baaa19c4d5a504db055
3
+ metadata.gz: 9ed31533488ea96baffad5a57685f0270a38e3c4
4
+ data.tar.gz: 21e8b7d9747ef1f43a614de297a54182781ccb0f
5
5
  SHA512:
6
- metadata.gz: 1ef0c98f6394aaaaf885addb150fa0487c8961180288cef0938f908908797679c34ffa14a5d496e299eaf3f8ef7e3bc499c8c945b285ebb45bd4e163898ee2b8
7
- data.tar.gz: ec53da00cec351a3b6b7f1ade123a1b2b22cf45712c06d6036c2cbb072e46d1ad4caa2e68ab620fb6cce8474e7f740f7c2d6a302d596fe8db60ba81f991c2f91
6
+ metadata.gz: bfb8b6e5680a6be288405e3f3b69f074afbcb91849403d2b816c37985f079b6759e79cb35b06ded436c422d390b48db0f4406e1cf67b04d6e0981cfadd36e499
7
+ data.tar.gz: ef0cfe88733e0f8f6d17f5dd5f05b26e9bfcbe8e530b2f3ecc8ff0e3f15c23202685c031f68a35ae119f88d34ccc025220fd22eada415f36174f958098285421
@@ -0,0 +1,18 @@
1
+ ---
2
+ engines:
3
+ duplication:
4
+ enabled: true
5
+ config:
6
+ languages:
7
+ - ruby:
8
+ fixme:
9
+ enabled: true
10
+ rubocop:
11
+ enabled: true
12
+
13
+ ratings:
14
+ paths:
15
+ - "**"
16
+
17
+ exclude_paths:
18
+ - lib/firebase-ruby/trollop.rb
data/README.md CHANGED
@@ -1,2 +1,60 @@
1
- # firebase-ruby-private
2
- Pure simple Ruby based Firebase REST library
1
+ # firebase-ruby
2
+
3
+ [![Gem Version](https://badge.fury.io/rb/firebase-ruby.svg)](http://badge.fury.io/rb/firebase-ruby) [![Code Climate](https://codeclimate.com/github/kenjij/firebase-ruby/badges/gpa.svg)](https://codeclimate.com/github/kenjij/firebase-ruby) [![security](https://hakiri.io/github/kenjij/firebase-ruby/master.svg)](https://hakiri.io/github/kenjij/firebase-ruby/master)
4
+
5
+ A pure Ruby library for [Firebase Realtime Database](https://firebase.google.com/products/database/) [REST API](https://firebase.google.com/docs/reference/rest/database/) which has only one external dependancy: [jwt](http://jwt.github.io/ruby-jwt/). `firebase-ruby` uses Ruby's built-in Net::HTTP for all HTTP access.
6
+
7
+ ## CLI: fbrb
8
+
9
+ This gem has a built-in command `fbrb` as an example use and for quick testing.
10
+
11
+ ```sh
12
+ fbrb -k privatekey.json /
13
+ ```
14
+
15
+ This will download the entire database in JSON format. By using the private key JSON file provided via Firebase console when creating a service account, necessary information such as project ID, URL, credentials are automatically applied.
16
+
17
+ ## Using In An App
18
+
19
+ ```ruby
20
+ require 'firebase-ruby'
21
+
22
+ # If you want to enable debug logging
23
+ Firebase.logger = Logger.new(STDOUT)
24
+ Firebase.logger.level = Logger::DEBUG
25
+
26
+ db = Firebase::Database.new()
27
+ db.set_auth_with_key(path: path_to_key_file)
28
+ # or alternatively supply the JSON as string
29
+ db.set_auth_with_key(json: json_string)
30
+
31
+ db.get('/users/jack/name')
32
+ #{
33
+ # "first": "Jack",
34
+ # "last": "Sparrow"
35
+ #}
36
+
37
+ db.put('/users/jack/name', {first: "Jack", last: "Sparrow"})
38
+ #{
39
+ # "first": "Jack",
40
+ # "last": "Sparrow"
41
+ #}
42
+
43
+ db.post('/message_list', {user_id: "jack", text: "Ahoy!"})
44
+ #{
45
+ # "name": "-INOQPH-aV_psbk3ZXEX"
46
+ #}
47
+
48
+ db.patch('/users/jack/name', {last: "Jones"})
49
+ #{
50
+ # "last": "Jones"
51
+ #}
52
+
53
+ db.delete('/users/jack/name/last')
54
+ ```
55
+
56
+ ## OAuth 2.0 Access Token
57
+
58
+ Using the given credentials, `firebase-ruby` will automatically retrieve the [access token](https://firebase.google.com/docs/reference/rest/database/user-auth) from Google's server. The token is valid for 1 hour but a new token will be fetched right before it expires.
59
+
60
+ `firebase-ruby` keeps the Google OAuth 2.0 process a black box. But for more details, see the document on Google Developers which the process is based on: [Using OAuth 2.0 for Server to Server Applications](https://developers.google.com/identity/protocols/OAuth2ServiceAccount).
data/bin/fbrb CHANGED
@@ -1,6 +1,7 @@
1
1
  #!/usr/bin/env ruby
2
2
  require 'firebase-ruby/trollop'
3
3
  require 'firebase-ruby'
4
+ require 'json'
4
5
 
5
6
 
6
7
  opts = Trollop::options do
@@ -11,6 +12,7 @@ opts = Trollop::options do
11
12
  opt :log, 'Log file', type: :string
12
13
  opt :path, 'Path', type: :string
13
14
  opt :request, 'Specify request command to use', type: :string, short: 'X', default: 'get'
15
+ opt :ruby, 'Output Ruby format'
14
16
  opt :verbose, 'Verbose mode'
15
17
  end
16
18
 
@@ -48,4 +50,11 @@ when :put, :patch, :post
48
50
  end
49
51
  end
50
52
 
51
- puts data if data
53
+ if data
54
+ if opts[:ruby]
55
+ puts data
56
+ else
57
+ json_opts = {indent: ' ', space: ' ', object_nl: "\n", array_nl: "\n"}
58
+ puts JSON.fast_generate(data, json_opts)
59
+ end
60
+ end
@@ -7,12 +7,15 @@ Gem::Specification.new do |s|
7
7
  s.version = Firebase::Version
8
8
  s.authors = ['Ken J.']
9
9
  s.email = ['kenjij@gmail.com']
10
- s.summary = %q{Pure simple Ruby based Firebase REST library}
11
- s.description = %q{Firebase REST library written in pure Ruby without external dependancy.}
10
+ s.summary = %q{Pure Ruby Firebase REST library}
11
+ s.description = %q{A simple Firebase Realtime Database REST API library in pure Ruby.}
12
12
  s.homepage = 'https://github.com/kenjij/firebase-ruby'
13
13
  s.license = 'MIT'
14
14
 
15
15
  s.files = `git ls-files`.split($/)
16
16
  s.executables = s.files.grep(%r{^bin/}) { |f| File.basename(f) }
17
17
  s.require_paths = ['lib']
18
+
19
+ s.required_ruby_version = '>= 2.0'
20
+ s.add_runtime_dependency 'jwt', '~> 1.5'
18
21
  end
@@ -59,12 +59,9 @@ module Firebase
59
59
  def http
60
60
  unless @http
61
61
  url = FIREBASE_URL_TEMPLATE % project_id
62
- headers = {
63
- 'Authorization' => "Bearer #{auth.valid_token}",
64
- 'Content-Type' => 'application/json'
65
- }
66
- @http = HTTP.new(url, headers)
62
+ @http = HTTP.new(url, {'Content-Type' => 'application/json'})
67
63
  end
64
+ @http.headers['Authorization'] = "Bearer #{auth.valid_token}"
68
65
  return @http
69
66
  end
70
67
 
@@ -1,5 +1,5 @@
1
1
  module Firebase
2
2
 
3
- Version = '0.1.0'
3
+ Version = '0.2.0.1'
4
4
 
5
5
  end
metadata CHANGED
@@ -1,16 +1,30 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: firebase-ruby
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.1.0
4
+ version: 0.2.0.1
5
5
  platform: ruby
6
6
  authors:
7
7
  - Ken J.
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2017-08-05 00:00:00.000000000 Z
12
- dependencies: []
13
- description: Firebase REST library written in pure Ruby without external dependancy.
11
+ date: 2017-08-09 00:00:00.000000000 Z
12
+ dependencies:
13
+ - !ruby/object:Gem::Dependency
14
+ name: jwt
15
+ requirement: !ruby/object:Gem::Requirement
16
+ requirements:
17
+ - - "~>"
18
+ - !ruby/object:Gem::Version
19
+ version: '1.5'
20
+ type: :runtime
21
+ prerelease: false
22
+ version_requirements: !ruby/object:Gem::Requirement
23
+ requirements:
24
+ - - "~>"
25
+ - !ruby/object:Gem::Version
26
+ version: '1.5'
27
+ description: A simple Firebase Realtime Database REST API library in pure Ruby.
14
28
  email:
15
29
  - kenjij@gmail.com
16
30
  executables:
@@ -18,6 +32,7 @@ executables:
18
32
  extensions: []
19
33
  extra_rdoc_files: []
20
34
  files:
35
+ - ".codeclimate.yml"
21
36
  - LICENSE
22
37
  - README.md
23
38
  - bin/fbrb
@@ -41,7 +56,7 @@ required_ruby_version: !ruby/object:Gem::Requirement
41
56
  requirements:
42
57
  - - ">="
43
58
  - !ruby/object:Gem::Version
44
- version: '0'
59
+ version: '2.0'
45
60
  required_rubygems_version: !ruby/object:Gem::Requirement
46
61
  requirements:
47
62
  - - ">="
@@ -49,8 +64,8 @@ required_rubygems_version: !ruby/object:Gem::Requirement
49
64
  version: '0'
50
65
  requirements: []
51
66
  rubyforge_project:
52
- rubygems_version: 2.6.12
67
+ rubygems_version: 2.4.8
53
68
  signing_key:
54
69
  specification_version: 4
55
- summary: Pure simple Ruby based Firebase REST library
70
+ summary: Pure Ruby Firebase REST library
56
71
  test_files: []