score-sync-zqds: It works! + some optimizations
This commit is contained in:
parent
22e25a384a
commit
debfd2a894
2 changed files with 38 additions and 18 deletions
|
|
@ -23,9 +23,9 @@ var (
|
|||
eventId = ""
|
||||
roundId = ""
|
||||
|
||||
clientId = ""
|
||||
clientSecret = ""
|
||||
TokenURL = "https://idp.well-played.gg/oauth/token"
|
||||
TokenURL = "https://idp.well-played.gg/oauth/token"
|
||||
|
||||
configOauth = clientcredentials.Config{}
|
||||
|
||||
lock sync.Mutex
|
||||
)
|
||||
|
|
@ -91,21 +91,28 @@ func treat(team fic.ExportedTeam, tid string) {
|
|||
return
|
||||
}
|
||||
|
||||
config := clientcredentials.Config{
|
||||
ClientID: clientId,
|
||||
ClientSecret: clientSecret,
|
||||
Scopes: []string{"score:update"},
|
||||
TokenURL: TokenURL,
|
||||
}
|
||||
client := config.Client(context.Background())
|
||||
client := configOauth.Client(context.Background())
|
||||
|
||||
if req, err := http.NewRequest("PUT", u.String(), bytes.NewReader(body)); err != nil {
|
||||
req, err := http.NewRequest("PUT", u.String(), bytes.NewReader(body))
|
||||
if err != nil {
|
||||
log.Println("[ERR] Unable to send request: ", err.Error())
|
||||
} else if resp, err := client.Do(req); err != nil {
|
||||
return
|
||||
}
|
||||
|
||||
req.Header.Add("Content-Type", "application/json")
|
||||
|
||||
resp, err := client.Do(req)
|
||||
if err != nil {
|
||||
log.Println("[ERR] Error during request execution: ", err.Error())
|
||||
} else {
|
||||
log.Println(resp)
|
||||
log.Println(ioutil.ReadAll(resp.Body))
|
||||
return
|
||||
}
|
||||
|
||||
if resp.StatusCode != http.StatusOK {
|
||||
if v, err := ioutil.ReadAll(resp.Body); err != nil {
|
||||
log.Println("An error occurs when trying to send scores, then decoding response: %w", err)
|
||||
} else {
|
||||
log.Printf("An error occurs when trying to send scores: %s", string(v))
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
|||
Reference in a new issue