Class: DBLRuby::Widget
- Inherits:
-
Object
- Object
- DBLRuby::Widget
- Defined in:
- lib/dblruby/widget.rb
Overview
Make a widget
Constant Summary collapse
- BASE_URL =
'https://discordbots.org/api/widget/'.freeze
Instance Attribute Summary collapse
-
#avatarbg ⇒ Object
writeonly
Sets the attribute avatarbg.
-
#certifiedcolor ⇒ Object
writeonly
Sets the attribute certifiedcolor.
-
#datacolor ⇒ Object
writeonly
Sets the attribute datacolor.
-
#highlightcolor ⇒ Object
writeonly
Sets the attribute highlightcolor.
-
#labelcolor ⇒ Object
writeonly
Sets the attribute labelcolor.
-
#leftcolor ⇒ Object
writeonly
Sets the attribute leftcolor.
-
#lefttextcolor ⇒ Object
writeonly
Sets the attribute lefttextcolor.
-
#middlecolor ⇒ Object
writeonly
Sets the attribute middlecolor.
-
#rightcolor ⇒ Object
writeonly
Sets the attribute rightcolor.
-
#righttextcolor ⇒ Object
writeonly
Sets the attribute righttextcolor.
-
#topcolor ⇒ Object
writeonly
Sets the attribute topcolor.
-
#usernamecolor ⇒ Object
writeonly
Sets the attribute usernamecolor.
Instance Method Summary collapse
- #file_type=(file_type) ⇒ Object
-
#initialize(size: 'large', file_type: 'png', small_type: nil, topcolor: nil, middlecolor: nil, usernamecolor: nil, certifiedcolor: nil, datacolor: nil, labelcolor: nil, highlightcolor: nil, avatarbg: nil, leftcolor: nil, rightcolor: nil, lefttextcolor: nil, righttextcolor: nil, noavatar: nil, id: nil) ⇒ Widget
constructor
Make a new widget.
- #noavatar=(noavatar) ⇒ Object
- #size=(size) ⇒ Object
- #small_type=(small_type) ⇒ Object
-
#url ⇒ String
(also: #to_s)
The URL, ready for linking.
Constructor Details
#initialize(size: 'large', file_type: 'png', small_type: nil, topcolor: nil, middlecolor: nil, usernamecolor: nil, certifiedcolor: nil, datacolor: nil, labelcolor: nil, highlightcolor: nil, avatarbg: nil, leftcolor: nil, rightcolor: nil, lefttextcolor: nil, righttextcolor: nil, noavatar: nil, id: nil) ⇒ Widget
Make a new widget
22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 |
# File 'lib/dblruby/widget.rb', line 22 def initialize(size: 'large', file_type: 'png', small_type: nil, topcolor: nil, middlecolor: nil, usernamecolor: nil, certifiedcolor: nil, datacolor: nil, labelcolor: nil, highlightcolor: nil, avatarbg: nil, leftcolor: nil, rightcolor: nil, lefttextcolor: nil, righttextcolor: nil, noavatar: nil, id: nil) @size = size @file_type = file_type @small_type = small_type @topcolor = topcolor @middlecolor = middlecolor @usernamecolor = usernamecolor @certifiedcolor = certifiedcolor @datacolor = datacolor @labelcolor = labelcolor @highlightcolor = highlightcolor @avatarbg = avatarbg @leftcolor = leftcolor @rightcolor = rightcolor @lefttextcolor = lefttextcolor @righttextcolor = righttextcolor @noavatar = noavatar @id = id raise DBLRuby::Errors::InvalidWidget, 'Small size specified but no small type was provided' if @size == 'small' && @small_type.nil? raise DBLRuby::Errors::InvalidWidget, 'Small parameter specified for large widget' if @size == 'large' && (!@avatarbg.nil? || !@leftcolor.nil? || !@rightcolor.nil? || !@lefttextcolor.nil? || !@righttextcolor.nil? || !@noavatar.nil?) raise DBLRuby::Errors::InvalidWidget, 'Large parameter specified for small widget' if @size == 'small' && (!@topcolor.nil? || !@middlecolor.nil? || !@usernamecolor.nil? || !@certifiedcolor.nil? || !@datacolor.nil? || !@labelcolor.nil? || !@highlightcolor.nil?) raise DBLRuby::Errors::InvalidWidget, 'Invalid size' unless %w[small large].include? @size raise DBLRuby::Errors::InvalidWidget, 'Invalid small widget type' if @size == 'small' && !%w[owner status upvotes servers lib].include?(@small_type) raise DBLRuby::Errors::InvalidWidget, 'Invalid file type' unless %w[png svg].include? @file_type raise DBLRuby::Errors::InvalidWidget, 'Invalid noavatar parameter' if !@noavatar.nil? && !%w[true false].include?(@noavatar) end |
Instance Attribute Details
#avatarbg=(value) ⇒ Object (writeonly)
Sets the attribute avatarbg
80 81 82 |
# File 'lib/dblruby/widget.rb', line 80 def avatarbg=(value) @avatarbg = value end |
#certifiedcolor=(value) ⇒ Object (writeonly)
Sets the attribute certifiedcolor
76 77 78 |
# File 'lib/dblruby/widget.rb', line 76 def certifiedcolor=(value) @certifiedcolor = value end |
#datacolor=(value) ⇒ Object (writeonly)
Sets the attribute datacolor
77 78 79 |
# File 'lib/dblruby/widget.rb', line 77 def datacolor=(value) @datacolor = value end |
#highlightcolor=(value) ⇒ Object (writeonly)
Sets the attribute highlightcolor
79 80 81 |
# File 'lib/dblruby/widget.rb', line 79 def highlightcolor=(value) @highlightcolor = value end |
#labelcolor=(value) ⇒ Object (writeonly)
Sets the attribute labelcolor
78 79 80 |
# File 'lib/dblruby/widget.rb', line 78 def labelcolor=(value) @labelcolor = value end |
#leftcolor=(value) ⇒ Object (writeonly)
Sets the attribute leftcolor
81 82 83 |
# File 'lib/dblruby/widget.rb', line 81 def leftcolor=(value) @leftcolor = value end |
#lefttextcolor=(value) ⇒ Object (writeonly)
Sets the attribute lefttextcolor
83 84 85 |
# File 'lib/dblruby/widget.rb', line 83 def lefttextcolor=(value) @lefttextcolor = value end |
#middlecolor=(value) ⇒ Object (writeonly)
Sets the attribute middlecolor
74 75 76 |
# File 'lib/dblruby/widget.rb', line 74 def middlecolor=(value) @middlecolor = value end |
#rightcolor=(value) ⇒ Object (writeonly)
Sets the attribute rightcolor
82 83 84 |
# File 'lib/dblruby/widget.rb', line 82 def rightcolor=(value) @rightcolor = value end |
#righttextcolor=(value) ⇒ Object (writeonly)
Sets the attribute righttextcolor
84 85 86 |
# File 'lib/dblruby/widget.rb', line 84 def righttextcolor=(value) @righttextcolor = value end |
#topcolor=(value) ⇒ Object (writeonly)
Sets the attribute topcolor
73 74 75 |
# File 'lib/dblruby/widget.rb', line 73 def topcolor=(value) @topcolor = value end |
#usernamecolor=(value) ⇒ Object (writeonly)
Sets the attribute usernamecolor
75 76 77 |
# File 'lib/dblruby/widget.rb', line 75 def usernamecolor=(value) @usernamecolor = value end |
Instance Method Details
#file_type=(file_type) ⇒ Object
61 62 63 64 65 |
# File 'lib/dblruby/widget.rb', line 61 def file_type=(file_type) raise DBLRuby::Errors::InvalidWidget, 'Invalid file type' unless %w[png svg].include? file_type @file_type = file_type end |
#noavatar=(noavatar) ⇒ Object
86 87 88 89 90 |
# File 'lib/dblruby/widget.rb', line 86 def noavatar=(noavatar) raise DBLRuby::Errors::InvalidWidget, 'Invalid noavatar parameter' unless %w[true false].include? noavatar @noavatar = noavatar end |
#size=(size) ⇒ Object
55 56 57 58 59 |
# File 'lib/dblruby/widget.rb', line 55 def size=(size) raise DBLRuby::Errors::InvalidWidget, 'Invalid size' unless %w[small large].include? size @size = size end |
#small_type=(small_type) ⇒ Object
67 68 69 70 71 |
# File 'lib/dblruby/widget.rb', line 67 def small_type=(small_type) raise DBLRuby::Errors::InvalidWidget, 'Invalid small widget type' if @size == 'small' && !%w[owner status upvotes servers lib].include?(small_type) @small_type = small_type end |
#url ⇒ String Also known as: to_s
Returns The URL, ready for linking.
93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 |
# File 'lib/dblruby/widget.rb', line 93 def url params = [] if @size == 'large' params.push("topcolor=#{@topcolor}") unless @topcolor.nil? params.push("middlecolor=#{@middlecolor}") unless @middlecolor.nil? params.push("usernamecolor=#{@usernamecolor}") unless @usernamecolor.nil? params.push("certifiedcolor=#{@certifiedcolor}") unless @certifiedcolor.nil? params.push("datacolor=#{@datacolor}") unless @datacolor.nil? params.push("labelcolor=#{@labelcolor}") unless @labelcolor.nil? params.push("highlightcolor=#{@highlightcolor}") unless @highlightcolor.nil? output = "#{BASE_URL}#{@id}.#{@file_type}" elsif @size == 'small' params.push("avatarbg=#{@avatarbg}") unless @avatarbg.nil? params.push("leftcolor=#{@leftcolor}") unless @leftcolor.nil? params.push("rightcolor=#{@rightcolor}") unless @rightcolor.nil? params.push("certifiedcolor=#{@certifiedcolor}") unless @certifiedcolor.nil? params.push("lefttextcolor=#{@lefttextcolor}") unless @lefttextcolor.nil? params.push("righttextcolor=#{@labelcolor}") unless @righttextcolor.nil? params.push("noavatar=#{@noavatar}") unless @noavatar.nil? output = "#{BASE_URL}#{@small_type}/#{@id}.#{@file_type}" end output += "?#{params.join('&')}" unless params.length.zero? output end |