class Submissions
Public Class Methods
drop(email_address = nil)
click to toggle source
# 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)
click to toggle source
# 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)
click to toggle source
# 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)
click to toggle source
# 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
Private Class Methods
default_options()
click to toggle source
# File lib/oxy/firebase/submissions.rb, line 59 def self.default_options { :base_uri => ENV["FIREBASE_URL"], :query => { :auth => ENV["FIREBASE_SECRET"] }, :headers => { "Content-Type" => "application/json" } } end
parse(response)
click to toggle source
# File lib/oxy/firebase/submissions.rb, line 48 def self.parse(response) # yield nil if response is not parseable return nil unless response && response.parsed_response # parse it from JSON JSON.parse(response.body, { :object_class => Submission }) end
to_lookup_key(email_address)
click to toggle source
# File lib/oxy/firebase/submissions.rb, line 55 def self.to_lookup_key(email_address) Digest::MD5.hexdigest(email_address) end