class TelegramNotification::Client

Constants

API_URL

Attributes

api_url[R]

Public Class Methods

new(api_url = nil) click to toggle source
# File lib/telegram_notification/client.rb, line 11
def initialize(api_url = nil)
  @api_url = URI.parse(api_url || API_URL)
end

Public Instance Methods

post(api_token: ::TelegramNotification.config.api_token,method: "sendMessage",chat_id: ::TelegramNotification.config.chat_id, text:) click to toggle source
# File lib/telegram_notification/client.rb, line 15
def post(api_token: ::TelegramNotification.config.api_token,method: "sendMessage",chat_id: ::TelegramNotification.config.chat_id, text:)
  url = endpoint(api_token,method)
  params = { chat_id: chat_id, text: text }.to_json

  # puts "url: #{url}, params: #{params}"


  response = Net::HTTP.post(url, params, 'Content-Type': 'application/json')
  response_body = JSON.parse(response.body)
  return response_body["ok"] == true

end

Private Instance Methods

endpoint(api_token, method) click to toggle source
# File lib/telegram_notification/client.rb, line 30
def endpoint(api_token, method)
  api_url+("/bot"+api_token+"/"+method)
end