class Memerator
All Memerator
functionality, whether extended or just here.
Attributes
token[R]
Get the token from instantiation
Public Class Methods
Public Instance Methods
meme(id)
click to toggle source
Get a meme by its id @param id [String] the Meme
ID @raise [Memerator::Errors::InvalidMeme] if the meme does not exist. @return [Meme] the meme
# File lib/memerator.rb, line 36 def meme(id) data = JSON.parse(RestClient.get("https://api.memerator.me/v1/meme/#{id}", Authorization: @token)) Meme.new(data, token: @token) rescue RestClient::NotFound raise Memerator::Errors::InvalidMeme, "This meme doesn't exist!" end
notifications()
click to toggle source
@return [Array<Notification>] your notifications
# File lib/memerator.rb, line 58 def notifications notifications = JSON.parse(RestClient.get('https://api.memerator.me/v1/notifications', Authorization: @token)) notifications.map { |notification_data| Notification.new(notification_data) } end
profile()
click to toggle source
@return [Profile] your profile
# File lib/memerator.rb, line 27 def profile data = JSON.parse(RestClient.get('https://api.memerator.me/v1/profile/me', Authorization: @token)) Profile.new(data, token: @token) end
randommeme()
click to toggle source
Get a random meme @return [Meme] the meme
# File lib/memerator.rb, line 46 def randommeme data = JSON.parse(RestClient.get("https://api.memerator.me/v1/meme/random", Authorization: @token)) Meme.new(data, token: @token) end
reports()
click to toggle source
@return [Array<Report>] your reports
# File lib/memerator.rb, line 64 def reports reports = JSON.parse(RestClient.get('https://api.memerator.me/v1/reports', Authorization: @token)) reports.map { |report_data| Report.new(report_data) } end
stats()
click to toggle source
@return [Stats] the site's stats
# File lib/memerator.rb, line 52 def stats data = JSON.parse(RestClient.get('https://api.memerator.me/v1/stats', Authorization: @token)) Stats.new(data) end
topmemers()
click to toggle source
Get the top memers (by meme count) @return [Hash<User, Integer>] the top memers in a hash of user to their memes
# File lib/memerator.rb, line 71 def topmemers users = JSON.parse(RestClient.get('https://api.memerator.me/v1/topmemers', Authorization: @token)) top = {} users.each do |woah| top[User.new(woah['profile'])] = woah['memes'] end top end
user(perso)
click to toggle source
@param perso [String, Integer] the ID of the user, or their username @raise [Memerator::Errors::InvalidUser] if the user does not exist @return [User] the user's profile
# File lib/memerator.rb, line 16 def user(perso) return profile if perso.downcase == 'me' data = JSON.parse(RestClient.get("https://api.memerator.me/v1/profile/#{perso}", Authorization: @token)) User.new(data) rescue RestClient::NotFound raise Memerator::Errors::InvalidUser, "This user doesn't exist!" end