class Notifications::Uploader

Public Class Methods

call(origin: nil, destination:, text:, link:, created_at: Time.now) click to toggle source
# File lib/notifications/uploader.rb, line 10
def call(origin: nil, destination:, text:, link:, created_at: Time.now)
  message = JSON.generate(
    origin:     origin,
    text:       text,
    link:       link,
    read_at:    false,
    created_at: created_at.to_datetime.to_i
  )

  connection = Faraday.new(url: firebase_host)

  connection.post do |req|
    req.url "/notifications/#{destination}.json"
    req.headers['Content-Type'] = 'application/json'
    req.body = message
  end
end

Private Class Methods

firebase_host() click to toggle source
# File lib/notifications/uploader.rb, line 30
def firebase_host
  project_id = Notifications.configuration.firebase_project_id

  "https://#{project_id}.firebaseio.com"
end