forked from botanio/sdk
-
Notifications
You must be signed in to change notification settings - Fork 0
/
botan.rb
31 lines (27 loc) · 787 Bytes
/
botan.rb
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
#usage example:
#
#require_relative 'botan'
#
#puts Botan.track(1111, 1, {'text' => 2}, 'Search')
module Botan
require 'net/http'
require 'net/https'
require 'json'
URI_TEMPLATE = 'https://api.botan.io/track?token=%{token}&uid=%{uid}&name=%{name}';
def self.track(token, uid, message, name = 'Message')
begin
uri = URI(URI_TEMPLATE % {token: token, uid: uid, name: name})
puts uri
http = Net::HTTP.new(uri.host, uri.port)
body = JSON.dump(message)
req = Net::HTTP::Post.new(uri)
req.add_field "Content-type", "application/json"
req.body = body
# Fetch Request
res = http.request(req)
return JSON.parse(res.body)
rescue StandardError => e
puts "HTTP Request failed (#{e.message})"
end
end
end