From 6c242710d7b1e4ba7c7d9b76437529d1d00c7c67 Mon Sep 17 00:00:00 2001 From: hanemile Date: Fri, 10 Jul 2020 16:37:52 +0200 Subject: the functions handling almost everything I need --- login.go | 35 ++--------------------------------- 1 file changed, 2 insertions(+), 33 deletions(-) (limited to 'login.go') diff --git a/login.go b/login.go index 3e35858..aa24db5 100644 --- a/login.go +++ b/login.go @@ -3,9 +3,8 @@ package matrix import ( "encoding/json" - "github.com/h2non/gentleman/plugins/body" "gopkg.in/h2non/gentleman.v2" - "gopkg.in/h2non/gentleman.v2/plugins/query" + "gopkg.in/h2non/gentleman.v2/plugins/body" ) // Login logs in to the homeserver and returns an Authinfo struct containing @@ -38,38 +37,8 @@ func Login(username, password, homeserver string) (Authinfo, error) { if err := json.Unmarshal(res.Bytes(), &authinfo); err != nil { return Authinfo{}, err } - return authinfo, nil -} -func Sync(authinfo Authinfo) { - cli := gentleman.New() - cli.URL(authinfo.HomeServer) - - req := cli.Request() - req.Path("/_matrix/client/r0/sync") - req.Method("GET") - - req.Use(query.Set("access_token", authinfo.AccessToken)) - - res, err := req.Send() - if err != nil { - return err - } - if !res.Ok { - return err - } + authinfo.HomeServer = homeserver - var authinfo Authinfo - if err := json.Unmarshal(res.Bytes(), &authinfo); err != nil { - return Authinfo{}, err - } return authinfo, nil } - -// Authinfo defines the fields returned after logging in -type Authinfo struct { - UserID string `json:"user_id"` - HomeServer string `json:"home_server"` - DeviceID string `json:"device_id"` - AccessToken string `json:"access_token"` -} -- cgit 1.4.1