Class: Notifications::Uploader

Inherits:
Object
  • Object
show all
Defined in:
lib/notifications/uploader.rb

Class Method Summary collapse

Class Method Details

.call(origin: nil, destination:, text:, link:, created_at: Time.now) ⇒ Object



10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
# 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