This commit is contained in:
callebtc
2022-08-24 22:20:14 +02:00
parent 4867d649c9
commit ef375c01bd
6 changed files with 80 additions and 64 deletions

View File

@@ -167,58 +167,21 @@ func GetAmbossClient() AmbossClient {
}
func (c *AmbossClient) GetNodeInfo(pubkey string) (Amboss_NodeInfoResponse, error) {
url := "https://api.amboss.space/graphql"
log.Infof("Getting info from amboss.space for %s", pubkey)
graphqlClient := graphql.NewClient(url)
graphqlRequest := graphql.NewRequest(simple_query)
graphqlRequest := graphql.NewRequest(amboss_graphql_query)
graphqlRequest.Var("pubkey", pubkey)
// set header fields
graphqlRequest.Header.Set("Cache-Control", "no-cache")
graphqlRequest.Header.Set("Content-Type", "application/json")
var r_nested *AutoGenerated
if err := graphqlClient.Run(context.Background(), graphqlRequest, &r_nested); err != nil {
var r_nested Amboss_NodeInfoResponse_Nested
if err := graphqlClient.Run(context.Background(), graphqlRequest, &r_nested.Data); err != nil {
log.Errorf("[amboss] api error: %v", err)
}
// r := r_nested.Data.GetNode.Amboss_NodeInfoResponse
return Amboss_NodeInfoResponse{}, nil
// jsonData := map[string]string{
// "query": query,
// "variables": variables,
// }
// client := http.Client{
// Timeout: time.Second * 2, // Timeout after 2 seconds
// }
// req, err := http.NewRequest(http.MethodGet, url, nil)
// if err != nil {
// log.Fatal(err)
// }
// res, getErr := client.Do(req)
// if getErr != nil {
// log.Fatal(getErr)
// }
// if res.Body != nil {
// defer res.Body.Close()
// }
// body, readErr := ioutil.ReadAll(res.Body)
// if readErr != nil {
// log.Fatal(readErr)
// }
// r := Amboss_NodeInfoResponse{}
// jsonErr := json.Unmarshal(body, &r)
// if jsonErr != nil {
// log.Errorf("API error: %v", jsonErr)
// }
// return r, nil
r := r_nested.Data.GetNode.Amboss_NodeInfoResponse
return r, nil
}