Class: Pechkin::Connector::Base
- Inherits:
-
Object
- Object
- Pechkin::Connector::Base
- Defined in:
- lib/pechkin/connector/base.rb
Overview
Base connector
Constant Summary collapse
- DEFAULT_HEADERS =
{ 'Content-Type' => 'application/json; charset=UTF-8' }.freeze
Instance Method Summary collapse
- #post_data(url, data, headers: {}) ⇒ Object
- #preview(chats, message, _message_desc) ⇒ Object
- #send_message(chat, message, message_desc) ⇒ Object
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, , ) "Connector: #{self.class.name}; Chats: #{chats.join(', ')}\n" \ "Message:\n#{}" end |
#send_message(chat, message, message_desc) ⇒ Object
9 |
# File 'lib/pechkin/connector/base.rb', line 9 def (chat, , ); end |