forked from grumbulon/pleroma-tools
2 changed files with 0 additions and 86 deletions
@ -1,3 +0,0 @@ |
|||
module git.freecumextremist.com/grumbulon/pleroma-tools |
|||
|
|||
go 1.17 |
@ -1,83 +0,0 @@ |
|||
package main |
|||
|
|||
import ( |
|||
"encoding/json" |
|||
"flag" |
|||
"fmt" |
|||
"io/ioutil" |
|||
"log" |
|||
"net/http" |
|||
) |
|||
|
|||
type accountsAPI []struct { |
|||
Fqn string `json:"fqn"` |
|||
ID string `json:"id"` |
|||
} |
|||
|
|||
func main() { |
|||
instanceName := flag.String("i", "", "The instance the account is on") |
|||
accountName := flag.String("n", "", "The name of the account on the instance") |
|||
flag.Parse() |
|||
if len(*instanceName) != 0 && len(*accountName) != 0 { |
|||
getID(instanceName, accountName) |
|||
} |
|||
} |
|||
|
|||
func getID(instanceName *string, accountName *string) { |
|||
client := &http.Client{} |
|||
urlBuilder := fmt.Sprintf("https://%v/api/v1/accounts/%v", *instanceName, *accountName) |
|||
|
|||
req, err := http.NewRequest("GET", urlBuilder, nil) |
|||
if err != nil { |
|||
log.Fatalln(err) |
|||
} |
|||
|
|||
req.Header.Add("Accept", "application/json") |
|||
req.Header.Add("Content-Type", "application/json") |
|||
|
|||
resp, err := client.Do(req) |
|||
if err != nil { |
|||
log.Fatalln(err) |
|||
} |
|||
|
|||
defer resp.Body.Close() |
|||
bodyBytes, err := ioutil.ReadAll(resp.Body) |
|||
if err != nil { |
|||
log.Fatalln(err) |
|||
} |
|||
|
|||
var responseObject accountsAPI |
|||
json.Unmarshal(bodyBytes, &responseObject) |
|||
fmt.Println(responseObject) |
|||
} |
|||
|
|||
func callAPI(instanceName *string, accountName *string) { |
|||
fmt.Println("Querying API...") |
|||
|
|||
client := &http.Client{} |
|||
urlBuilder := fmt.Sprintf("https://%p/api/v1/account/%p", instanceName, accountName) |
|||
fmt.Println(urlBuilder) |
|||
|
|||
req, err := http.NewRequest("GET", urlBuilder, nil) |
|||
if err != nil { |
|||
log.Fatalln(err) |
|||
} |
|||
|
|||
req.Header.Add("Accept", "application/json") |
|||
req.Header.Add("Content-Type", "application/json") |
|||
|
|||
resp, err := client.Do(req) |
|||
if err != nil { |
|||
log.Fatalln(err) |
|||
} |
|||
|
|||
defer resp.Body.Close() |
|||
bodyBytes, err := ioutil.ReadAll(resp.Body) |
|||
if err != nil { |
|||
log.Fatalln(err) |
|||
} |
|||
|
|||
var responseObject accountsAPI |
|||
json.Unmarshal(bodyBytes, &responseObject) |
|||
fmt.Println(responseObject) |
|||
} |
Loading…
Reference in new issue