module Discord::Notifier
Constants
- VERSION
Public Class Methods
endpoint(config)
click to toggle source
# File lib/discord_notifier.rb, line 66 def self.endpoint(config) uri = URI(config[:url]) uri.query = URI.encode_www_form(wait: true) if config[:wait] return uri end
message(content, config = {})
click to toggle source
# File lib/discord_notifier.rb, line 21 def self.message(content, config = {}) params = payload(content, config) if params[:file] send_form(params) else send_request(params) end end
payload(content, config)
click to toggle source
# File lib/discord_notifier.rb, line 31 def self.payload(content, config) payload = @@config.to_h.merge(config) case content when String payload[:content] = content when Embed payload[:embeds] = [content.data] when Array payload[:embeds] = content.map { |embed| embed.data } when File payload[:file] = content else raise ArgumentError, 'Unsupported content type' end payload.compact end
send_form(params)
click to toggle source
# File lib/discord_notifier.rb, line 56 def self.send_form(params) uri = endpoint(params) req = Discord.form_data_request(uri, params) http = Net::HTTP.new(uri.host, uri.port) http.use_ssl = true http.request(req) end
send_request(params)
click to toggle source
# File lib/discord_notifier.rb, line 50 def self.send_request(params) Net::HTTP.post endpoint(params), params.to_json, { 'Content-Type' => 'application/json' } end
setup() { |config| ... }
click to toggle source
# File lib/discord_notifier.rb, line 17 def self.setup yield @@config end