firebase 0.2.6 → 0.2.7

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: e864ba62615c80fdea3df462d52ff16f0a05581b
4
- data.tar.gz: f92180ed3c2af45cdec10d0c0342a05079727b58
2
+ SHA256:
3
+ metadata.gz: d72f4bd9c17f8c7d7839cbb1defd919299ca5d32b62c44b31c98f877f5e8b8b9
4
+ data.tar.gz: 7b0edc9268116110902f07912f5e2f06830e202a651a375c0b800506c17d64db
5
5
  SHA512:
6
- metadata.gz: 63f404aa8ed4b8f69baebeb5dc3043fd3f7bec1916dd9c1bb51e4690225e7908dad5807a732da525b8b365d2c43467079ff9626e658eb645f911b2e566dcf769
7
- data.tar.gz: 7bdbd22fffb2c1ebb2362db13f2b7e01d13303c56d365e806f8073c8422699024a03fc2da4c2f9c6d283f4242aaca4478eefecc6b9db82d18a1fb3d7aeed32c9
6
+ metadata.gz: b8c9c29aeccf96d90d88ee18448f29b8ea3d2f269d31230ea8ee8851fb4ae6035f9953351fe1cd430b87a7d03e47a8ab6fec6835568add43f6869a2b56a6faf6
7
+ data.tar.gz: 821ec1fa4f8279d908356344146452b3e7515242dc936f4077c412adf5084dda4c077ed9b697a753e43888e353fca70b8e9a329dcdfbe277b0ec9373edd41917
@@ -1,12 +1,16 @@
1
1
  # Changelog
2
2
 
