Class: Firebase::Client
- Inherits:
-
Object
- Object
- Firebase::Client
- Defined in:
- lib/firebase.rb
Instance Attribute Summary collapse
-
#auth ⇒ Object
readonly
Returns the value of attribute auth.
-
#request ⇒ Object
readonly
Returns the value of attribute request.
Instance Method Summary collapse
-
#delete(path, query = {}) ⇒ Object
Deletes the data at path and returs true.
-
#get(path, query = {}) ⇒ Object
Returns the data at path.
-
#initialize(base_uri, auth = nil) ⇒ Client
constructor
A new instance of Client.
-
#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”.
-
#set(path, data, query = {}) ⇒ Object
Writes and returns the data Firebase.set(‘users/info’, { ‘name’ => ‘Oscar’ }) => { ‘name’ => ‘Oscar’ }.
-
#update(path, data, query = {}) ⇒ Object
Write the data at path but does not delete ommited children.
Constructor Details
#initialize(base_uri, auth = nil) ⇒ Client
Returns a new instance of Client.
11 12 13 14 15 16 17 18 19 20 21 22 23 |
# File 'lib/firebase.rb', line 11 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 = HTTPClient.new({ :base_url => base_uri, :default_header => { 'Content-Type' => 'application/json' } }) @auth = auth end |
Instance Attribute Details
#auth ⇒ Object (readonly)
Returns the value of attribute auth.
9 10 11 |
# File 'lib/firebase.rb', line 9 def auth @auth end |
#request ⇒ Object (readonly)
Returns the value of attribute request.
9 10 11 |
# File 'lib/firebase.rb', line 9 def request @request end |
Instance Method Details
#delete(path, query = {}) ⇒ Object
Deletes the data at path and returs true
43 44 45 |
# File 'lib/firebase.rb', line 43 def delete(path, query={}) process :delete, path, nil, query end |
#get(path, query = {}) ⇒ Object
Returns the data at path
32 33 34 |
# File 'lib/firebase.rb', line 32 def get(path, query={}) process :get, path, nil, 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"}
38 39 40 |
# File 'lib/firebase.rb', line 38 def push(path, data, query={}) process :post, path, data, query end |
#set(path, data, query = {}) ⇒ Object
Writes and returns the data
Firebase.set('users/info', { 'name' => 'Oscar' }) => { 'name' => 'Oscar' }
27 28 29 |
# File 'lib/firebase.rb', line 27 def set(path, data, query={}) process :put, path, data, 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' }
49 50 51 |
# File 'lib/firebase.rb', line 49 def update(path, data, query={}) process :patch, path, data, query end |