Sha256: d0e2ce1d71b3885fb9ccc65c646cc03275c59a702b6b5683c01d5b4452ff4c0f
Contents?: true
Size: 1.46 KB
Versions: 5
Compression:
Stored size: 1.46 KB
Contents
module Telegram module Bot class Botan TRACK_URI = 'https://api.botan.io/track'.freeze autoload :ClientHelpers, 'telegram/bot/botan/client_helpers' autoload :ControllerHelpers, 'telegram/bot/botan/controller_helpers' class Error < Bot::Error; end extend Initializers prepend Async include DebugClient class << self def by_id(id) Telegram.botans[id] end def prepare_async_args(method, uri, query = {}, body = nil) [method.to_s, uri.to_s, Async.prepare_hash(query), body] end end attr_reader :client, :token def initialize(token = nil, **options) @client = HTTPClient.new @token = token || options[:token] end def track(event, uid, payload = {}) request(:post, TRACK_URI, {name: event, uid: uid}, payload.to_json) end def request(method, uri, query = {}, body = nil) res = http_request(method, uri, query.merge(token: token), body) status = res.status return JSON.parse(res.body) if status < 300 result = JSON.parse(res.body) rescue nil # rubocop:disable RescueModifier err_msg = "#{res.reason}: #{result && result['info'] || '-'}" raise Error, err_msg end def http_request(method, uri, query, body) client.request(method, uri, query, body) end def inspect "#<#{self.class.name}##{object_id}(#{@id})>" end end end end
Version data entries
5 entries across 5 versions & 1 rubygems