Sha256: f97e3e18407d5eeaddf1fa3ac060d1600667b09fb2e5562209623ebf52b18c84
Contents?: true
Size: 1.46 KB
Versions: 12
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 300 > status 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
12 entries across 12 versions & 1 rubygems