Class: DBLRuby
- Inherits:
-
Object
- Object
- DBLRuby
- Defined in:
- lib/dblruby.rb
Overview
All DBLRuby functionality, whether extended or just here.
Defined Under Namespace
Modules: Errors Classes: Bot, Search, Stats, User, Weekend, Widget
Instance Attribute Summary collapse
-
#api ⇒ Object
(also: #apikey)
Get the API Key from instantiation.
-
#id ⇒ Object
Get the ID from instantiation.
Instance Method Summary collapse
-
#bot(id) ⇒ Bot
(also: #loadbot)
Load a bot.
-
#initialize(apikey, id) ⇒ DBLRuby
constructor
Initialize a new DBL API, via a key.
-
#search(search: nil, limit: 50, offset: 0, sort: nil, fields: nil) ⇒ Search
Start a search.
-
#self ⇒ Bot
Get all of the bot's stats as if you just called DBL.bot(id).
-
#stats ⇒ Stats
Initialize stats.
-
#user(id) ⇒ User
(also: #loaduser)
Load a user.
-
#weekend ⇒ Weekend
The Weekend endpoint only really tells us if it's a weekend.
-
#weekend? ⇒ true, false
Returns true or false depending on if it's the “weekend” Weekend counts as 2 votes instead of one.
- #widget(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, id: @id) ⇒ Object
Constructor Details
#initialize(apikey, id) ⇒ DBLRuby
Initialize a new DBL API, via a key.
10 11 12 13 |
# File 'lib/dblruby.rb', line 10 def initialize(apikey, id) @api = apikey @id = id end |
Instance Attribute Details
#api ⇒ Object Also known as: apikey
Get the API Key from instantiation
106 107 108 |
# File 'lib/dblruby.rb', line 106 def api @api end |
#id ⇒ Object
Get the ID from instantiation
103 104 105 |
# File 'lib/dblruby.rb', line 103 def id @id end |
Instance Method Details
#bot(id) ⇒ Bot Also known as: loadbot
Load a bot.
25 26 27 28 29 30 31 32 33 34 35 |
# File 'lib/dblruby.rb', line 25 def bot(id) url = "https://top.gg/api/bots/#{id}" data = JSON.parse(RestClient.get(url, Authorization: api)) Bot.new(data) rescue RestClient::Unauthorized raise DBLRuby::Errors::InvalidAPIKey, 'The API returned a 401 error, I believe your token is invalid.' rescue RestClient::NotFound raise DBLRuby::Errors::InvalidBot, 'The API returned a 404 error! Is that bot listed?' end |
#search(search: nil, limit: 50, offset: 0, sort: nil, fields: nil) ⇒ Search
Start a search
93 94 95 |
# File 'lib/dblruby.rb', line 93 def search(search: nil, limit: 50, offset: 0, sort: nil, fields: nil) Search.new(search: search, limit: limit, offset: offset, sort: sort, fields: fields) end |
#self ⇒ Bot
Get all of the bot's stats as if you just called DBL.bot(id)
41 42 43 |
# File 'lib/dblruby.rb', line 41 def self bot(@id) end |
#stats ⇒ Stats
Initialize stats
17 18 19 |
# File 'lib/dblruby.rb', line 17 def stats Stats.new(@api, @id) end |
#user(id) ⇒ User Also known as: loaduser
Load a user
49 50 51 52 53 54 55 56 57 58 59 |
# File 'lib/dblruby.rb', line 49 def user(id) url = "https://top.gg/api/users/#{id}" data = JSON.parse(RestClient.get(url, Authorization: api)) User.new(data) rescue RestClient::Unauthorized raise DBLRuby::Errors::InvalidAPIKey, 'The API returned a 401 error, I believe your token is invalid.' rescue RestClient::NotFound raise DBLRuby::Errors::InvalidBot, 'The API returned a 404 error! Is that bot listed?' end |
#weekend ⇒ Weekend
The Weekend endpoint only really tells us if it's a weekend
78 79 80 81 |
# File 'lib/dblruby.rb', line 78 def weekend url = 'https://top.gg/api/weekend' Weekend.new JSON.parse(RestClient.get(url)) end |
#weekend? ⇒ true, false
Returns true or false depending on if it's the “weekend” Weekend counts as 2 votes instead of one.
86 87 88 |
# File 'lib/dblruby.rb', line 86 def weekend? weekend.weekend? end |
#widget(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, id: @id) ⇒ Object
98 99 100 |
# File 'lib/dblruby.rb', line 98 def (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, id: @id) Widget.new(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, id: id) end |