mirror of https://github.com/matrix-org/gomatrix
Update Login() Logout() and LogoutAll() to r0.6.0 (#73)
Co-authored-by: Neil Alexander <neilalexander@users.noreply.github.com>
This commit is contained in:
parent
e5578b12c7
commit
c698fb0c10
10
client.go
10
client.go
|
@ -354,7 +354,7 @@ func (cli *Client) Login(req *ReqLogin) (resp *RespLogin, err error) {
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
// Logout the current user. See http://matrix.org/docs/spec/client_server/r0.2.0.html#post-matrix-client-r0-logout
|
// Logout the current user. See http://matrix.org/docs/spec/client_server/r0.6.0.html#post-matrix-client-r0-logout
|
||||||
// This does not clear the credentials from the client instance. See ClearCredentials() instead.
|
// This does not clear the credentials from the client instance. See ClearCredentials() instead.
|
||||||
func (cli *Client) Logout() (resp *RespLogout, err error) {
|
func (cli *Client) Logout() (resp *RespLogout, err error) {
|
||||||
urlPath := cli.BuildURL("logout")
|
urlPath := cli.BuildURL("logout")
|
||||||
|
@ -362,6 +362,14 @@ func (cli *Client) Logout() (resp *RespLogout, err error) {
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// LogoutAll logs the current user out on all devices. See https://matrix.org/docs/spec/client_server/r0.6.0#post-matrix-client-r0-logout-all
|
||||||
|
// This does not clear the credentials from the client instance. See ClearCredentails() instead.
|
||||||
|
func (cli *Client) LogoutAll() (resp *RespLogoutAll, err error) {
|
||||||
|
urlPath := cli.BuildURL("logout/all")
|
||||||
|
err = cli.MakeRequest("POST", urlPath, nil, &resp)
|
||||||
|
return
|
||||||
|
}
|
||||||
|
|
||||||
// Versions returns the list of supported Matrix versions on this homeserver. See http://matrix.org/docs/spec/client_server/r0.2.0.html#get-matrix-client-versions
|
// Versions returns the list of supported Matrix versions on this homeserver. See http://matrix.org/docs/spec/client_server/r0.2.0.html#get-matrix-client-versions
|
||||||
func (cli *Client) Versions() (resp *RespVersions, err error) {
|
func (cli *Client) Versions() (resp *RespVersions, err error) {
|
||||||
urlPath := cli.BuildBaseURL("_matrix", "client", "versions")
|
urlPath := cli.BuildBaseURL("_matrix", "client", "versions")
|
||||||
|
|
|
@ -0,0 +1,69 @@
|
||||||
|
package gomatrix
|
||||||
|
|
||||||
|
// Identifier is the interface for https://matrix.org/docs/spec/client_server/r0.6.0#identifier-types
|
||||||
|
type Identifier interface {
|
||||||
|
// Returns the identifier type
|
||||||
|
// https://matrix.org/docs/spec/client_server/r0.6.0#identifier-types
|
||||||
|
Type() string
|
||||||
|
}
|
||||||
|
|
||||||
|
// UserIdentifier is the Identifier for https://matrix.org/docs/spec/client_server/r0.6.0#matrix-user-id
|
||||||
|
type UserIdentifier struct {
|
||||||
|
IDType string `json:"type"` // Set by NewUserIdentifer
|
||||||
|
User string `json:"user"`
|
||||||
|
}
|
||||||
|
|
||||||
|
// Type implements the Identifier interface
|
||||||
|
func (i UserIdentifier) Type() string {
|
||||||
|
return "m.id.user"
|
||||||
|
}
|
||||||
|
|
||||||
|
// NewUserIdentifier creates a new UserIdentifier with IDType set to "m.id.user"
|
||||||
|
func NewUserIdentifier(user string) UserIdentifier {
|
||||||
|
return UserIdentifier{
|
||||||
|
IDType: "m.id.user",
|
||||||
|
User: user,
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
// ThirdpartyIdentifier is the Identifier for https://matrix.org/docs/spec/client_server/r0.6.0#third-party-id
|
||||||
|
type ThirdpartyIdentifier struct {
|
||||||
|
IDType string `json:"type"` // Set by NewThirdpartyIdentifier
|
||||||
|
Medium string `json:"medium"`
|
||||||
|
Address string `json:"address"`
|
||||||
|
}
|
||||||
|
|
||||||
|
// Type implements the Identifier interface
|
||||||
|
func (i ThirdpartyIdentifier) Type() string {
|
||||||
|
return "m.id.thirdparty"
|
||||||
|
}
|
||||||
|
|
||||||
|
// NewThirdpartyIdentifier creates a new UserIdentifier with IDType set to "m.id.user"
|
||||||
|
func NewThirdpartyIdentifier(medium, address string) ThirdpartyIdentifier {
|
||||||
|
return ThirdpartyIdentifier{
|
||||||
|
IDType: "m.id.thirdparty",
|
||||||
|
Medium: medium,
|
||||||
|
Address: address,
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
// PhoneIdentifier is the Identifier for https://matrix.org/docs/spec/client_server/r0.6.0#phone-number
|
||||||
|
type PhoneIdentifier struct {
|
||||||
|
IDType string `json:"type"` // Set by NewPhoneIdentifier
|
||||||
|
Country string `json:"country"`
|
||||||
|
Phone string `json:"phone"`
|
||||||
|
}
|
||||||
|
|
||||||
|
// Type implements the Identifier interface
|
||||||
|
func (i PhoneIdentifier) Type() string {
|
||||||
|
return "m.id.phone"
|
||||||
|
}
|
||||||
|
|
||||||
|
// NewPhoneIdentifier creates a new UserIdentifier with IDType set to "m.id.user"
|
||||||
|
func NewPhoneIdentifier(country, phone string) PhoneIdentifier {
|
||||||
|
return PhoneIdentifier{
|
||||||
|
IDType: "m.id.phone",
|
||||||
|
Country: country,
|
||||||
|
Phone: phone,
|
||||||
|
}
|
||||||
|
}
|
19
requests.go
19
requests.go
|
@ -10,16 +10,17 @@ type ReqRegister struct {
|
||||||
Auth interface{} `json:"auth,omitempty"`
|
Auth interface{} `json:"auth,omitempty"`
|
||||||
}
|
}
|
||||||
|
|
||||||
// ReqLogin is the JSON request for http://matrix.org/docs/spec/client_server/r0.2.0.html#post-matrix-client-r0-login
|
// ReqLogin is the JSON request for http://matrix.org/docs/spec/client_server/r0.6.0.html#post-matrix-client-r0-login
|
||||||
type ReqLogin struct {
|
type ReqLogin struct {
|
||||||
Type string `json:"type"`
|
Type string `json:"type"`
|
||||||
Password string `json:"password,omitempty"`
|
Identifier Identifier `json:"identifier,omitempty"`
|
||||||
Medium string `json:"medium,omitempty"`
|
Password string `json:"password,omitempty"`
|
||||||
User string `json:"user,omitempty"`
|
Medium string `json:"medium,omitempty"`
|
||||||
Address string `json:"address,omitempty"`
|
User string `json:"user,omitempty"`
|
||||||
Token string `json:"token,omitempty"`
|
Address string `json:"address,omitempty"`
|
||||||
DeviceID string `json:"device_id,omitempty"`
|
Token string `json:"token,omitempty"`
|
||||||
InitialDeviceDisplayName string `json:"initial_device_display_name,omitempty"`
|
DeviceID string `json:"device_id,omitempty"`
|
||||||
|
InitialDeviceDisplayName string `json:"initial_device_display_name,omitempty"`
|
||||||
}
|
}
|
||||||
|
|
||||||
// ReqCreateRoom is the JSON request for https://matrix.org/docs/spec/client_server/r0.2.0.html#post-matrix-client-r0-createroom
|
// ReqCreateRoom is the JSON request for https://matrix.org/docs/spec/client_server/r0.2.0.html#post-matrix-client-r0-createroom
|
||||||
|
|
26
responses.go
26
responses.go
|
@ -122,17 +122,31 @@ type RespRegister struct {
|
||||||
UserID string `json:"user_id"`
|
UserID string `json:"user_id"`
|
||||||
}
|
}
|
||||||
|
|
||||||
// RespLogin is the JSON response for http://matrix.org/docs/spec/client_server/r0.2.0.html#post-matrix-client-r0-login
|
// RespLogin is the JSON response for http://matrix.org/docs/spec/client_server/r0.6.0.html#post-matrix-client-r0-login
|
||||||
type RespLogin struct {
|
type RespLogin struct {
|
||||||
AccessToken string `json:"access_token"`
|
AccessToken string `json:"access_token"`
|
||||||
DeviceID string `json:"device_id"`
|
DeviceID string `json:"device_id"`
|
||||||
HomeServer string `json:"home_server"`
|
HomeServer string `json:"home_server"`
|
||||||
UserID string `json:"user_id"`
|
UserID string `json:"user_id"`
|
||||||
|
WellKnown DiscoveryInformation `json:"well_known"`
|
||||||
}
|
}
|
||||||
|
|
||||||
// RespLogout is the JSON response for http://matrix.org/docs/spec/client_server/r0.2.0.html#post-matrix-client-r0-logout
|
// DiscoveryInformation is the JSON Response for https://matrix.org/docs/spec/client_server/r0.6.0#get-well-known-matrix-client and a part of the JSON Response for https://matrix.org/docs/spec/client_server/r0.6.0#post-matrix-client-r0-login
|
||||||
|
type DiscoveryInformation struct {
|
||||||
|
Homeserver struct {
|
||||||
|
BaseURL string `json:"base_url"`
|
||||||
|
} `json:"m.homeserver"`
|
||||||
|
IdentityServer struct {
|
||||||
|
BaseURL string `json:"base_url"`
|
||||||
|
} `json:"m.identitiy_server"`
|
||||||
|
}
|
||||||
|
|
||||||
|
// RespLogout is the JSON response for http://matrix.org/docs/spec/client_server/r0.6.0.html#post-matrix-client-r0-logout
|
||||||
type RespLogout struct{}
|
type RespLogout struct{}
|
||||||
|
|
||||||
|
// RespLogoutAll is the JSON response for https://matrix.org/docs/spec/client_server/r0.6.0#post-matrix-client-r0-logout-all
|
||||||
|
type RespLogoutAll struct{}
|
||||||
|
|
||||||
// RespCreateRoom is the JSON response for https://matrix.org/docs/spec/client_server/r0.2.0.html#post-matrix-client-r0-createroom
|
// 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 {
|
type RespCreateRoom struct {
|
||||||
RoomID string `json:"room_id"`
|
RoomID string `json:"room_id"`
|
||||||
|
|
Loading…
Reference in New Issue