Class: Firebase::Client

Inherits:
Object
  • Object
show all
Defined in:
lib/firebase.rb

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(base_uri, auth = nil) ⇒ Client

Returns a new instance of Client.



15
16
17
18
19
# File 'lib/firebase.rb', line 15

def initialize(base_uri, auth=nil)
  uri = Firebase::Client.format_uri(base_uri)
  @request = Firebase::Request.new(uri)
  @auth = auth
end

Instance Attribute Details

#authObject (readonly)

Returns the value of attribute auth.



13
14
15
# File 'lib/firebase.rb', line 13

def auth
  @auth
end

#requestObject (readonly)

Returns the value of attribute request.



13
14
15
# File 'lib/firebase.rb', line 13

def request
  @request
end

Class Method Details

.format_uri(other) ⇒ Object



7
8
9
10
11
# File 'lib/firebase.rb', line 7

def self.format_uri(other)
  if other
    other.end_with?("/") ? other : other + '/'
  end
end

Instance Method Details

#delete(path, query = {}) ⇒ Object

Deletes the data at path and returs true



39
40
41
# File 'lib/firebase.rb', line 39

def delete(path, query={})
  request.delete(path, query_options(query))
end

#get(path, query = {}) ⇒ Object

Returns the data at path



28
29
30
# File 'lib/firebase.rb', line 28

def get(path, query={})
  request.get(path, query_options(query))
end

#push(path, data, query = {}) ⇒ Object

Writes the data, returns the key name of the data added

Firebase.push('users', { 'age' => 18}) => {"name":"-INOQPH-aV_psbk3ZXEX"}


34
35
36
# File 'lib/firebase.rb', line 34

def push(path, data, query={})
  request.post(path, data, query_options(query))
end

#set(path, data, query = {}) ⇒ Object

Writes and returns the data

Firebase.set('users/info', { 'name' => 'Oscar' }) => { 'name' => 'Oscar' }


23
24
25
# File 'lib/firebase.rb', line 23

def set(path, data, query={})
  request.put(path, data, query_options(query))
end

#update(path, data, query = {}) ⇒ Object

Write the data at path but does not delete ommited children. Returns the data

Firebase.update('users/info', { 'name' => 'Oscar' }) => { 'name' => 'Oscar' }


45
46
47
# File 'lib/firebase.rb', line 45

def update(path, data, query={})
  request.patch(path, data, query_options(query))
end