class Lita::Adapters::Discord::API

Constants

APIBASE

Public Instance Methods

avatar_url(user_id, avatar_id) click to toggle source

Make an avatar URL from the user and avatar IDs

# File lib/lita/adapters/discord/api.rb, line 40
def avatar_url(user_id, avatar_id)
        "#{APIBASE}/users/#{user_id}/avatars/#{avatar_id}.jpg"
end
login(email, password) click to toggle source

Login to the server

# File lib/lita/adapters/discord/api.rb, line 45
def login(email, password)
        request( :post, "#{APIBASE}/auth/login", email: email, password: password )
end
logout(token) click to toggle source

Logout from the server

# File lib/lita/adapters/discord/api.rb, line 50
def logout(token)
        request( :post, "#{APIBASE}/auth/logout", nil, Authorization: token )
end
raw_request(type, attributes) click to toggle source

Referenced github.com/meew0/discordrb/blob/9897dad08370d4de5de738c8f6c27b8c7764c429/lib/discordrb/api.rb#L35

# File lib/lita/adapters/discord/api.rb, line 19
def raw_request(type, attributes)
    RestClient.send(type, *attributes)
        rescue RestClient::Forbidden
        raise Lita.logger.debug("The bot doesn't have the required permission to do this!")
end
request(type, *attributes) click to toggle source
# File lib/lita/adapters/discord/api.rb, line 25
def request(type, *attributes)
        # Add a custom user agent
    attributes.last[:user_agent] = user_agent if attributes.last.is_a? Hash
    response = raw_request(type, attributes)

    while response.code == 429
            wait_seconds = response[:retry_after].to_i / 1000.0
            Lita.logger.debug("WARNING: Discord rate limiting will cause a delay of #{wait_seconds} seconds for the request: #{type} #{attributes}")
            sleep wait_seconds / 1000.0
            response = raw_request(type, attributes)
        end
        response                           
end
user(token, user_id) click to toggle source
# File lib/lita/adapters/discord/api.rb, line 58
def user(token, user_id)
        request( :get, "#{APIBASE}/users/#{user_id}", Authorization: token )
end
user_agent() click to toggle source
# File lib/lita/adapters/discord/api.rb, line 10
def user_agent
    # This particular string is required by the Discord devs.
    required = "lita-discord (https://github.com/kyleboe/lita-discord, v0.1.0)"
        @bot_name ||= ''

        "rest-client/#{RestClient::VERSION} #{RUBY_ENGINE}/#{RUBY_VERSION}p#{RUBY_PATCHLEVEL} lita-discord/0.1.0 #{required} #{@bot_name}"
end
validate_token(token) click to toggle source
# File lib/lita/adapters/discord/api.rb, line 54
def validate_token(token)
        request( :post, "#{APIBASE}/auth/login",{}.to_json, Authorization: token, content_type: :json )
end