Class: Firecord::Repository::Firebase
- Includes:
- HTTParty
- Defined in:
- lib/firecord/repository/firebase.rb
Instance Method Summary collapse
- #all ⇒ Object
- #delete(id) ⇒ Object
- #get(id) ⇒ Object
-
#initialize(root) ⇒ Firebase
constructor
A new instance of Firebase.
- #patch(record) ⇒ Object
- #post(record) ⇒ Object
Constructor Details
#initialize(root) ⇒ Firebase
Returns a new instance of Firebase.
8 9 10 11 12 |
# File 'lib/firecord/repository/firebase.rb', line 8 def initialize(root) @credentials = Credentials.new @root = root self.class.base_uri "https://#{@credentials.project_id}.firebaseio.com/" end |
Instance Method Details
#all ⇒ Object
14 15 16 17 18 19 |
# File 'lib/firecord/repository/firebase.rb', line 14 def all self .class.get("/#{@root}.json", ) .as { |response| Response.new(response).sanitize } .map { |id, data| Response.new(data.merge(id: id)).sanitize } end |
#delete(id) ⇒ Object
39 40 41 42 43 |
# File 'lib/firecord/repository/firebase.rb', line 39 def delete(id) self .class.delete("/#{@root}/#{id}.json", ) .as { |response| response ? false : true } end |
#get(id) ⇒ Object
21 22 23 24 25 |
# File 'lib/firecord/repository/firebase.rb', line 21 def get(id) self .class.get("/#{@root}/#{id}.json", ) .as { |response| Response.new(response, id: id).sanitize_with_nil } end |