Class: Pechkin::Connector::Base

Inherits:
Object
  • Object
show all
Defined in:
lib/pechkin/connector/base.rb

Overview

Base connector

Direct Known Subclasses

Slack, Telegram

Constant Summary collapse

DEFAULT_HEADERS =
{
  'Content-Type' => 'application/json; charset=UTF-8'
}.freeze

Instance Method Summary collapse

Instance Method Details

#post_data(url, data, headers: {}) ⇒ Object



16
17
18
19
20
21
22
23
24
25
26
# File 'lib/pechkin/connector/base.rb', line 16

def post_data(url, data, headers: {})
  uri = URI.parse(url)
  headers = DEFAULT_HEADERS.merge(headers)
  http = Net::HTTP.new(uri.host, uri.port)
  http.use_ssl = url.start_with?('https://')

  request = Net::HTTP::Post.new(uri.request_uri, headers)
  request.body = data.to_json

  http.request(request)
end

#preview(chats, message, _message_desc) ⇒ Object



11
12
13
14
# File 'lib/pechkin/connector/base.rb', line 11

def preview(chats, message, _message_desc)
  "Connector: #{self.class.name}; Chats: #{chats.join(', ')}\n" \
  "Message:\n#{message}"
end

#send_message(chat, message, message_desc) ⇒ Object



9
# File 'lib/pechkin/connector/base.rb', line 9

def send_message(chat, message, message_desc); end