module Discord::Notifier
Constants
- VERSION
Public Class Methods
endpoint(config)
click to toggle source
# File lib/discord_notifier_confidist.rb, line 72 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_confidist.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_confidist.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_confidist.rb, line 62 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_confidist.rb, line 50 def self.send_request(params) uri = endpoint(params) http = Net::HTTP.new(uri.host, uri.port) http.use_ssl = true req = Net::HTTP::Post.new(endpoint(params)) req.body = params.to_json req.content_type = 'application/json' http.request(req) end
setup() { |config| ... }
click to toggle source
# File lib/discord_notifier_confidist.rb, line 17 def self.setup yield @@config end