From 0827f53d1c9e6be7e9f846dd28ca31ebfbfcff1f Mon Sep 17 00:00:00 2001 From: Kegan Dougal Date: Thu, 5 Jan 2017 14:16:47 +0000 Subject: [PATCH] Add /logout API --- client.go | 12 ++++++++++++ responses.go | 3 +++ 2 files changed, 15 insertions(+) diff --git a/client.go b/client.go index c3a4d4e..d10704e 100644 --- a/client.go +++ b/client.go @@ -350,6 +350,18 @@ func (cli *Client) Login(req *ReqLogin, setOnClient bool) (resp *RespLogin, err return } +// Logout the current user. See http://matrix.org/docs/spec/client_server/r0.2.0.html#post-matrix-client-r0-logout +// If "removeCredentials" is true, the user ID and access token will be removed from this client instance on success. +func (cli *Client) Logout(removeCredentials bool) (resp *RespLogout, err error) { + urlPath := cli.BuildURL("logout") + _, err = cli.MakeRequest("POST", urlPath, nil, &resp) + if removeCredentials && err == nil { + cli.UserID = "" + cli.AccessToken = "" + } + return +} + // JoinRoom joins the client to a room ID or alias. See http://matrix.org/docs/spec/client_server/r0.2.0.html#post-matrix-client-r0-join-roomidoralias // // If serverName is specified, this will be added as a query param to instruct the homeserver to join via that server. If content is specified, it will diff --git a/responses.go b/responses.go index 1cfd4e0..f71742e 100644 --- a/responses.go +++ b/responses.go @@ -74,6 +74,9 @@ type RespLogin struct { UserID string `json:"user_id"` } +// RespLogout is the JSON response for http://matrix.org/docs/spec/client_server/r0.2.0.html#post-matrix-client-r0-logout +type RespLogout struct{} + // RespCreateRoom is the JSON response for https://matrix.org/docs/spec/client_server/r0.2.0.html#post-matrix-client-r0-createroom type RespCreateRoom struct { RoomID string `json:"room_id"`