3
+ ## 0.2.7
4
+
5
+ * Support newer Firebase [authentication method](https://github.com/oscardelben/firebase-ruby/pull/81)
6
+
3
7
  ## 0.2.5
4
8
 
5
9
  * [Refactor to remove Request proxy class, expose http client](https://github.com/oscardelben/firebase-ruby/commit/138b1e1461ff33da506b0d7992b42e3544be9cf1)
6
10
 
7
11
  ## 0.2.4
8
12
 
9
- * Add support for server timestamp.
13
+ * Add support for server timestamp.
10
14
 
11
15
  ## 0.2.3
12
16
 
File without changes
data/README.md CHANGED
@@ -1,4 +1,5 @@
1
- # firebase [![Build Status](https://travis-ci.org/oscardelben/firebase-ruby.svg?branch=master)](https://travis-ci.org/oscardelben/firebase-ruby)
1
+ # firebase [![Build Status](https://travis-ci.org/oscardelben/firebase-ruby.svg?branch=master)](https://travis-ci.org/oscardelben/firebase-ruby) [![Gem Version](https://badge.fury.io/rb/firebase.svg)](https://rubygems.org/gems/firebase)
2
+
2
3
 
3
4
  Ruby wrapper for the [Firebase REST API](https://www.firebase.com/docs/rest/api/).
4
5
 
@@ -19,18 +20,21 @@ base_uri = 'https://<your-firebase>.firebaseio.com/'
19
20
 
20
21
  firebase = Firebase::Client.new(base_uri)
21
22
 
22
- response = firebase.push("todos", { :name => 'Pick the milk', :priority => 1 })
23
+ response = firebase.push("todos", { :name => 'Pick the milk', :'.priority' => 1 })
23
24
  response.success? # => true
24
25
  response.code # => 200
25
26
  response.body # => { 'name' => "-INOQPH-aV_psbk3ZXEX" }
26
27
  response.raw_body # => '{"name":"-INOQPH-aV_psbk3ZXEX"}'
27
28
  ```
28
29
 
29
- If you have a read-only namespace, set your secret key as follows:
30
+ 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
+
30
32
  ```ruby
31
- firebase = Firebase::Client.new(base_uri, secret_key)
33
+ # Using Firebase Admin SDK private key
34
+ firebase = Firebase::Client.new(base_uri, private_key_json_string)
32
35
 
33
- response = firebase.push("todos", { :name => 'Pick the milk', :priority => 1 })
36
+ # Using Firebase Database Secret (deprecated)
37
+ firebase = Firebase::Client.new(base_uri, db_secret)
34
38
  ```
35
39
 
36
40
  You can now pass custom query options to firebase:
@@ -48,6 +52,16 @@ response = firebase.push("todos", {
48
52
  })
49
53
  ```
50
54
 
55
+ To update multiple values that are not direct descendants, supply their paths as keys in the payload to update:
56
+
57
+ ```ruby
58
+ # note the empty path string here as the first argument
59
+ firebase.update('', {
60
+ "users/posts/#{postID}" => true,
61
+ "posts/#{postID}" => text
62
+ })
63
+ ```
64
+
51
65
  So far, supported methods are:
52
66
 
53
67
  ```ruby
@@ -1,5 +1,6 @@
1
1
  require 'firebase/response'
2
2
  require 'firebase/server_value'
3
+ require 'googleauth'
3
4
  require 'httpclient'
4
5
  require 'json'
5
6
  require 'uri'
@@ -13,13 +14,22 @@ module Firebase
13
14
  raise ArgumentError.new('base_uri must be a valid https uri')
14
15
  end
15
16
  base_uri += '/' unless base_uri.end_with?('/')
17
+ default_header = {
18
+ 'Content-Type' => 'application/json'
19
+ }
20
+ 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)
25
+ else
26
+ # Using deprecated Database Secret
27
+ @auth = auth
28
+ end
16
29
  @request = HTTPClient.new({
17
30
  :base_url => base_uri,
18
- :default_header => {
19
- 'Content-Type' => 'application/json'
20
- }
31
+ :default_header => default_header
21
32
  })
22
- @auth = auth
23
33
  end
24
34
 
25
35
  # Writes and returns the data
@@ -53,11 +63,23 @@ module Firebase
53
63
  private
54
64
 
55
65
  def process(verb, path, data=nil, query={})
66
+ if path[0] == '/'
67
+ raise(ArgumentError.new("Invalid path: #{path}. Path must be relative"))
68
+ end
56
69
  Firebase::Response.new @request.request(verb, "#{path}.json", {
57
70
  :body => (data && data.to_json),
58
71
  :query => (@auth ? { :auth => @auth }.merge(query) : query),
59
72
  :follow_redirect => true
60
73
  })
61
74
  end
75
+
76
+ def valid_json?(json)
77
+ begin
78
+ JSON.parse(json)
79
+ return true
80
+ rescue JSON::ParserError
81
+ return false
82
+ end
83
+ end
62
84
  end
63
85
  end
File without changes
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: firebase
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.2.6
4
+ version: 0.2.7
5
5
  platform: ruby
6
6
  authors:
7
7
  - Oscar Del Ben
@@ -12,6 +12,20 @@ date: 2015-11-26 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: httpclient
15
+ requirement: !ruby/object:Gem::Requirement
16
+ requirements:
17
+ - - ">="
18
+ - !ruby/object:Gem::Version
19
+ version: 2.5.3
20
+ type: :runtime
21
+ prerelease: false
22
+ version_requirements: !ruby/object:Gem::Requirement
23
+ requirements:
24
+ - - ">="
25
+ - !ruby/object:Gem::Version
26
+ version: 2.5.3
27
+ - !ruby/object:Gem::Dependency
28
+ name: json
15
29
  requirement: !ruby/object:Gem::Requirement
16
30
  requirements:
17
31
  - - ">="
@@ -25,7 +39,7 @@ dependencies:
25
39
  - !ruby/object:Gem::Version
26
40
  version: '0'
27
41
  - !ruby/object:Gem::Dependency
28
- name: json
42
+ name: googleauth
29
43
  requirement: !ruby/object:Gem::Requirement
30
44
  requirements:
31
45
  - - ">="
@@ -89,22 +103,12 @@ extra_rdoc_files:
89
103
  - LICENSE.txt
90
104
  - README.md
91
105
  files:
92
- - ".document"
93
- - ".rspec"
94
- - ".travis.yml"
95
106
  - CHANGELOG.md
96
- - Gemfile
97
- - Gemfile.lock
98
107
  - LICENSE.txt
99
108
  - README.md
100
- - Rakefile
101
- - VERSION
102
- - firebase.gemspec
103
109
  - lib/firebase.rb
104
110
  - lib/firebase/response.rb
105
111
  - lib/firebase/server_value.rb
106
- - spec/firebase_spec.rb
107
- - spec/spec_helper.rb
108
112
  homepage: http://github.com/oscardelben/firebase-ruby
109
113
  licenses:
110
114
  - MIT
@@ -125,7 +129,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
125
129
  version: '0'
126
130
  requirements: []
127
131
  rubyforge_project:
128
- rubygems_version: 2.4.5
132
+ rubygems_version: 2.7.3
129
133
  signing_key:
130
134
  specification_version: 4
131
135
  summary: Firebase wrapper for Ruby
data/.document DELETED
@@ -1,5 +0,0 @@
1
- lib/**/*.rb
2
- bin/*
3
- -
4
- features/**/*.feature
5
- LICENSE.txt
data/.rspec DELETED
@@ -1 +0,0 @@
1
- --color
@@ -1,8 +0,0 @@
1
- sudo: false
2
- language: ruby
3
- rvm:
4
- - "1.8.7"
5
- - "1.9.3"
6
- - "2.1.5"
7
- - "2.2.3"
8
- bundler_args: --without utility
data/Gemfile DELETED
@@ -1,19 +0,0 @@
1
- source "http://rubygems.org"
2
- # Add dependencies required to use your gem here.
3
- # Example:
4
- # gem "activesupport", ">= 2.3.5"
5
-
6
- gem 'httpclient'
7
- gem 'json'
8
-
9
- # Add dependencies to develop your gem here.
10
- # Include everything needed to run rake, tests, features, etc.
11
- group :development do
12
- gem 'rake'
13
- gem 'rdoc'
14
- gem 'rspec'
15
- end
16
-
17
- group :utility do
18
- gem 'jeweler'
19
- end
@@ -1,73 +0,0 @@
1
- GEM
2
- remote: http://rubygems.org/
3
- specs:
4
- addressable (2.3.8)
5
- builder (3.2.2)
6
- descendants_tracker (0.0.4)
7
- thread_safe (~> 0.3, >= 0.3.1)
8
- diff-lcs (1.2.5)
9
- faraday (0.9.2)
10
- multipart-post (>= 1.2, < 3)
11
- git (1.2.9.1)
12
- github_api (0.13.0)
13
- addressable (~> 2.3)
14
- descendants_tracker (~> 0.0.4)
15
- faraday (~> 0.8, < 0.10)
16
- hashie (>= 3.4)
17
- multi_json (>= 1.7.5, < 2.0)
18
- nokogiri (~> 1.6.6)
19
- oauth2
20
- hashie (3.4.3)
21
- highline (1.7.8)
22
- httpclient (2.7.0.1)
23
- jeweler (2.0.1)
24
- builder
25
- bundler (>= 1.0)
26
- git (>= 1.2.5)
27
- github_api
28
- highline (>= 1.6.15)
29
- nokogiri (>= 1.5.10)
30
- rake
31
- rdoc
32
- json (1.8.3)
33
- jwt (1.5.2)
34
- mini_portile (0.6.2)
35
- multi_json (1.11.2)
36
- multi_xml (0.5.5)
37
- multipart-post (2.0.0)
38
- nokogiri (1.6.6.4)
39
- mini_portile (~> 0.6.0)
40
- oauth2 (1.0.0)
41
- faraday (>= 0.8, < 0.10)
42
- jwt (~> 1.0)
43
- multi_json (~> 1.3)
44
- multi_xml (~> 0.5)
45
- rack (~> 1.2)
46
- rack (1.6.4)
47
- rake (10.4.2)
48
- rdoc (4.2.0)
49
- rspec (3.4.0)
50
- rspec-core (~> 3.4.0)
51
- rspec-expectations (~> 3.4.0)
52
- rspec-mocks (~> 3.4.0)
53
- rspec-core (3.4.1)
54
- rspec-support (~> 3.4.0)
55
- rspec-expectations (3.4.0)
56
- diff-lcs (>= 1.2.0, < 2.0)
57
- rspec-support (~> 3.4.0)
58
- rspec-mocks (3.4.0)
59
- diff-lcs (>= 1.2.0, < 2.0)
60
- rspec-support (~> 3.4.0)
61
- rspec-support (3.4.1)
62
- thread_safe (0.3.5)
63
-
64
- PLATFORMS
65
- ruby
66
-
67
- DEPENDENCIES
68
- httpclient
69
- jeweler
70
- json
71
- rake
72
- rdoc
73
- rspec
data/Rakefile DELETED
@@ -1,52 +0,0 @@
1
- # encoding: utf-8
2
-
3
- require 'rubygems'
4
- require 'bundler'
5
- begin
6
- Bundler.setup(:default, :development)
7
- rescue Bundler::BundlerError => e
8
- $stderr.puts e.message
9
- $stderr.puts "Run `bundle install` to install missing gems"
10
- exit e.status_code
11
- end
12
- require 'rake'
13
-
14
- begin
15
- require 'jeweler'
16
- Jeweler::Tasks.new do |gem|
17
- # gem is a Gem::Specification... see http://docs.rubygems.org/read/chapter/20 for more options
18
- gem.name = "firebase"
19
- gem.homepage = "http://github.com/oscardelben/firebase-ruby"
20
- gem.license = "MIT"
21
- gem.summary = %Q{Firebase wrapper for Ruby}
22
- gem.description = %Q{Firebase wrapper for Ruby}
23
- gem.email = "info@oscardelben.com"
24
- gem.authors = ["Oscar Del Ben"]
25
- # dependencies defined in Gemfile
26
- end
27
- Jeweler::RubygemsDotOrgTasks.new
28
- rescue LoadError
29
- end
30
-
31
- require 'rspec/core'
32
- require 'rspec/core/rake_task'
33
- RSpec::Core::RakeTask.new(:spec) do |spec|
34
- spec.pattern = FileList['spec/**/*_spec.rb']
35
- end
36
-
37
- RSpec::Core::RakeTask.new(:rcov) do |spec|
38
- spec.pattern = 'spec/**/*_spec.rb'
39
- spec.rcov = true
40
- end
41
-
42
- task :default => :spec
43
-
44
- require 'rdoc/task'
45
- Rake::RDocTask.new do |rdoc|
46
- version = File.exist?('VERSION') ? File.read('VERSION') : ""
47
-
48
- rdoc.rdoc_dir = 'rdoc'
49
- rdoc.title = "firebase #{version}"
50
- rdoc.rdoc_files.include('README*')
51
- rdoc.rdoc_files.include('lib/**/*.rb')
52
- end
data/VERSION DELETED
@@ -1 +0,0 @@
1
- 0.2.6
@@ -1,69 +0,0 @@
1
- # Generated by jeweler
2
- # DO NOT EDIT THIS FILE DIRECTLY
3
- # Instead, edit Jeweler::Tasks in Rakefile, and run 'rake gemspec'
4
- # -*- encoding: utf-8 -*-
5
- # stub: firebase 0.2.6 ruby lib
6
-
7
- Gem::Specification.new do |s|
8
- s.name = "firebase"
9
- s.version = "0.2.6"
10
-
11
- s.required_rubygems_version = Gem::Requirement.new(">= 0") if s.respond_to? :required_rubygems_version=
12
- s.require_paths = ["lib"]
13
- s.authors = ["Oscar Del Ben"]
14
- s.date = "2015-11-26"
15
- s.description = "Firebase wrapper for Ruby"
16
- s.email = "info@oscardelben.com"
17
- s.extra_rdoc_files = [
18
- "CHANGELOG.md",
19
- "LICENSE.txt",
20
- "README.md"
21
- ]
22
- s.files = [
23
- ".document",
24
- ".rspec",
25
- ".travis.yml",
26
- "CHANGELOG.md",
27
- "Gemfile",
28
- "Gemfile.lock",
29
- "LICENSE.txt",
30
- "README.md",
31
- "Rakefile",
32
- "VERSION",
33
- "firebase.gemspec",
34
- "lib/firebase.rb",
35
- "lib/firebase/response.rb",
36
- "lib/firebase/server_value.rb",
37
- "spec/firebase_spec.rb",
38
- "spec/spec_helper.rb"
39
- ]
40
- s.homepage = "http://github.com/oscardelben/firebase-ruby"
41
- s.licenses = ["MIT"]
42
- s.rubygems_version = "2.4.5"
43
- s.summary = "Firebase wrapper for Ruby"
44
-
45
- if s.respond_to? :specification_version then
46
- s.specification_version = 4
47
-
48
- if Gem::Version.new(Gem::VERSION) >= Gem::Version.new('1.2.0') then
49
- s.add_runtime_dependency(%q<httpclient>, [">= 0"])
50
- s.add_runtime_dependency(%q<json>, [">= 0"])
51
- s.add_development_dependency(%q<rake>, [">= 0"])
52
- s.add_development_dependency(%q<rdoc>, [">= 0"])
53
- s.add_development_dependency(%q<rspec>, [">= 0"])
54
- else
55
- s.add_dependency(%q<httpclient>, [">= 0"])
56
- s.add_dependency(%q<json>, [">= 0"])
57
- s.add_dependency(%q<rake>, [">= 0"])
58
- s.add_dependency(%q<rdoc>, [">= 0"])
59
- s.add_dependency(%q<rspec>, [">= 0"])
60
- end
61
- else
62
- s.add_dependency(%q<httpclient>, [">= 0"])
63
- s.add_dependency(%q<json>, [">= 0"])
64
- s.add_dependency(%q<rake>, [">= 0"])
65
- s.add_dependency(%q<rdoc>, [">= 0"])
66
- s.add_dependency(%q<rspec>, [">= 0"])
67
- end
68
- end
69
-
@@ -1,132 +0,0 @@
1
- require 'spec_helper'
2
-
3
- describe "Firebase" do
4
- let (:data) do
5
- { 'name' => 'Oscar' }
6
- end
7
-
8
- describe "invalid uri" do
9
- it "should raise on http" do
10
- expect{ Firebase::Client.new('http://test.firebaseio.com') }.to raise_error(ArgumentError)
11
- end
12
-
13
- it 'should raise on empty' do
14
- expect{ Firebase::Client.new('') }.to raise_error(ArgumentError)
15
- end
16
- end
17
-
18
- before do
19
- @firebase = Firebase::Client.new('https://test.firebaseio.com')
20
- end
21
-
22
- describe "set" do
23
- it "writes and returns the data" do
24
- expect(@firebase).to receive(:process).with(:put, 'users/info', data, {})
25
- @firebase.set('users/info', data)
26
- end
27
- end
28
-
29
- describe "get" do
30
- it "returns the data" do
31
- expect(@firebase).to receive(:process).with(:get, 'users/info', nil, {})
32
- @firebase.get('users/info')
33
- end
34
-
35
- it "correctly passes custom ordering params" do
36
- params = {
37
- :orderBy => '"$key"',
38
- :startAt => '"A1"'
39
- }
40
- expect(@firebase).to receive(:process).with(:get, 'users/info', nil, params)
41
- @firebase.get('users/info', params)
42
- end
43
-
44
- it "works when run against real Firebase dataset" do
45
- firebase = Firebase::Client.new 'https://dinosaur-facts.firebaseio.com'
46
- response = firebase.get 'dinosaurs', :orderBy => '"$key"', :startAt => '"a"', :endAt => '"m"'
47
- expect(response.body).to eq({
48
- "bruhathkayosaurus" => {
49
- "appeared" => -70000000,
50
- "height" => 25,
51
- "length" => 44,
52
- "order" => "saurischia",
53
- "vanished" => -70000000,
54
- "weight" => 135000
55
- },
56
- "lambeosaurus" => {
57
- "appeared" => -76000000,
58
- "height" => 2.1,
59
- "length" => 12.5,
60
- "order" => "ornithischia",
61
- "vanished" => -75000000,
62
- "weight" => 5000
63
- },
64
- "linhenykus" => {
65
- "appeared" => -85000000,
66
- "height" => 0.6,
67
- "length" => 1,
68
- "order" => "theropoda",
69
- "vanished" => -75000000,
70
- "weight" => 3
71
- }
72
- })
73
- end
74
-
75
- it "return nil if response body contains 'null'" do
76
- mock_response = double(:body => 'null')
77
- response = Firebase::Response.new(mock_response)
78
- expect { response.body }.to_not raise_error
79
- end
80
-
81
- it "return true if response body contains 'true'" do
82
- mock_response = double(:body => 'true')
83
- response = Firebase::Response.new(mock_response)
84
- expect(response.body).to eq(true)
85
- end
86
-
87
- it "return false if response body contains 'false'" do
88
- mock_response = double(:body => 'false')
89
- response = Firebase::Response.new(mock_response)
90
- expect(response.body).to eq(false)
91
- end
92
-
93
- it "raises JSON::ParserError if response body contains invalid JSON" do
94
- mock_response = double(:body => '{"this is wrong"')
95
- response = Firebase::Response.new(mock_response)
96
- expect { response.body }.to raise_error(JSON::ParserError)
97
- end
98
- end
99
-
100
- describe "push" do
101
- it "writes the data" do
102
- expect(@firebase).to receive(:process).with(:post, 'users', data, {})
103
- @firebase.push('users', data)
104
- end
105
- end
106
-
107
- describe "delete" do
108
- it "returns true" do
109
- expect(@firebase).to receive(:process).with(:delete, 'users/info', nil, {})
110
- @firebase.delete('users/info')
111
- end
112
- end
113
-
114
- describe "update" do
115
- it "updates and returns the data" do
116
- expect(@firebase).to receive(:process).with(:patch, 'users/info', data, {})
117
- @firebase.update('users/info', data)
118
- end
119
- end
120
-
121
- describe "http processing" do
122
- it "sends custom auth" do
123
- firebase = Firebase::Client.new('https://test.firebaseio.com', 'secret')
124
- expect(firebase.request).to receive(:request).with(:get, "todos.json", {
125
- :body => nil,
126
- :query => {:auth => "secret", :foo => 'bar'},
127
- :follow_redirect => true
128
- })
129
- firebase.get('todos', :foo => 'bar')
130
- end
131
- end
132
- end
@@ -1,12 +0,0 @@
1
- $LOAD_PATH.unshift(File.join(File.dirname(__FILE__), '..', 'lib'))
2
- $LOAD_PATH.unshift(File.dirname(__FILE__))
3
- require 'rspec'
4
- require 'firebase'
5
-
6
- # Requires supporting files with custom matchers and macros, etc,
7
- # in ./support/ and its subdirectories.
8
- Dir["#{File.dirname(__FILE__)}/support/**/*.rb"].each {|f| require f}
9
-
10
- RSpec.configure do |config|
11
-
12
- end