Class: Firefighter::RealtimeDatabase

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

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(api_key:, db_name:, db_secret:, logger: Logger.new(STDOUT)) ⇒ RealtimeDatabase

Returns a new instance of RealtimeDatabase.



16
17
18
19
20
21
# File 'lib/firefighter/realtime_database.rb', line 16

def initialize(api_key:, db_name:, db_secret:, logger: Logger.new(STDOUT))
  @api_key = api_key
  @db_name = db_name
  @db_secret = db_secret
  @logger = logger
end

Class Method Details

.from_envObject



7
8
9
10
11
12
13
14
# File 'lib/firefighter/realtime_database.rb', line 7

def self.from_env
  config = {
    api_key: ENV['FIREBASE_WEB_API_KEY'],
    db_name: ENV['FIREBASE_WEB_DB_NAME'],
    db_secret: ENV['FIREBASE_WEB_DB_SECRET']
  }
  new(config)
end

Instance Method Details

#add(path, data) ⇒ Object



38
39
40
41
# File 'lib/firefighter/realtime_database.rb', line 38

def add(path, data)
  url = endpoint(path)
  call(:post, url, data)
end

#read(path) ⇒ Object



43
44
45
46
# File 'lib/firefighter/realtime_database.rb', line 43

def read(path)
  url = endpoint(path)
  get(url)
end

#signup(email, password) ⇒ Object



23
24
25
26
27
28
29
30
31
# File 'lib/firefighter/realtime_database.rb', line 23

def (email, password)
  url = "https://www.googleapis.com/identitytoolkit/v3/relyingparty/signupNewUser?key=#{@api_key}"
  data = {
    email: email,
    password: password,
    returnSecureToken: true
  }
  call(:post, url, data)
end

#write(path, data) ⇒ Object



33
34
35
36
# File 'lib/firefighter/realtime_database.rb', line 33

def write(path, data)
  url = endpoint(path)
  call(:put, url, data)
end