package main
import (
+ "encoding/json"
"fmt"
"io"
"net/http"
"net/url"
+ "os"
)
type App struct {
func (a App) Create() (application Application, err error) {
resp, err := http.PostForm("https://hackers.town/api/v1/apps",
url.Values{
- "client_name": {"dead-tooter"},
- "redirect_uris": {"urn:ietf:wg:oauth:2.0:oob"},
- "scopes": {"read:follows write:blocks"},
- "website": {"https://dead-tooter.vexingworkshop.com"},
+ "client_name": {a.ClientName},
+ "redirect_uris": {a.RedirectUris},
+ "scopes": {a.Scopes},
+ "website": {a.Website},
},
)
if err != nil {
defer resp.Body.Close()
body, err := io.ReadAll(resp.Body)
- fmt.Printf("%s", resp.Status)
- fmt.Printf("%s", string(body))
+ err = json.Unmarshal(body, &application)
- return Application{}, nil
+ return
+}
+
+func (a App) Load(name string) (Application, error) {
+ err := os.Mkdir("foodir", 0750)
+ if err != nil && !os.IsExist(err) {
+ panic(err.Error())
+ }
+
+ data, err := os.ReadFile("~/foodir/" + name)
+ if err != nil && os.IsNotExist(err) {
+ panic(err.Error())
+ }
+
+ var application Application
+ err = json.Unmarshal(data, &application)
+ if err != nil {
+ panic(err.Error())
+ }
+
+ return application, nil
}
type Application struct {
func (a Application) Login() {}
-func main() {
- app := App{
- ClientName: "dead-tooter",
- RedirectUris: "urn:ietf:wg:oauth:2.0:oob",
- Scopes: "read:follows",
- Website: "https://dead-tooter.vexingworkshop.com",
+/*
+ func main() {
+ app := App{
+ ClientName: "dead-tooter",
+ RedirectUris: "urn:ietf:wg:oauth:2.0:oob",
+ Scopes: "read:follows",
+ Website: "https://dead-tooter.vexingworkshop.com",
+ }
+
+ tooter, err := app.Create()
+ if err != nil {
+ panic(err.Error())
+ }
+
+ fmt.Printf("%v", tooter)
}
- _, err := app.Create()
+*/
+func main() {
+
+ tooter, err := App{}.Load("dead-tooter")
if err != nil {
panic(err.Error())
}
+
+ fmt.Printf("%v", tooter)
}