forked from pothtonswer/discordmuffin
Added VoiceRegions and VoiceIce. Clean up endpoint constants
This commit is contained in:
parent
4fc845b7eb
commit
9076028987
1 changed files with 87 additions and 53 deletions
140
restapi.go
140
restapi.go
|
@ -15,6 +15,7 @@ import (
|
||||||
"fmt"
|
"fmt"
|
||||||
"io/ioutil"
|
"io/ioutil"
|
||||||
"net/http"
|
"net/http"
|
||||||
|
"strconv"
|
||||||
"time"
|
"time"
|
||||||
)
|
)
|
||||||
|
|
||||||
|
@ -24,57 +25,70 @@ const (
|
||||||
// Base URLS
|
// Base URLS
|
||||||
DISCORD = "http://discordapp.com"
|
DISCORD = "http://discordapp.com"
|
||||||
API = DISCORD + "/api"
|
API = DISCORD + "/api"
|
||||||
SERVERS = API + "/guilds"
|
GUILDS = API + "/guilds" // Guilds()
|
||||||
CHANNELS = API + "/channels"
|
CHANNELS = API + "/channels" // Channels()
|
||||||
USERS = API + "/users"
|
USERS = API + "/users" // Users()
|
||||||
LOGIN = API + "/auth/login"
|
LOGIN = API + "/auth/login" // Login()
|
||||||
LOGOUT = API + "/auth/logout"
|
LOGOUT = API + "/auth/logout" // Logout()
|
||||||
GATEWAY = API + "/gateway"
|
GATEWAY = API + "/gateway" // Gateway()
|
||||||
|
|
||||||
// Constants not implemented below yet. TODO tracker :)
|
|
||||||
REGISTER = API + "/auth/register"
|
|
||||||
INVITE = API + "/invite"
|
|
||||||
TRACK = API + "/track"
|
|
||||||
SSO = API + "/sso"
|
|
||||||
VERIFY = API + "/auth/verify"
|
|
||||||
VERIFY_RESEND = API + "/auth/verify/resend"
|
|
||||||
FORGOT_PASSWORD = API + "/auth/forgot"
|
|
||||||
RESET_PASSWORD = API + "/auth/reset"
|
|
||||||
REGIONS = API + "/voice/regions"
|
|
||||||
ICE = API + "/voice/ice"
|
|
||||||
REPORT = API + "/report"
|
|
||||||
INTEGRATIONS = API + "/integrations"
|
|
||||||
// Authenticated User Info
|
// Authenticated User Info
|
||||||
AU = USERS + "/@me"
|
AU = USERS + "/@me"
|
||||||
AU_DEVICES = AU + "/devices"
|
AU_SETTINGS = AU + "/settings" // Call Settings with @me
|
||||||
AU_SETTINGS = AU + "/settings"
|
AU_CHANNELS = AU + "/channels" // Call Channel with @me
|
||||||
AU_CONNECTIONS = AU + "/connections"
|
AU_GUILDS = AU + "/guilds" // Call Guilds with @me
|
||||||
AU_CHANNELS = AU + "/channels"
|
|
||||||
AU_SERVERS = AU + "/guilds"
|
|
||||||
|
|
||||||
// Need a way to handle these here so the variables can be inserted.
|
REGIONS = API + "/voice/regions" // VoiceRegions()
|
||||||
// Maybe defined as functions?
|
ICE = API + "/voice/ice" // VoiceIce()
|
||||||
/*
|
|
||||||
INTEGRATIONS_JOIN: integrationId => `/integrations/${integrationId}/join`,
|
|
||||||
AVATAR: (userId, hash) => `/users/${userId}/avatars/${hash}.jpg`,
|
|
||||||
MESSAGES: channelId => `/channels/${channelId}/messages`,
|
|
||||||
INSTANT_INVITES: channelId => `/channels/${channelId}/invites`,
|
|
||||||
TYPING: channelId => `/channels/${channelId}/typing`,
|
|
||||||
CHANNEL_PERMISSIONS: channelId => `/channels/${channelId}/permissions`,
|
|
||||||
TUTORIAL: `/tutorial`,
|
|
||||||
TUTORIAL_INDICATORS: `/tutorial/indicators`,
|
|
||||||
USER_CHANNELS: userId => `/users/${userId}/channels`,
|
|
||||||
GUILD_CHANNELS: guildId => `/guilds/${guildId}/channels`,
|
|
||||||
GUILD_MEMBERS: guildId => `/guilds/${guildId}/members`,
|
|
||||||
GUILD_INTEGRATIONS: guildId => `/guilds/${guildId}/integrations`,
|
|
||||||
GUILD_BANS: guildId => `/guilds/${guildId}/bans`,
|
|
||||||
GUILD_ROLES: guildId => `/guilds/${guildId}/roles`,
|
|
||||||
GUILD_INSTANT_INVITES: guildId => `/guilds/${guildId}/invites`,
|
|
||||||
GUILD_EMBED: guildId => `/guilds/${guildId}/embed`,
|
|
||||||
GUILD_PRUNE: guildId => `/guilds/${guildId}/prune`,
|
|
||||||
GUILD_ICON: (guildId, hash) => `/guilds/${guildId}/icons/${hash}.jpg`,
|
|
||||||
*/
|
|
||||||
|
|
||||||
|
// : guildId => `/guilds/${guildId}/channels`,
|
||||||
|
// GUILD_CHANNELS: guildId => `/guilds/${guildId}/channels`,
|
||||||
|
|
||||||
|
// TODO: Test below
|
||||||
|
// AU_DEVICES = AU + "/devices"
|
||||||
|
// AU_CONNECTIONS = AU + "/connections"
|
||||||
|
// REGISTER = API + "/auth/register"
|
||||||
|
// INVITE = API + "/invite"
|
||||||
|
// TRACK = API + "/track"
|
||||||
|
// SSO = API + "/sso"
|
||||||
|
// VERIFY = API + "/auth/verify"
|
||||||
|
// VERIFY_RESEND = API + "/auth/verify/resend"
|
||||||
|
// FORGOT_PASSWORD = API + "/auth/forgot"
|
||||||
|
// RESET_PASSWORD = API + "/auth/reset"
|
||||||
|
// REPORT = API + "/report"
|
||||||
|
// INTEGRATIONS = API + "/integrations"
|
||||||
|
|
||||||
|
// Need a way to handle these here so the variables can be inserted.
|
||||||
|
// Maybe defined as functions?
|
||||||
|
/*
|
||||||
|
INTEGRATIONS_JOIN: integrationId => `/integrations/${integrationId}/join`,
|
||||||
|
AVATAR: (userId, hash) => `/users/${userId}/avatars/${hash}.jpg`,
|
||||||
|
MESSAGES: channelId => `/channels/${channelId}/messages`,
|
||||||
|
INSTANT_INVITES: channelId => `/channels/${channelId}/invites`,
|
||||||
|
TYPING: channelId => `/channels/${channelId}/typing`,
|
||||||
|
CHANNEL_PERMISSIONS: channelId => `/channels/${channelId}/permissions`,
|
||||||
|
TUTORIAL: `/tutorial`,
|
||||||
|
TUTORIAL_INDICATORS: `/tutorial/indicators`,
|
||||||
|
USER_CHANNELS: userId => `/users/${userId}/channels`,
|
||||||
|
GUILD_CHANNELS: guildId => `/guilds/${guildId}/channels`,
|
||||||
|
GUILD_MEMBERS: guildId => `/guilds/${guildId}/members`,
|
||||||
|
GUILD_INTEGRATIONS: guildId => `/guilds/${guildId}/integrations`,
|
||||||
|
GUILD_BANS: guildId => `/guilds/${guildId}/bans`,
|
||||||
|
GUILD_ROLES: guildId => `/guilds/${guildId}/roles`,
|
||||||
|
GUILD_INSTANT_INVITES: guildId => `/guilds/${guildId}/invites`,
|
||||||
|
GUILD_EMBED: guildId => `/guilds/${guildId}/embed`,
|
||||||
|
GUILD_PRUNE: guildId => `/guilds/${guildId}/prune`,
|
||||||
|
GUILD_ICON: (guildId, hash) => `/guilds/${guildId}/icons/${hash}.jpg`,
|
||||||
|
*/
|
||||||
|
|
||||||
|
)
|
||||||
|
|
||||||
|
// Almost like the constants above :) Dynamic Variables?
|
||||||
|
var (
|
||||||
|
GUILD_CHANNELS = func(i int) (s string) {
|
||||||
|
s = GUILDS + "/" + strconv.Itoa(i) + "/channels"
|
||||||
|
return
|
||||||
|
}
|
||||||
)
|
)
|
||||||
|
|
||||||
// Request makes a (GET/POST/?) Requests to Discord REST API.
|
// Request makes a (GET/POST/?) Requests to Discord REST API.
|
||||||
|
@ -148,9 +162,28 @@ func (s *Session) Users(userId string) (user User, err error) {
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
// USERS could pull users channels, servers, settings and so forth too?
|
func (s *Session) VoiceRegions() (vr []VoiceRegion, err error) {
|
||||||
// you know, pull all the data for the user. update the user strut
|
|
||||||
// to house that data. Seems reasonable.
|
body, err := s.Request("GET", REGIONS, ``)
|
||||||
|
err = json.Unmarshal(body, &vr)
|
||||||
|
return
|
||||||
|
}
|
||||||
|
|
||||||
|
func (s *Session) VoiceIce() (ice VoiceIce, err error) {
|
||||||
|
|
||||||
|
body, err := s.Request("GET", ICE, ``)
|
||||||
|
err = json.Unmarshal(body, &ice)
|
||||||
|
return
|
||||||
|
}
|
||||||
|
|
||||||
|
// Settings returns the settings for a given user
|
||||||
|
// This seems to only return a result for "@me"
|
||||||
|
func (s *Session) Settings(userId string) (settings Settings, err error) {
|
||||||
|
|
||||||
|
body, err := s.Request("GET", fmt.Sprintf("%s/%s/settings", USERS, userId), ``)
|
||||||
|
err = json.Unmarshal(body, &settings)
|
||||||
|
return
|
||||||
|
}
|
||||||
|
|
||||||
// PrivateChannels returns an array of Channel structures for all private
|
// PrivateChannels returns an array of Channel structures for all private
|
||||||
// channels for a user
|
// channels for a user
|
||||||
|
@ -178,7 +211,7 @@ func (s *Session) Guilds(userId string) (servers []Guild, err error) {
|
||||||
// server.
|
// server.
|
||||||
func (s *Session) Members(serverId int) (members []Member, err error) {
|
func (s *Session) Members(serverId int) (members []Member, err error) {
|
||||||
|
|
||||||
body, err := s.Request("GET", fmt.Sprintf("%s/%d/members", SERVERS, serverId), ``)
|
body, err := s.Request("GET", fmt.Sprintf("%s/%d/members", GUILDS, serverId), ``)
|
||||||
err = json.Unmarshal(body, &members)
|
err = json.Unmarshal(body, &members)
|
||||||
|
|
||||||
return
|
return
|
||||||
|
@ -186,9 +219,10 @@ func (s *Session) Members(serverId int) (members []Member, err error) {
|
||||||
|
|
||||||
// Channels returns an array of Channel structures for all channels of a given
|
// Channels returns an array of Channel structures for all channels of a given
|
||||||
// server.
|
// server.
|
||||||
func (s *Session) Channels(serverId int) (channels []Channel, err error) {
|
func (s *Session) Channels(Id int) (channels []Channel, err error) {
|
||||||
|
|
||||||
body, err := s.Request("GET", fmt.Sprintf("%s/%d/channels", SERVERS, serverId), ``)
|
// body, err := s.Request("GET", fmt.Sprintf("%s/%d/channels", GUILDS, serverId), ``)
|
||||||
|
body, err := s.Request("GET", GUILD_CHANNELS(Id), ``)
|
||||||
err = json.Unmarshal(body, &channels)
|
err = json.Unmarshal(body, &channels)
|
||||||
|
|
||||||
return
|
return
|
||||||
|
|
Loading…
Reference in a new issue