Class: Discordify::Client

Inherits:
Object
  • Object
show all
Defined in:
lib/discordify/client.rb

Class Attribute Summary collapse

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(webhook_address = nil) ⇒ Client

Returns a new instance of Client.



14
15
16
# File 'lib/discordify/client.rb', line 14

def initialize(webhook_address = nil)
  @webhook_address = webhook_address || self.class.webhook_address
end

Class Attribute Details

.webhook_addressObject

Returns the value of attribute webhook_address.



10
11
12
# File 'lib/discordify/client.rb', line 10

def webhook_address
  @webhook_address
end

Instance Attribute Details

#webhook_addressObject

Returns the value of attribute webhook_address.



6
7
8
# File 'lib/discordify/client.rb', line 6

def webhook_address
  @webhook_address
end

Instance Method Details

#post_json(message:, username:, avatar:) ⇒ Object



18
19
20
21
22
23
24
25
26
# 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