class Firecord::Repository::Firebase
Public Class Methods
new(root)
click to toggle source
# 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
Public Instance Methods
all()
click to toggle source
# 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)
click to toggle source
# 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)
click to toggle source
# 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)
click to toggle source
# 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)
click to toggle source
# 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
Private Instance Methods
body(record)
click to toggle source
# File lib/firecord/repository/firebase.rb, line 53 def body(record) record.fields.each_with_object({}) do |field, data| next if field.type == :private_key data[field.name] = record.send(field.name) end end
options()
click to toggle source
# File lib/firecord/repository/firebase.rb, line 61 def options { headers: { 'Authorization' => "Bearer #{@credentials.generate_access_token}", 'Content-Type' => 'application/json', 'User-Agent' => 'X-FIREBASE-CLIENT' } } end
payload(record)
click to toggle source
# File lib/firecord/repository/firebase.rb, line 47 def payload(record) options.dup.tap do |data| data[:body] = body(record).to_json end end