2024-06-06 17:59:58 -04:00
|
|
|
package main
|
2024-06-11 17:28:20 -04:00
|
|
|
|
|
|
|
import (
|
|
|
|
"fmt"
|
|
|
|
|
|
|
|
"codeberg.org/vlbeaudoin/voki/v3"
|
|
|
|
)
|
|
|
|
|
|
|
|
type APIClient struct {
|
|
|
|
Voki *voki.Voki
|
|
|
|
}
|
|
|
|
|
|
|
|
func (c APIClient) GetHealth() (health string, err error) {
|
|
|
|
var request HealthGETRequest
|
|
|
|
response, err := request.Request(c.Voki)
|
|
|
|
if err != nil {
|
|
|
|
return "", err
|
|
|
|
}
|
|
|
|
|
|
|
|
if code, message := response.StatusCode(), response.Message; code >= 400 {
|
|
|
|
err = fmt.Errorf("%d: %s", code, message)
|
|
|
|
return
|
|
|
|
}
|
|
|
|
|
|
|
|
return response.Message, nil
|
|
|
|
}
|
2024-06-17 14:07:49 -04:00
|
|
|
|
|
|
|
func (c APIClient) InsertProgrammes(programmes ...Programme) (amountInserted int64, err error) {
|
|
|
|
var request ProgrammesPOSTRequest
|
|
|
|
request.Data.Programmes = programmes
|
|
|
|
|
|
|
|
response, err := request.Request(c.Voki)
|
|
|
|
if err != nil {
|
|
|
|
return
|
|
|
|
}
|
|
|
|
|
|
|
|
if code, message := response.StatusCode(), response.Message; code >= 400 {
|
|
|
|
err = fmt.Errorf("%d: %s", code, message)
|
|
|
|
return
|
|
|
|
}
|
|
|
|
|
|
|
|
return response.Data.ProgrammesInserted, nil
|
|
|
|
}
|
2024-06-17 17:25:53 -04:00
|
|
|
|
|
|
|
func (c APIClient) InsertMembres(membres ...Membre) (amountInserted int64, err error) {
|
|
|
|
var request MembresPOSTRequest
|
|
|
|
request.Data.Membres = membres
|
|
|
|
|
|
|
|
response, err := request.Request(c.Voki)
|
|
|
|
if err != nil {
|
|
|
|
return
|
|
|
|
}
|
|
|
|
|
|
|
|
if code, message := response.StatusCode(), response.Message; code >= 400 {
|
|
|
|
err = fmt.Errorf("%d: %s", code, message)
|
|
|
|
return
|
|
|
|
}
|
|
|
|
|
|
|
|
return response.Data.MembresInserted, nil
|
|
|
|
}
|
2024-06-18 19:44:20 -04:00
|
|
|
|
|
|
|
func (c APIClient) GetMembre(membreID string) (membre Membre, err error) {
|
|
|
|
var request MembreGETRequest
|
|
|
|
request.Param.MembreID = membreID
|
|
|
|
|
|
|
|
response, err := request.Request(c.Voki)
|
|
|
|
if err != nil {
|
|
|
|
return
|
|
|
|
}
|
|
|
|
|
|
|
|
if code, message := response.StatusCode(), response.Message; code >= 400 {
|
|
|
|
err = fmt.Errorf("%d: %s", code, message)
|
|
|
|
return
|
|
|
|
}
|
|
|
|
|
|
|
|
return response.Data.Membre, nil
|
|
|
|
}
|