Class: BupBupRB::Resource::Notification

Inherits:
Object
  • Object
show all
Defined in:
lib/bup_bup_rb/resources/notification.rb

Class Method Summary collapse

Class Method Details

.send(ids, message) ⇒ Object

Raises:



4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
# File 'lib/bup_bup_rb/resources/notification.rb', line 4

def self.send(ids, message)
  timestamp = Time.now.getutc.to_i
  signature = Digest::MD5.hexdigest("#{ timestamp }-#{ config.app_secret }")

  response = connection.post do |req|
    req.url '/api/notifications'
    req.body = '{ "device_ids": ids, "message": message }'
    req.headers['Content-Type'] = 'application/json'
    req.headers['Authorization-Signature'] = signature
    req.headers['Authorization-App-Id'] = config.app_id
    req.headers['Authorization-Timestamp'] = timestamp.to_s
  end
  result = JSON.parse(response.body)

  return result["status"] if result["status"]
  raise BupbupError, result["message"]
end