Class: DiscordWebHooks::Message
- Inherits:
-
Object
- Object
- DiscordWebHooks::Message
- Defined in:
- lib/discord_webhooks/message.rb
Instance Method Summary collapse
-
#initialize(text:, embeds: []) ⇒ Message
constructor
A new instance of Message.
- #send(webhook) ⇒ Object
Constructor Details
#initialize(text:, embeds: []) ⇒ Message
Returns a new instance of Message.
3 4 5 6 7 8 9 10 |
# File 'lib/discord_webhooks/message.rb', line 3 def initialize(text:,embeds:[]) @text = text = { content: text, embeds: .map{|e|e.to_h} } @json = .to_json end |
Instance Method Details
#send(webhook) ⇒ Object
12 13 14 15 16 17 18 19 20 21 22 |
# File 'lib/discord_webhooks/message.rb', line 12 def send(webhook) webhook_url = URI.parse(webhook) request = Net::HTTP::Post.new(webhook_url.path, {'Content-Type' => 'application/json'}) request.body = @json response = Net::HTTP.start(webhook_url.host, webhook_url.port, use_ssl: true) do |http| http.request(request) end end |