class Discordify::Client
Attributes
webhook_address[RW]
webhook_address[RW]
Public Class Methods
new(webhook_address = nil)
click to toggle source
# File lib/discordify/client.rb, line 14 def initialize(webhook_address = nil) @webhook_address = webhook_address || self.class.webhook_address end
Public Instance Methods
post_json(message:, username:, avatar:)
click to toggle source
# File lib/discordify/client.rb, line 18 def post_json(message:, username:, avatar:) avatar ||= default_avatar url = uri(webhook_address) request = Net::HTTP::Post.new(url.path, headers) request.body = { content: message, username: username, avatar_url: avatar }.to_json res = https_request(url).request(request) res.code == '204' end
Private Instance Methods
default_avatar()
click to toggle source
# File lib/discordify/client.rb, line 44 def default_avatar 'http://www.gravatar.com/avatar/?d=identicon' end
headers()
click to toggle source
# File lib/discordify/client.rb, line 40 def headers { 'Content-Type' => 'application/json' } end
https_request(uri)
click to toggle source
# File lib/discordify/client.rb, line 34 def https_request(uri) Net::HTTP.new(uri.host, uri.port).tap do |http| http.use_ssl = true end end
uri(url)
click to toggle source
# File lib/discordify/client.rb, line 30 def uri(url) URI.parse(URI.escape(url)) end