Class: Firecord::Repository::Firebase

Inherits:
Object
  • Object
show all
Includes:
HTTParty
Defined in:
lib/firecord/repository/firebase.rb

Instance Method Summary collapse

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

#allObject



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

def all
  self
    .class.get("/#{@root}.json", options)
    .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", options)
    .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", options)
    .as { |response| Response.new(response, id: id).sanitize_with_nil }
end

#patch(record) ⇒ Object



33
34
35
36
37
# File 'lib/firecord/repository/firebase.rb', line 33

def patch(record)
  self
    .class.patch("/#{@root}/#{record.id}.json", payload(record))
    .as { |response| Response.new(response).sanitize }
end

#post(record) ⇒ Object



27
28
29
30
31
# File 'lib/firecord/repository/firebase.rb', line 27

def post(record)
  self
    .class.post("/#{@root}.json", payload(record))
    .as { |response| Response.new(response).sanitize }
end