class JacondaTelegram::Api
Constants
- ENDPOINT
Public Class Methods
new(token)
click to toggle source
# File lib/jaconda_telegram.rb, line 8 def initialize(token) @@token = token end
Public Instance Methods
get_group(id)
click to toggle source
# File lib/jaconda_telegram.rb, line 21 def get_group(id) begin result = RestClient.get "#{ENDPOINT}/groups", { params: { token: @@token, id: id } } rescue Exception => e parse_exception e end parse_result result.body end
list_groups()
click to toggle source
# File lib/jaconda_telegram.rb, line 12 def list_groups begin result = RestClient.get "#{ENDPOINT}/groups", { params: { token: @@token } } rescue Exception => e parse_exception e end parse_result result.body end
send_media(group_id, file_path)
click to toggle source
# File lib/jaconda_telegram.rb, line 39 def send_media(group_id, file_path) begin result = RestClient.post "#{ENDPOINT}/groups/#{group_id}/media", { token: @@token, file: File.new(file_path, 'rb') } rescue Exception => e parse_exception e end parse_result result.body end
send_message(group_id, text)
click to toggle source
# File lib/jaconda_telegram.rb, line 30 def send_message(group_id, text) begin result = RestClient.post "#{ENDPOINT}/groups/#{group_id}/messages", { token: @@token, text: text } rescue Exception => e parse_exception e end parse_result result.body end
Protected Instance Methods
parse_exception(e)
click to toggle source
# File lib/jaconda_telegram.rb, line 50 def parse_exception(e) if e.message.eql?('401 Unauthorized') fail 'Invalid Token!' else fail 'Jaconda is unreachable!' end end
parse_result(data)
click to toggle source
# File lib/jaconda_telegram.rb, line 58 def parse_result(data) begin json_result = JSON.parse data rescue fail 'Expected JSON got some crap' end return json_result end