Class: Submissions

Inherits:
Object
  • Object
show all
Includes:
HTTParty
Defined in:
lib/oxy/firebase/submissions.rb

Class Method Summary collapse

Class Method Details

.drop(email_address = nil) ⇒ Object



35
36
37
38
39
40
41
42
43
44
45
# File 'lib/oxy/firebase/submissions.rb', line 35

def self.drop(email_address = nil)
  # prepare
  path = "/submissions"
  # fabricate lookup key based on MD5
  if email_address
    lookup_key = to_lookup_key(email_address)
    path += "/#{lookup_key}"
  end
  # delete the entry
  delete("#{path}.json", default_options)
end

.find_by(email_address) ⇒ Object



8
9
10
11
12
13
14
15
# File 'lib/oxy/firebase/submissions.rb', line 8

def self.find_by(email_address)
  # fabricate lookup key based on MD5 hash of the email address
  lookup_key = to_lookup_key(email_address)
  # fetch response from Firebase
  response = get("/submissions/#{lookup_key}.json", default_options)
  # parse it into JSON
  parse(response)
end

.find_submission(email_address) ⇒ Object



17
18
19
20
21
22
23
24
# File 'lib/oxy/firebase/submissions.rb', line 17

def self.find_submission(email_address)
  # fabricate lookup key based on MD5 hash of the email address
  lookup_key = to_lookup_key(email_address)
  # fetch response from Firebase
  response = get("/submissions/#{lookup_key}.json", default_options)
  # return response's parsed body
  response.parsed_response
end

.push(submission) ⇒ Object



26
27
28
29
30
31
32
33
# File 'lib/oxy/firebase/submissions.rb', line 26

def self.push(submission)
  # fabricate lookup key based on MD5
  lookup_key = to_lookup_key(submission["email_address"])
  # merge options
  options = default_options.merge(:body => submission.to_json)
  # push the submission entry to Firebase
  put("/submissions/#{lookup_key}.json", options)
end