Created
November 26, 2018 11:30
-
-
Save scalone/4ae90b104a0783d22c5fdcd35c3f07a5 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
TOKEN="" | |
class Notification | |
def self.create(serial_number) | |
loop do | |
begin | |
puts "SEND NOTIFICATION [#{serial_number}]" | |
payload = {"content" => "APP_UPDATE", "range" => "specific_logical_numbers", "group_id" => 2001, "logical_numbers" => serial_number, "kind" => "processing"} | |
uri = URI("https://api.cloudwalk.io/v1/notifications?access_token=#{TOKEN}") | |
http = Net::HTTP.new(uri.host, uri.port) | |
http.use_ssl = true | |
request = Net::HTTP::Post.new(uri.request_uri) | |
request.body = payload.to_json | |
res = http.request(request) | |
case res.code.to_i | |
when 200, 201, 202 | |
break(res.body) | |
when 429, 503 | |
sleep 60 | |
next | |
else | |
raise "Error to post notification #{serial_number} response code [#{res.code}] body [#{res.body}] message [#{res.message}]" | |
nil | |
end | |
rescue SocketError | |
"SocketError - Error to create notification #{serial_number}" | |
end | |
end | |
end | |
end | |
Notification.create("SERIAL NUMBER") |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment