Class: Firebase::Client

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

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(base_uri, auth = nil) ⇒ Client

Returns a new instance of Client.



9
10
11
12
13
14
15
16
# File 'lib/firebase.rb', line 9

def initialize(base_uri, auth=nil)
  if base_uri !~ URI::regexp(%w(https))
    raise ArgumentError.new('base_uri must be a valid https uri')
  end
  base_uri += '/' unless base_uri.end_with?('/')
  @request = Firebase::Request.new(base_uri)
  @auth = auth
end

Instance Attribute Details

#authObject (readonly)

Returns the value of attribute auth.



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

def auth
  @auth
end

#requestObject (readonly)

Returns the value of attribute request.



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

def request
  @request
end

Instance Method Details

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

Deletes the data at path and returs true



36
37
38
# File 'lib/firebase.rb', line 36

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

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

Returns the data at path



25
26
27
# File 'lib/firebase.rb', line 25

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"}


31
32
33
# File 'lib/firebase.rb', line 31

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' }


20
21
22
# File 'lib/firebase.rb', line 20

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' }


42
43
44
# File 'lib/firebase.rb', line 42

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