firebase 0.1.1 → 0.1.2

Sign up to get free protection for your applications and to get access to all the features.
data/README.md CHANGED
@@ -27,6 +27,15 @@ response.body # => { 'name' => "-INOQPH-aV_psbk3ZXEX" }
27
27
  response.raw_body # => '{"name":"-INOQPH-aV_psbk3ZXEX"}'
28
28
  ```
29
29
 
30
+ If you have a read-only namespace, set your secret key as follows:
31
+ ```ruby
32
+ Firebase.base_uri = 'http://gamma.firebase.com/youruser'
33
+ Firebase.auth = 'yoursecretkey'
34
+
35
+ response = Firebase.push("todos", { :name => 'Pick the milk', :priority => 1 })
36
+ ```
37
+
38
+
30
39
  So far, supported methods are:
31
40
 
32
41
  ```ruby
data/VERSION CHANGED
@@ -1 +1 @@
1
- 0.1.1
1
+ 0.1.2
@@ -5,11 +5,11 @@
5
5
 
6
6
  Gem::Specification.new do |s|
7
7
  s.name = "firebase"
8
- s.version = "0.1.1"
8
+ s.version = "0.1.2"
9
9
 
10
10
  s.required_rubygems_version = Gem::Requirement.new(">= 0") if s.respond_to? :required_rubygems_version=
11
11
  s.authors = ["Oscar Del Ben"]
12
- s.date = "2012-08-06"
12
+ s.date = "2013-02-02"
13
13
  s.description = "Firebase wrapper for Ruby"
14
14
  s.email = "info@oscardelben.com"
15
15
  s.extra_rdoc_files = [
@@ -28,6 +28,7 @@ Gem::Specification.new do |s|
28
28
  "firebase.gemspec",
29
29
  "lib/firebase.rb",
30
30
  "lib/firebase/request.rb",
31
+ "spec/firebase_request_spec.rb",
31
32
  "spec/firebase_spec.rb",
32
33
  "spec/spec_helper.rb"
33
34
  ]
@@ -4,13 +4,19 @@ module Firebase
4
4
  autoload :Request, 'firebase/request'
5
5
 
6
6
  class << self
7
- attr_accessor :base_uri
7
+ attr_accessor :base_uri, :auth
8
8
 
9
9
  def base_uri=(other)
10
- other = other + "/" if other[-1] != "/"
10
+ if other # Guard from nil
11
+ other = other + "/" if other[-1] != "/"
12
+ end
11
13
  @base_uri = other
12
14
  end
13
15
 
16
+ def auth=(auth)
17
+ @auth = auth
18
+ end
19
+
14
20
  # Writes and returns the data
15
21
  # Firebase.set('users/info', { 'name' => 'Oscar' }) => { 'name' => 'Oscar' }
16
22
  def set(path, data)
@@ -1,5 +1,7 @@
1
1
  require 'typhoeus'
2
2
  require 'json'
3
+ require 'open-uri'
4
+ require 'uri'
3
5
 
4
6
  module Firebase
5
7
  class Request
@@ -22,15 +24,21 @@ module Firebase
22
24
  process(:delete, path)
23
25
  end
24
26
 
27
+ def build_url(path)
28
+ host = Firebase.base_uri
29
+ path = "#{path}.json"
30
+ query_string = Firebase.auth ? "?auth=#{Firebase.auth}" : ""
31
+ url = URI.join(Firebase.base_uri, path, query_string)
32
+
33
+ url.to_s
34
+ end
35
+
25
36
  private
26
37
 
27
38
  def process(method, path, options={})
28
39
  raise "Please set Firebase.base_uri before making requests" unless Firebase.base_uri
29
40
 
30
- url = URI.join(Firebase.base_uri, path)
31
- url = [url, '.json'].compact.join
32
-
33
- request = Typhoeus::Request.new(url.to_s,
41
+ request = Typhoeus::Request.new(build_url(path),
34
42
  :body => options[:body],
35
43
  :method => method)
36
44
  hydra = Typhoeus::Hydra.new
@@ -0,0 +1,32 @@
1
+ require 'spec_helper'
2
+
3
+ describe "Firebase Request" do
4
+
5
+ after do
6
+ Firebase.base_uri = nil
7
+ end
8
+
9
+ describe "url_builder" do
10
+ it "should build the correct url when passed no path" do
11
+ Firebase.base_uri = 'https://test.firebaseio.com'
12
+ Firebase::Request.build_url(nil).should == 'https://test.firebaseio.com/.json'
13
+ end
14
+ end
15
+
16
+ describe "url_builder" do
17
+ it "should build the correct url when passed a path" do
18
+ Firebase.base_uri = 'https://test.firebaseio.com'
19
+
20
+ Firebase::Request.build_url('users/eugene').should == 'https://test.firebaseio.com/users/eugene.json'
21
+ end
22
+ end
23
+
24
+ describe "url_builder" do
25
+ it "should include a auth in the query string, if configured" do
26
+ Firebase.base_uri = 'https://test.firebaseio.com'
27
+ Firebase.auth = 'secretkey'
28
+
29
+ Firebase::Request.build_url('users/eugene').should == 'https://test.firebaseio.com/users/eugene.json?auth=secretkey'
30
+ end
31
+ end
32
+ end
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.1.1
4
+ version: 0.1.2
5
5
  prerelease:
6
6
  platform: ruby
7
7
  authors:
@@ -9,7 +9,7 @@ authors:
9
9
  autorequire:
10
10
  bindir: bin
11
11
  cert_chain: []
12
- date: 2012-08-06 00:00:00.000000000 Z
12
+ date: 2013-02-02 00:00:00.000000000 Z
13
13
  dependencies:
14
14
  - !ruby/object:Gem::Dependency
15
15
  name: typhoeus
@@ -94,6 +94,7 @@ files:
94
94
  - firebase.gemspec
95
95
  - lib/firebase.rb
96
96
  - lib/firebase/request.rb
97
+ - spec/firebase_request_spec.rb
97
98
  - spec/firebase_spec.rb
98
99
  - spec/spec_helper.rb
99
100
  homepage: http://github.com/oscardelben/firebase-ruby
@@ -111,7 +112,7 @@ required_ruby_version: !ruby/object:Gem::Requirement
111
112
  version: '0'
112
113
  segments:
113
114
  - 0
114
- hash: -4237307739577820133
115
+ hash: -3657937325613634651
115
116
  required_rubygems_version: !ruby/object:Gem::Requirement
116
117
  none: false
117
118
  requirements: