-
-
Notifications
You must be signed in to change notification settings - Fork 19
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
twittermeow: copy x-go library into repo
- Loading branch information
Showing
39 changed files
with
4,285 additions
and
3 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,32 @@ | ||
# x-go | ||
A Go library for interacting with X's API | ||
|
||
### Test steps | ||
|
||
1. Create cookies.txt in this directory, grab your cookie string from x.com and paste it there | ||
2. Run `go test client_test.go -v` | ||
|
||
### Testing functionality | ||
|
||
```go | ||
_, _, err = cli.LoadMessagesPage() | ||
if err != nil { | ||
log.Fatal(err) | ||
} | ||
``` | ||
The `LoadMessagesPage` method makes a request to `https://x.com/messages` then makes 2 calls: | ||
```go | ||
data, err := c.GetAccountSettings(...) | ||
initialInboxState, err := c.GetInitialInboxState(...) | ||
``` | ||
it sets up the current "page" session for the client, fetches the current authenticated user info as well as the initial inbox state (the very starting inbox information you see when u load `/messages`) then returns the parsed data. | ||
|
||
To easily test with the available functions I have made, lets say you wanna test uploading an image and sending it to the top conversation in your inbox you could simply do something like: | ||
```go | ||
initialInboxData, _, err := cli.LoadMessagesPage() | ||
if err != nil { | ||
log.Fatal(err) | ||
} | ||
uploadAndSendImageTest(initialInboxData) | ||
``` | ||
Or feel free to try it out yourself! All the methods are available on the client instance. |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,57 @@ | ||
package twittermeow | ||
|
||
import ( | ||
"encoding/json" | ||
"fmt" | ||
|
||
"go.mau.fi/mautrix-twitter/pkg/twittermeow/data/endpoints" | ||
"go.mau.fi/mautrix-twitter/pkg/twittermeow/data/payload" | ||
"go.mau.fi/mautrix-twitter/pkg/twittermeow/data/response" | ||
) | ||
|
||
func (c *Client) Login() error { | ||
err := c.session.LoadPage(endpoints.BASE_LOGIN_URL) | ||
if err != nil { | ||
return err | ||
} | ||
return nil | ||
} | ||
|
||
func (c *Client) GetAccountSettings(params payload.AccountSettingsQuery) (*response.AccountSettingsResponse, error) { | ||
encodedQuery, err := params.Encode() | ||
if err != nil { | ||
return nil, err | ||
} | ||
url := fmt.Sprintf("%s?%s", endpoints.ACCOUNT_SETTINGS_URL, string(encodedQuery)) | ||
apiRequestOpts := apiRequestOpts{ | ||
Url: url, | ||
Method: "GET", | ||
} | ||
_, respBody, err := c.makeAPIRequest(apiRequestOpts) | ||
if err != nil { | ||
return nil, err | ||
} | ||
|
||
data := response.AccountSettingsResponse{} | ||
return &data, json.Unmarshal(respBody, &data) | ||
} | ||
|
||
func (c *Client) GetDMPermissions(params payload.GetDMPermissionsQuery) (*response.GetDMPermissionsResponse, error) { | ||
encodedQuery, err := params.Encode() | ||
if err != nil { | ||
return nil, err | ||
} | ||
url := fmt.Sprintf("%s?%s", endpoints.DM_PERMISSIONS_URL, string(encodedQuery)) | ||
apiRequestOpts := apiRequestOpts{ | ||
Url: url, | ||
Method: "GET", | ||
WithClientUUID: true, | ||
} | ||
_, respBody, err := c.makeAPIRequest(apiRequestOpts) | ||
if err != nil { | ||
return nil, err | ||
} | ||
|
||
data := response.GetDMPermissionsResponse{} | ||
return &data, json.Unmarshal(respBody, &data) | ||
} |
Oops, something went wrong.