firebase 0.2.4 → 0.2.5
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/README.md +16 -3
- data/VERSION +1 -1
- data/firebase.gemspec +3 -4
- data/lib/firebase.rb +20 -15
- data/spec/firebase_spec.rb +12 -9
- metadata +2 -3
- data/lib/firebase/request.rb +0 -38
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 7f4d0e635f2b61323e742ed14dffca10ef4507ea
|
4
|
+
data.tar.gz: feb3f0741ff08578e52d78f5396012c0b0f4ab76
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: b7330bf19b01c9631ca5c181248907a5f4fa8faafe1db2ce85f23eb5c63b5317b41f13a4eca104c58fd8c96534ff5014dc3b86dfa53e45aa0c7fbe86950f382e
|
7
|
+
data.tar.gz: e30401898c34f104c7c4a4b6257f96eb4a6e0e090c64b7488e0eb02f3df2241061d30d73607d7fa4dfdd7b9fc4faa57d28f5e661f301c0a83f84790cbaaa4056
|
data/README.md
CHANGED
@@ -7,12 +7,12 @@ update your clients **in realtime from the backend**.
|
|
7
7
|
|
8
8
|
See a [video demo](https://vimeo.com/41494336?utm_source=internal&utm_medium=email&utm_content=cliptranscoded&utm_campaign=adminclip) of what's possible.
|
9
9
|
|
10
|
-
|
10
|
+
## Installation
|
11
11
|
|
12
12
|
```
|
13
13
|
gem install firebase
|
14
14
|
```
|
15
|
-
|
15
|
+
## Usage
|
16
16
|
|
17
17
|
```ruby
|
18
18
|
base_uri = 'https://<your-firebase>.firebaseio.com/'
|
@@ -58,10 +58,23 @@ delete(path, query_options)
|
|
58
58
|
update(path, data, query_options)
|
59
59
|
```
|
60
60
|
|
61
|
+
### Configuring HTTP options
|
62
|
+
|
63
|
+
[httpclient](https://github.com/nahi/httpclient) is used under the covers to make HTTP requests.
|
64
|
+
You may find yourself wanting to tweak the timeout settings. By default, `httpclient` uses
|
65
|
+
some [sane defaults](https://github.com/nahi/httpclient/blob/dd322d39d4d11c48f7bbbc05ed6273ac912d3e3b/lib/httpclient/session.rb#L138),
|
66
|
+
but it is quite easy to change them by modifying the `request` object directly:
|
67
|
+
|
68
|
+
```ruby
|
69
|
+
firebase = Firebase::Client.new(base_uri)
|
70
|
+
# firebase.request is a regular httpclient object
|
71
|
+
firebase.request.connect_timeout = 30
|
72
|
+
```
|
73
|
+
|
61
74
|
More information about Firebase and the Firebase API is available at the
|
62
75
|
[official website](http://www.firebase.com/).
|
63
76
|
|
64
|
-
|
77
|
+
## Copyright
|
65
78
|
|
66
79
|
Copyright (c) 2013 Oscar Del Ben. See LICENSE.txt for
|
67
80
|
further details.
|
data/VERSION
CHANGED
@@ -1 +1 @@
|
|
1
|
-
0.2.
|
1
|
+
0.2.5
|
data/firebase.gemspec
CHANGED
@@ -2,16 +2,16 @@
|
|
2
2
|
# DO NOT EDIT THIS FILE DIRECTLY
|
3
3
|
# Instead, edit Jeweler::Tasks in Rakefile, and run 'rake gemspec'
|
4
4
|
# -*- encoding: utf-8 -*-
|
5
|
-
# stub: firebase 0.2.
|
5
|
+
# stub: firebase 0.2.5 ruby lib
|
6
6
|
|
7
7
|
Gem::Specification.new do |s|
|
8
8
|
s.name = "firebase"
|
9
|
-
s.version = "0.2.
|
9
|
+
s.version = "0.2.5"
|
10
10
|
|
11
11
|
s.required_rubygems_version = Gem::Requirement.new(">= 0") if s.respond_to? :required_rubygems_version=
|
12
12
|
s.require_paths = ["lib"]
|
13
13
|
s.authors = ["Oscar Del Ben"]
|
14
|
-
s.date = "2015-
|
14
|
+
s.date = "2015-11-18"
|
15
15
|
s.description = "Firebase wrapper for Ruby"
|
16
16
|
s.email = "info@oscardelben.com"
|
17
17
|
s.extra_rdoc_files = [
|
@@ -31,7 +31,6 @@ Gem::Specification.new do |s|
|
|
31
31
|
"VERSION",
|
32
32
|
"firebase.gemspec",
|
33
33
|
"lib/firebase.rb",
|
34
|
-
"lib/firebase/request.rb",
|
35
34
|
"lib/firebase/response.rb",
|
36
35
|
"lib/firebase/server_value.rb",
|
37
36
|
"spec/firebase_spec.rb",
|
data/lib/firebase.rb
CHANGED
@@ -1,7 +1,8 @@
|
|
1
|
-
require 'uri'
|
2
|
-
require 'firebase/request'
|
3
1
|
require 'firebase/response'
|
4
2
|
require 'firebase/server_value'
|
3
|
+
require 'httpclient'
|
4
|
+
require 'json'
|
5
|
+
require 'uri'
|
5
6
|
|
6
7
|
module Firebase
|
7
8
|
class Client
|
@@ -12,47 +13,51 @@ module Firebase
|
|
12
13
|
raise ArgumentError.new('base_uri must be a valid https uri')
|
13
14
|
end
|
14
15
|
base_uri += '/' unless base_uri.end_with?('/')
|
15
|
-
@request =
|
16
|
+
@request = HTTPClient.new({
|
17
|
+
:base_url => base_uri,
|
18
|
+
:default_header => {
|
19
|
+
'Content-Type' => 'application/json'
|
20
|
+
}
|
21
|
+
})
|
16
22
|
@auth = auth
|
17
23
|
end
|
18
24
|
|
19
25
|
# Writes and returns the data
|
20
26
|
# Firebase.set('users/info', { 'name' => 'Oscar' }) => { 'name' => 'Oscar' }
|
21
27
|
def set(path, data, query={})
|
22
|
-
|
28
|
+
process :put, path, data, query
|
23
29
|
end
|
24
30
|
|
25
31
|
# Returns the data at path
|
26
32
|
def get(path, query={})
|
27
|
-
|
33
|
+
process :get, path, query
|
28
34
|
end
|
29
35
|
|
30
36
|
# Writes the data, returns the key name of the data added
|
31
37
|
# Firebase.push('users', { 'age' => 18}) => {"name":"-INOQPH-aV_psbk3ZXEX"}
|
32
38
|
def push(path, data, query={})
|
33
|
-
|
39
|
+
process :post, path, data, query
|
34
40
|
end
|
35
41
|
|
36
42
|
# Deletes the data at path and returs true
|
37
43
|
def delete(path, query={})
|
38
|
-
|
44
|
+
process :delete, path, query
|
39
45
|
end
|
40
46
|
|
41
47
|
# Write the data at path but does not delete ommited children. Returns the data
|
42
48
|
# Firebase.update('users/info', { 'name' => 'Oscar' }) => { 'name' => 'Oscar' }
|
43
49
|
def update(path, data, query={})
|
44
|
-
|
50
|
+
process :patch, path, data, query
|
45
51
|
end
|
46
52
|
|
47
53
|
private
|
48
54
|
|
49
|
-
def
|
50
|
-
|
51
|
-
|
52
|
-
|
53
|
-
|
54
|
-
|
55
|
+
def process(verb, path, data=nil, query={})
|
56
|
+
Firebase::Response.new @request.request(verb, "#{path}.json", {
|
57
|
+
:body => (data && data.to_json),
|
58
|
+
:query => (auth ? { :auth => auth }.merge(query) : query),
|
59
|
+
:follow_redirect => true
|
60
|
+
})
|
55
61
|
end
|
56
62
|
end
|
57
63
|
end
|
58
|
-
|
data/spec/firebase_spec.rb
CHANGED
@@ -17,19 +17,18 @@ describe "Firebase" do
|
|
17
17
|
|
18
18
|
before do
|
19
19
|
@firebase = Firebase::Client.new('https://test.firebaseio.com')
|
20
|
-
@req = @firebase.request
|
21
20
|
end
|
22
21
|
|
23
22
|
describe "set" do
|
24
23
|
it "writes and returns the data" do
|
25
|
-
@
|
24
|
+
@firebase.should_receive(:process).with(:put, 'users/info', data, {})
|
26
25
|
@firebase.set('users/info', data)
|
27
26
|
end
|
28
27
|
end
|
29
28
|
|
30
29
|
describe "get" do
|
31
30
|
it "returns the data" do
|
32
|
-
@
|
31
|
+
@firebase.should_receive(:process).with(:get, 'users/info', {})
|
33
32
|
@firebase.get('users/info')
|
34
33
|
end
|
35
34
|
|
@@ -60,29 +59,33 @@ describe "Firebase" do
|
|
60
59
|
|
61
60
|
describe "push" do
|
62
61
|
it "writes the data" do
|
63
|
-
@
|
62
|
+
@firebase.should_receive(:process).with(:post, 'users', data, {})
|
64
63
|
@firebase.push('users', data)
|
65
64
|
end
|
66
65
|
end
|
67
66
|
|
68
67
|
describe "delete" do
|
69
68
|
it "returns true" do
|
70
|
-
@
|
69
|
+
@firebase.should_receive(:process).with(:delete, 'users/info', {})
|
71
70
|
@firebase.delete('users/info')
|
72
71
|
end
|
73
72
|
end
|
74
73
|
|
75
74
|
describe "update" do
|
76
75
|
it "updates and returns the data" do
|
77
|
-
@
|
76
|
+
@firebase.should_receive(:process).with(:patch, 'users/info', data, {})
|
78
77
|
@firebase.update('users/info', data)
|
79
78
|
end
|
80
79
|
end
|
81
80
|
|
82
|
-
describe "
|
83
|
-
it "
|
81
|
+
describe "http processing" do
|
82
|
+
it "sends custom auth" do
|
84
83
|
firebase = Firebase::Client.new('https://test.firebaseio.com', 'secret')
|
85
|
-
firebase.request.should_receive(:
|
84
|
+
firebase.request.should_receive(:request).with(:get, "todos.json", {
|
85
|
+
:body => {:foo => 'bar'}.to_json,
|
86
|
+
:query => {:auth => "secret"},
|
87
|
+
:follow_redirect => true
|
88
|
+
})
|
86
89
|
firebase.get('todos', :foo => 'bar')
|
87
90
|
end
|
88
91
|
end
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: firebase
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.2.
|
4
|
+
version: 0.2.5
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Oscar Del Ben
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2015-
|
11
|
+
date: 2015-11-18 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: httpclient
|
@@ -86,7 +86,6 @@ files:
|
|
86
86
|
- VERSION
|
87
87
|
- firebase.gemspec
|
88
88
|
- lib/firebase.rb
|
89
|
-
- lib/firebase/request.rb
|
90
89
|
- lib/firebase/response.rb
|
91
90
|
- lib/firebase/server_value.rb
|
92
91
|
- spec/firebase_spec.rb
|
data/lib/firebase/request.rb
DELETED
@@ -1,38 +0,0 @@
|
|
1
|
-
require 'httpclient'
|
2
|
-
require 'json'
|
3
|
-
|
4
|
-
module Firebase
|
5
|
-
class Request
|
6
|
-
def initialize(base_uri)
|
7
|
-
@client = HTTPClient.new(base_url: base_uri)
|
8
|
-
@client.default_header['Content-Type'] = 'application/json'
|
9
|
-
end
|
10
|
-
|
11
|
-
def get(path, query_options)
|
12
|
-
process(:get, path, nil, query_options)
|
13
|
-
end
|
14
|
-
|
15
|
-
def put(path, value, query_options)
|
16
|
-
process(:put, path, value.to_json, query_options)
|
17
|
-
end
|
18
|
-
|
19
|
-
def post(path, value, query_options)
|
20
|
-
process(:post, path, value.to_json, query_options)
|
21
|
-
end
|
22
|
-
|
23
|
-
def delete(path, query_options)
|
24
|
-
process(:delete, path, nil, query_options)
|
25
|
-
end
|
26
|
-
|
27
|
-
def patch(path, value, query_options)
|
28
|
-
process(:patch, path, value.to_json, query_options)
|
29
|
-
end
|
30
|
-
|
31
|
-
private
|
32
|
-
|
33
|
-
def process(method, path, body=nil, query_options={})
|
34
|
-
response = @client.request(method, "#{path}.json", body: body, query: query_options, follow_redirect: true)
|
35
|
-
Firebase::Response.new(response)
|
36
|
-
end
|
37
|
-
end
|
38
|
-
end
|