firebase 0.2.7 → 0.2.8

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 CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: d72f4bd9c17f8c7d7839cbb1defd919299ca5d32b62c44b31c98f877f5e8b8b9
4
- data.tar.gz: 7b0edc9268116110902f07912f5e2f06830e202a651a375c0b800506c17d64db
3
+ metadata.gz: 49b70b598dec94254a0bbc0891a4d487bdf7e5ad8f21a492caee067eb666ee40
4
+ data.tar.gz: c85fdf4c54950027cfaa78d7241e2b6917a8db254cb333eeed401530595b721f
5
5
  SHA512:
6
- metadata.gz: b8c9c29aeccf96d90d88ee18448f29b8ea3d2f269d31230ea8ee8851fb4ae6035f9953351fe1cd430b87a7d03e47a8ab6fec6835568add43f6869a2b56a6faf6
7
- data.tar.gz: 821ec1fa4f8279d908356344146452b3e7515242dc936f4077c412adf5084dda4c077ed9b697a753e43888e353fca70b8e9a329dcdfbe277b0ec9373edd41917
6
+ metadata.gz: 3e254898a633f18cc5c17b47dd2a54df63476359bcd1e628c5da5416d7de3a840c1965019856737a2e039b8e7f4bde9b6b495bbfd0c968bbe7ace6182462de11
7
+ data.tar.gz: ec683cadd0d79f95c10036ed2e8088a5856abceaf79716639c2b074ee7017412947c333947cebe806c22365d092f894fc1a10fe6d8a48c6d3b2e5c12fa4d3caa
data/README.md CHANGED
@@ -27,16 +27,25 @@ response.body # => { 'name' => "-INOQPH-aV_psbk3ZXEX" }
27
27
  response.raw_body # => '{"name":"-INOQPH-aV_psbk3ZXEX"}'
28
28
  ```
29
29
 
30
+ ### Authentication
30
31
  If you have a read-only namespace, you need to authenticate your Firebase client. `firebase-ruby` will attempt to determine if you are using the old or new [authentication method](https://firebase.google.com/docs/database/rest/auth) by whether your auth string is a valid JSON string or not.
31
32
 
33
+ #### Using Firebase Database Secret (deprecated)
34
+ ```
35
+ # Using Firebase Database Secret (deprecated)
36
+ firebase = Firebase::Client.new(base_uri, db_secret)
37
+ ```
38
+
39
+ #### Using Firebase Admin SDK private key
40
+ Go to the Firebase console and under `Project Settings` -> `Service Accounts` -> `Firebase Admin SDK` click on `GENERATE NEW PRIVATE KEY`. Save the json file and use it like this:
41
+
32
42
  ```ruby
33
43
  # Using Firebase Admin SDK private key
44
+ private_key_json_string = File.open('/path/to/your/generated/json').read
34
45
  firebase = Firebase::Client.new(base_uri, private_key_json_string)
35
-
36
- # Using Firebase Database Secret (deprecated)
37
- firebase = Firebase::Client.new(base_uri, db_secret)
38
46
  ```
39
47
 
48
+
40
49
  You can now pass custom query options to firebase:
41
50
 
42
51
  ```ruby
@@ -14,22 +14,24 @@ module Firebase
14
14
  raise ArgumentError.new('base_uri must be a valid https uri')
15
15
  end
16
16
  base_uri += '/' unless base_uri.end_with?('/')
17
- default_header = {
18
- 'Content-Type' => 'application/json'
19
- }
17
+ @request = HTTPClient.new({
18
+ :base_url => base_uri,
19
+ :default_header => {
20
+ 'Content-Type' => 'application/json'
21
+ }
22
+ })
20
23
  if auth && valid_json?(auth)
21
- # Using Admin SDK private key
22
- scopes = %w(https://www.googleapis.com/auth/firebase.database https://www.googleapis.com/auth/userinfo.email)
23
- credentials = Google::Auth::DefaultCredentials.make_creds(json_key_io: StringIO.new(auth), scope: scopes)
24
- default_header = credentials.apply(default_header)
24
+ # Using Admin SDK service account
25
+ @credentials = Google::Auth::DefaultCredentials.make_creds(
26
+ json_key_io: StringIO.new(auth),
27
+ scope: %w(https://www.googleapis.com/auth/firebase.database https://www.googleapis.com/auth/userinfo.email)
28
+ )
29
+ @credentials.apply!(@request.default_header)
30
+ @expires_at = @credentials.issued_at + 0.95 * @credentials.expires_in
25
31
  else
26
32
  # Using deprecated Database Secret
27
- @auth = auth
33
+ @secret = auth
28
34
  end
29
- @request = HTTPClient.new({
30
- :base_url => base_uri,
31
- :default_header => default_header
32
- })
33
35
  end
34
36
 
35
37
  # Writes and returns the data
@@ -66,9 +68,16 @@ module Firebase
66
68
  if path[0] == '/'
67
69
  raise(ArgumentError.new("Invalid path: #{path}. Path must be relative"))
68
70
  end
71
+
72
+ if @expires_at && Time.now > @expires_at
73
+ @credentials.refresh!
74
+ @credentials.apply! @request.default_header
75
+ @expires_at = @credentials.issued_at + 0.95 * @credentials.expires_in
76
+ end
77
+
69
78
  Firebase::Response.new @request.request(verb, "#{path}.json", {
70
79
  :body => (data && data.to_json),
71
- :query => (@auth ? { :auth => @auth }.merge(query) : query),
80
+ :query => (@secret ? { :auth => @secret }.merge(query) : query),
72
81
  :follow_redirect => true
73
82
  })
74
83
  end
@@ -0,0 +1,3 @@
1
+ module Firebase
2
+ VERSION = '0.2.8'.freeze
3
+ end
metadata CHANGED
@@ -1,14 +1,15 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: firebase
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.2.7
4
+ version: 0.2.8
5
5
  platform: ruby
6
6
  authors:
7
7
  - Oscar Del Ben
8
+ - Vincent Woo
8
9
  autorequire:
9
10
  bindir: bin
10
11
  cert_chain: []
11
- date: 2015-11-26 00:00:00.000000000 Z
12
+ date: 2018-01-28 00:00:00.000000000 Z
12
13
  dependencies:
13
14
  - !ruby/object:Gem::Dependency
14
15
  name: httpclient
@@ -109,6 +110,7 @@ files:
109
110
  - lib/firebase.rb
110
111
  - lib/firebase/response.rb
111
112
  - lib/firebase/server_value.rb
113
+ - lib/firebase/version.rb
112
114
  homepage: http://github.com/oscardelben/firebase-ruby
113
115
  licenses:
114
116
  - MIT