restapi.go 20 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660
  1. // Discordgo - Discord bindings for Go
  2. // Available at https://github.com/bwmarrin/discordgo
  3. // Copyright 2015 Bruce Marriner <bruce@sqls.net>. All rights reserved.
  4. // Use of this source code is governed by a BSD-style
  5. // license that can be found in the LICENSE file.
  6. // This file contains functions for interacting with the Discord REST/JSON API
  7. // at the lowest level.
  8. package discordgo
  9. import (
  10. "bytes"
  11. "encoding/json"
  12. "fmt"
  13. "io/ioutil"
  14. "net/http"
  15. "net/url"
  16. "strconv"
  17. "time"
  18. )
  19. // Request makes a (GET/POST/...) Requests to Discord REST API.
  20. // All the other Discord REST Calls in this file use this function.
  21. func (s *Session) Request(method, urlStr string, data interface{}) (response []byte, err error) {
  22. if s.Debug {
  23. fmt.Printf("API REQUEST %8s :: %s\n", method, urlStr)
  24. fmt.Println("API REQUEST PAYLOAD :: [" + fmt.Sprintf("%+v", data) + "]")
  25. }
  26. body, err := json.Marshal(data)
  27. if err != nil {
  28. return
  29. }
  30. req, err := http.NewRequest(method, urlStr, bytes.NewBuffer(body))
  31. if err != nil {
  32. return
  33. }
  34. // Not used on initial login..
  35. // TODO: Verify if a login, otherwise complain about no-token
  36. if s.Token != "" {
  37. req.Header.Set("authorization", s.Token)
  38. }
  39. req.Header.Set("Content-Type", "application/json")
  40. // TODO: Make a configurable static variable.
  41. req.Header.Set("User-Agent", fmt.Sprintf("DiscordBot (https://github.com/bwmarrin/discordgo, v%s)", VERSION))
  42. if s.Debug {
  43. for k, v := range req.Header {
  44. fmt.Printf("API REQUEST HEADER :: [%s] = %+v\n", k, v)
  45. }
  46. }
  47. client := &http.Client{Timeout: (20 * time.Second)}
  48. resp, err := client.Do(req)
  49. if err != nil {
  50. return
  51. }
  52. response, err = ioutil.ReadAll(resp.Body)
  53. if err != nil {
  54. return
  55. }
  56. resp.Body.Close()
  57. if s.Debug {
  58. fmt.Printf("API RESPONSE STATUS :: %s\n", resp.Status)
  59. for k, v := range resp.Header {
  60. fmt.Printf("API RESPONSE HEADER :: [%s] = %+v\n", k, v)
  61. }
  62. fmt.Printf("API RESPONSE BODY :: [%s]\n", response)
  63. }
  64. // See http://www.w3.org/Protocols/rfc2616/rfc2616-sec10.html
  65. switch resp.StatusCode {
  66. case 200: // OK
  67. case 204: // No Content
  68. // TODO check for 401 response, invalidate token if we get one.
  69. // TODO check for 429 response, rate-limit when we get one.
  70. default: // Error condition
  71. err = fmt.Errorf("HTTP %d", resp.StatusCode)
  72. return
  73. }
  74. return
  75. }
  76. // ------------------------------------------------------------------------------------------------
  77. // Functions specific to Discord Sessions
  78. // ------------------------------------------------------------------------------------------------
  79. // Login asks the Discord server for an authentication token
  80. func (s *Session) Login(email string, password string) (token string, err error) {
  81. data := struct {
  82. Email string `json:"email"`
  83. Password string `json:"password"`
  84. }{email, password}
  85. response, err := s.Request("POST", LOGIN, data)
  86. var temp map[string]interface{}
  87. err = json.Unmarshal(response, &temp)
  88. // prevent crashing by manipulating a map that has no data
  89. if err != nil {
  90. return
  91. }
  92. token = temp["token"].(string)
  93. return
  94. }
  95. // Logout sends a logout request to Discord.
  96. // This does not seem to actually invalidate the token. So you can still
  97. // make API calls even after a Logout. So, it seems almost pointless to
  98. // even use.
  99. func (s *Session) Logout() (err error) {
  100. // _, err = s.Request("POST", LOGOUT, fmt.Sprintf(`{"token": "%s"}`, s.Token))
  101. return
  102. }
  103. // ------------------------------------------------------------------------------------------------
  104. // Functions specific to Discord Users
  105. // ------------------------------------------------------------------------------------------------
  106. // User returns the user details of the given userID
  107. // userID : A user ID or "@me" which is a shortcut of current user ID
  108. func (s *Session) User(userID string) (st User, err error) {
  109. body, err := s.Request("GET", USER(userID), nil)
  110. err = json.Unmarshal(body, &st)
  111. return
  112. }
  113. // UserUpdate updates a users settings.
  114. // userID : A user ID or "@me" which is a shortcut of current user ID
  115. func (s *Session) UserUpdate(userID, email, password, username, avatar, newPassword string) (st User, err error) {
  116. // NOTE: Avatar must be either the hash/id of existing Avatar or
  117. // data:image/png;base64,BASE64_STRING_OF_NEW_AVATAR_PNG
  118. // to set a new avatar.
  119. // If left blank, avatar will be set to null/blank
  120. data := struct {
  121. Email string `json:"email"`
  122. Password string `json:"password"`
  123. Username string `json:"username"`
  124. Avatar string `json:"avatar,omitempty"`
  125. NewPassword json.Token `json:"new_password,omitempty"`
  126. }{email, password, username, avatar, newPassword}
  127. body, err := s.Request("PATCH", USER(userID), data)
  128. err = json.Unmarshal(body, &st)
  129. return
  130. }
  131. // UserAvatar returns a ?? of a users Avatar
  132. // userID : A user ID or "@me" which is a shortcut of current user ID
  133. func (s *Session) UserAvatar(userID string) (st User, err error) {
  134. u, err := s.User(userID)
  135. _, err = s.Request("GET", USER_AVATAR(userID, u.Avatar), nil)
  136. // TODO need to figure out how to handle returning a file
  137. return
  138. }
  139. // UserSettings returns the settings for a given user
  140. // userID : A user ID or "@me" which is a shortcut of current user ID
  141. // This seems to only return a result for "@me"
  142. func (s *Session) UserSettings(userID string) (st Settings, err error) {
  143. body, err := s.Request("GET", USER_SETTINGS(userID), nil)
  144. err = json.Unmarshal(body, &st)
  145. return
  146. }
  147. // UserChannels returns an array of Channel structures for all private
  148. // channels for a user
  149. // userID : A user ID or "@me" which is a shortcut of current user ID
  150. func (s *Session) UserChannels(userID string) (st []Channel, err error) {
  151. body, err := s.Request("GET", USER_CHANNELS(userID), nil)
  152. err = json.Unmarshal(body, &st)
  153. return
  154. }
  155. // UserChannelCreate creates a new User (Private) Channel with another User
  156. // userID : A user ID or "@me" which is a shortcut of current user ID
  157. // recipientID : A user ID for the user to which this channel is opened with.
  158. func (s *Session) UserChannelCreate(userID, recipientID string) (st Channel, err error) {
  159. data := struct {
  160. RecipientID string `json:"recipient_id"`
  161. }{recipientID}
  162. body, err := s.Request(
  163. "POST",
  164. USER_CHANNELS(userID),
  165. data)
  166. err = json.Unmarshal(body, &st)
  167. return
  168. }
  169. // UserGuilds returns an array of Guild structures for all guilds for a given user
  170. // userID : A user ID or "@me" which is a shortcut of current user ID
  171. func (s *Session) UserGuilds(userID string) (st []Guild, err error) {
  172. body, err := s.Request("GET", USER_GUILDS(userID), nil)
  173. err = json.Unmarshal(body, &st)
  174. return
  175. }
  176. // ------------------------------------------------------------------------------------------------
  177. // Functions specific to Discord Guilds
  178. // ------------------------------------------------------------------------------------------------
  179. // Guild returns a Guild structure of a specific Guild.
  180. // guildID : The ID of a Guild
  181. func (s *Session) Guild(guildID string) (st Guild, err error) {
  182. body, err := s.Request("GET", GUILD(guildID), nil)
  183. err = json.Unmarshal(body, &st)
  184. return
  185. }
  186. // GuildCreate creates a new Guild
  187. // name : A name for the Guild (2-100 characters)
  188. func (s *Session) GuildCreate(name string) (st Guild, err error) {
  189. data := struct {
  190. Name string `json:"name"`
  191. }{name}
  192. body, err := s.Request("POST", GUILDS, data)
  193. err = json.Unmarshal(body, &st)
  194. return
  195. }
  196. // GuildEdit edits a new Guild
  197. // guildID : The ID of a Guild
  198. // name : A name for the Guild (2-100 characters)
  199. func (s *Session) GuildEdit(guildID, name string) (st Guild, err error) {
  200. data := struct {
  201. Name string `json:"name"`
  202. }{name}
  203. body, err := s.Request("POST", GUILD(guildID), data)
  204. err = json.Unmarshal(body, &st)
  205. return
  206. }
  207. // GuildDelete deletes or leaves a Guild.
  208. // guildID : The ID of a Guild
  209. func (s *Session) GuildDelete(guildID string) (st Guild, err error) {
  210. body, err := s.Request("DELETE", GUILD(guildID), nil)
  211. err = json.Unmarshal(body, &st)
  212. return
  213. }
  214. // GuildBans returns an array of User structures for all bans of a
  215. // given guild.
  216. // guildID : The ID of a Guild.
  217. func (s *Session) GuildBans(guildID string) (st []User, err error) {
  218. body, err := s.Request("GET", GUILD_BANS(guildID), nil)
  219. err = json.Unmarshal(body, &st)
  220. return
  221. }
  222. // GuildBanCreate bans the given user from the given guild.
  223. // guildID : The ID of a Guild.
  224. // userID : The ID of a User
  225. // days : The number of days of previous comments to delete.
  226. func (s *Session) GuildBanCreate(guildID, userID string, days int) (err error) {
  227. uri := GUILD_BAN(guildID, userID)
  228. if days > 0 {
  229. uri = fmt.Sprintf("%s?delete-message-days=%d", uri, days)
  230. }
  231. _, err = s.Request("PUT", uri, nil)
  232. return
  233. }
  234. // GuildBanDelete removes the given user from the guild bans
  235. // guildID : The ID of a Guild.
  236. // userID : The ID of a User
  237. func (s *Session) GuildBanDelete(guildID, userID string) (err error) {
  238. _, err = s.Request("DELETE", GUILD_BAN(guildID, userID), nil)
  239. return
  240. }
  241. // GuildMemberDelete removes the given user from the given guild.
  242. // guildID : The ID of a Guild.
  243. // userID : The ID of a User
  244. func (s *Session) GuildMemberDelete(guildID, userID string) (err error) {
  245. _, err = s.Request("DELETE", GUILD_MEMBER_DEL(guildID, userID), nil)
  246. return
  247. }
  248. // GuildChannels returns an array of Channel structures for all channels of a
  249. // given guild.
  250. // guildID : The ID of a Guild.
  251. func (s *Session) GuildChannels(guildID string) (st []Channel, err error) {
  252. body, err := s.Request("GET", GUILD_CHANNELS(guildID), nil)
  253. err = json.Unmarshal(body, &st)
  254. return
  255. }
  256. // GuildChannelCreate creates a new channel in the given guild
  257. // guildID : The ID of a Guild.
  258. // name : Name of the channel (2-100 chars length)
  259. // ctype : Tpye of the channel (voice or text)
  260. func (s *Session) GuildChannelCreate(guildID, name, ctype string) (st Channel, err error) {
  261. data := struct {
  262. Name string `json:"name"`
  263. Type string `json:"type"`
  264. }{name, ctype}
  265. body, err := s.Request("POST", GUILD_CHANNELS(guildID), data)
  266. err = json.Unmarshal(body, &st)
  267. return
  268. }
  269. // GuildInvites returns an array of Invite structures for the given guild
  270. // guildID : The ID of a Guild.
  271. func (s *Session) GuildInvites(guildID string) (st []Invite, err error) {
  272. body, err := s.Request("GET", GUILD_INVITES(guildID), nil)
  273. err = json.Unmarshal(body, &st)
  274. return
  275. }
  276. // GuildInviteCreate creates a new invite for the given guild.
  277. // guildID : The ID of a Guild.
  278. // i : An Invite struct with the values MaxAge, MaxUses, Temporary,
  279. // and XkcdPass defined.
  280. func (s *Session) GuildInviteCreate(guildID string, i Invite) (st Invite, err error) {
  281. data := struct {
  282. MaxAge int `json:"max_age"`
  283. MaxUses int `json:"max_uses"`
  284. Temporary bool `json:"temporary"`
  285. XKCDPass bool `json:"xkcdpass"`
  286. }{i.MaxAge, i.MaxUses, i.Temporary, i.XkcdPass}
  287. body, err := s.Request("POST", GUILD_INVITES(guildID), data)
  288. err = json.Unmarshal(body, &st)
  289. return
  290. }
  291. // GuildRoles returns all roles for a given guild.
  292. func (s *Session) GuildRoles(guildID string) (st []Role, err error) {
  293. body, err := s.Request("GET", GUILD_ROLES(guildID), nil)
  294. err = json.Unmarshal(body, &st)
  295. return // TODO return pointer
  296. }
  297. // GuildRoleCreate returns a new Guild Role
  298. func (s *Session) GuildRoleCreate(guildID string) (st Role, err error) {
  299. body, err := s.Request("POST", GUILD_ROLES(guildID), nil)
  300. err = json.Unmarshal(body, &st)
  301. return
  302. }
  303. // GuildRoleEdit updates an existing Guild Role with new values
  304. func (s *Session) GuildRoleEdit(guildID, roleID, name string, color int, hoist bool, perm int) (st Role, err error) {
  305. data := struct {
  306. Name string `json:"name"` // The color the role should have (as a decimal, not hex)
  307. Color int `json:"color"` // Whether to display the role's users separately
  308. Hoist bool `json:"hoist"` // The role's name (overwrites existing)
  309. Permissions int `json:"permissions"` // The overall permissions number of the role (overwrites existing)
  310. }{name, color, hoist, perm}
  311. body, err := s.Request("PATCH", GUILD_ROLE(guildID, roleID), data)
  312. err = json.Unmarshal(body, &st)
  313. return
  314. }
  315. // GuildRoleReorder reoders guild roles
  316. func (s *Session) GuildRoleReorder(guildID string, roles []Role) (st []Role, err error) {
  317. body, err := s.Request("PATCH", GUILD_ROLES(guildID), roles)
  318. err = json.Unmarshal(body, &st)
  319. return
  320. }
  321. // GuildRoleDelete deletes an existing role.
  322. func (s *Session) GuildRoleDelete(guildID, roleID string) (err error) {
  323. _, err = s.Request("DELETE", GUILD_ROLE(guildID, roleID), nil)
  324. return
  325. }
  326. // ------------------------------------------------------------------------------------------------
  327. // Functions specific to Discord Channels
  328. // ------------------------------------------------------------------------------------------------
  329. // Channel returns a Channel strucutre of a specific Channel.
  330. // channelID : The ID of the Channel you want returend.
  331. func (s *Session) Channel(channelID string) (st Channel, err error) {
  332. body, err := s.Request("GET", CHANNEL(channelID), nil)
  333. err = json.Unmarshal(body, &st)
  334. return
  335. }
  336. // ChannelEdit edits the given channel
  337. // channelID : The ID of a Channel
  338. // name : The new name to assign the channel.
  339. func (s *Session) ChannelEdit(channelID, name string) (st Channel, err error) {
  340. data := struct {
  341. Name string `json:"name"`
  342. }{name}
  343. body, err := s.Request("PATCH", CHANNEL(channelID), data)
  344. err = json.Unmarshal(body, &st)
  345. return
  346. }
  347. // ChannelDelete deletes the given channel
  348. // channelID : The ID of a Channel
  349. func (s *Session) ChannelDelete(channelID string) (st Channel, err error) {
  350. body, err := s.Request("DELETE", CHANNEL(channelID), nil)
  351. err = json.Unmarshal(body, &st)
  352. return
  353. }
  354. // ChannelTyping broadcasts to all members that authenticated user is typing in
  355. // the given channel.
  356. // channelID : The ID of a Channel
  357. func (s *Session) ChannelTyping(channelID string) (err error) {
  358. _, err = s.Request("POST", CHANNEL_TYPING(channelID), nil)
  359. return
  360. }
  361. // ChannelMessages returns an array of Message structures for messaages within
  362. // a given channel.
  363. // channelID : The ID of a Channel.
  364. // limit : The number messages that can be returned.
  365. // beforeID : If provided all messages returned will be before given ID.
  366. // afterID : If provided all messages returned will be after given ID.
  367. func (s *Session) ChannelMessages(channelID string, limit int, beforeID int, afterID int) (st []Message, err error) {
  368. uri := CHANNEL_MESSAGES(channelID)
  369. v := url.Values{}
  370. if limit > 0 {
  371. v.Set("limit", strconv.Itoa(limit))
  372. }
  373. if afterID > 0 {
  374. v.Set("after", strconv.Itoa(afterID))
  375. }
  376. if beforeID > 0 {
  377. v.Set("before", strconv.Itoa(beforeID))
  378. }
  379. if len(v) > 0 {
  380. uri = fmt.Sprintf("%s?%s", uri, v.Encode())
  381. }
  382. body, err := s.Request("GET", uri, nil)
  383. if err != nil {
  384. return
  385. }
  386. err = json.Unmarshal(body, &st)
  387. return
  388. }
  389. // ChannelMessageAck acknowledges and marks the given message as read
  390. // channeld : The ID of a Channel
  391. // messageID : the ID of a Message
  392. func (s *Session) ChannelMessageAck(channelID, messageID string) (err error) {
  393. _, err = s.Request("POST", CHANNEL_MESSAGE_ACK(channelID, messageID), nil)
  394. return
  395. }
  396. // ChannelMessageSend sends a message to the given channel.
  397. // channelID : The ID of a Channel.
  398. // content : The message to send.
  399. // NOTE, mention and tts parameters may be added in 2.x branch.
  400. func (s *Session) ChannelMessageSend(channelID string, content string) (st Message, err error) {
  401. // TODO: nonce string ?
  402. data := struct {
  403. Content string `json:"content"`
  404. TTS bool `json:"tts"`
  405. }{content, false}
  406. // Send the message to the given channel
  407. response, err := s.Request("POST", CHANNEL_MESSAGES(channelID), data)
  408. err = json.Unmarshal(response, &st)
  409. return
  410. }
  411. // ChannelMessageEdit edits an existing message, replacing it entirely with
  412. // the given content.
  413. // channeld : The ID of a Channel
  414. // messageID : the ID of a Message
  415. func (s *Session) ChannelMessageEdit(channelID, messageID, content string) (st Message, err error) {
  416. data := struct {
  417. Content string `json:"content"`
  418. }{content}
  419. response, err := s.Request("PATCH", CHANNEL_MESSAGE(channelID, messageID), data)
  420. err = json.Unmarshal(response, &st)
  421. return
  422. }
  423. // ChannelMessageDelete deletes a message from the Channel.
  424. func (s *Session) ChannelMessageDelete(channelID, messageID string) (err error) {
  425. _, err = s.Request("DELETE", CHANNEL_MESSAGE(channelID, messageID), nil)
  426. return
  427. }
  428. // ChannelInvites returns an array of Invite structures for the given channel
  429. // channelID : The ID of a Channel
  430. func (s *Session) ChannelInvites(channelID string) (st []Invite, err error) {
  431. body, err := s.Request("GET", CHANNEL_INVITES(channelID), nil)
  432. err = json.Unmarshal(body, &st)
  433. return
  434. }
  435. // ChannelInviteCreate creates a new invite for the given channel.
  436. // channelID : The ID of a Channel
  437. // i : An Invite struct with the values MaxAge, MaxUses, Temporary,
  438. // and XkcdPass defined.
  439. func (s *Session) ChannelInviteCreate(channelID string, i Invite) (st Invite, err error) {
  440. data := struct {
  441. MaxAge int `json:"max_age"`
  442. MaxUses int `json:"max_uses"`
  443. Temporary bool `json:"temporary"`
  444. XKCDPass bool `json:"xkcdpass"`
  445. }{i.MaxAge, i.MaxUses, i.Temporary, i.XkcdPass}
  446. body, err := s.Request("POST", CHANNEL_INVITES(channelID), data)
  447. err = json.Unmarshal(body, &st)
  448. return
  449. }
  450. // ChannelPermissionSet creates a Permission Override for the given channel.
  451. // NOTE: This func name may changed. Using Set instead of Create because
  452. // you can both create a new override or update an override with this function.
  453. func (s *Session) ChannelPermissionSet(channelID, targetID, targetType string, allow, deny int) (err error) {
  454. data := struct {
  455. ID string `json:"id"`
  456. Type string `json:"type"`
  457. Allow int `json:"allow"`
  458. Deny int `json:"deny"`
  459. }{targetID, targetType, allow, deny}
  460. _, err = s.Request("PUT", CHANNEL_PERMISSION(channelID, targetID), data)
  461. return
  462. }
  463. // ChannelPermissionDelete deletes a specific permission override for the given channel.
  464. // NOTE: Name of this func may change.
  465. func (s *Session) ChannelPermissionDelete(channelID, targetID string) (err error) {
  466. _, err = s.Request("DELETE", CHANNEL_PERMISSION(channelID, targetID), nil)
  467. return
  468. }
  469. // ------------------------------------------------------------------------------------------------
  470. // Functions specific to Discord Invites
  471. // ------------------------------------------------------------------------------------------------
  472. // Invite returns an Invite structure of the given invite
  473. // inviteID : The invite code (or maybe xkcdpass?)
  474. func (s *Session) Invite(inviteID string) (st Invite, err error) {
  475. body, err := s.Request("GET", INVITE(inviteID), nil)
  476. err = json.Unmarshal(body, &st)
  477. return
  478. }
  479. // InviteDelete deletes an existing invite
  480. // inviteID : the code (or maybe xkcdpass?) of an invite
  481. func (s *Session) InviteDelete(inviteID string) (st Invite, err error) {
  482. body, err := s.Request("DELETE", INVITE(inviteID), nil)
  483. err = json.Unmarshal(body, &st)
  484. return
  485. }
  486. // InviteAccept accepts an Invite to a Guild or Channel
  487. // inviteID : The invite code (or maybe xkcdpass?)
  488. func (s *Session) InviteAccept(inviteID string) (st Invite, err error) {
  489. body, err := s.Request("POST", INVITE(inviteID), nil)
  490. err = json.Unmarshal(body, &st)
  491. return
  492. }
  493. // ------------------------------------------------------------------------------------------------
  494. // Functions specific to Discord Voice
  495. // ------------------------------------------------------------------------------------------------
  496. // VoiceRegions returns the voice server regions
  497. func (s *Session) VoiceRegions() (st []VoiceRegion, err error) {
  498. body, err := s.Request("GET", VOICE_REGIONS, nil)
  499. err = json.Unmarshal(body, &st)
  500. return
  501. }
  502. // VoiceICE returns the voice server ICE information
  503. func (s *Session) VoiceICE() (st VoiceICE, err error) {
  504. body, err := s.Request("GET", VOICE_ICE, nil)
  505. err = json.Unmarshal(body, &st)
  506. return
  507. }
  508. // ------------------------------------------------------------------------------------------------
  509. // Functions specific to Discord Websockets
  510. // ------------------------------------------------------------------------------------------------
  511. // Gateway returns the a websocket Gateway address
  512. func (s *Session) Gateway() (gateway string, err error) {
  513. response, err := s.Request("GET", GATEWAY, nil)
  514. var temp map[string]interface{}
  515. err = json.Unmarshal(response, &temp)
  516. gateway = temp["url"].(string)
  517. return
  518. }