Class: YiffSpace::Images::Banner::Discord

Inherits:
Base
  • Object
show all
Defined in:
lib/yiffspace/images/banner/discord.rb

Instance Attribute Summary

Attributes inherited from Base

#id, #type

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(id) ⇒ Discord

Returns a new instance of Discord.



11
12
13
# File 'lib/yiffspace/images/banner/discord.rb', line 11

def initialize(id)
  super(id, self.class.type)
end

Class Method Details

.typeObject



9
# File 'lib/yiffspace/images/banner/discord.rb', line 9

def self.type = :discord

Instance Method Details

#update(hash) ⇒ Object

Raises:

  • (StandardError)


19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
# File 'lib/yiffspace/images/banner/discord.rb', line 19

def update(hash)
  raise(StandardError, "images.update_token config option must be set to use banner update") if YiffSpace.config.images.update_token.blank?

  response = HTTParty.post("#{YiffSpace.config.images.server_url}/banner/discord/update/#{id}",
                           YiffSpace.config.images.httparty_options.deep_merge(
                             headers: {
                               "Authorization" => "Bearer #{YiffSpace.config.images.update_token}",
                               "Content-Type"  => "application/json",
                             },
                             body:    { hash: hash }.to_json,
                           ))
  Rails.logger.error("banner update failed: #{response.to_json}") unless response.key?("updated")

  response.fetch("updated", false)
end

#urlObject



15
16
17
# File 'lib/yiffspace/images/banner/discord.rb', line 15

def url
  "#{YiffSpace.config.images.server_url}/banner/discord/#{id}"
end