remote-challenge-sync-airbus: WIP
This commit is contained in:
parent
6d9fd1ff12
commit
367e686e8a
5 changed files with 270 additions and 51 deletions
|
|
@ -12,7 +12,7 @@ import (
|
|||
type AirbusAPI struct {
|
||||
BaseURL string
|
||||
Token string
|
||||
SessionID uint64
|
||||
SessionID int64
|
||||
}
|
||||
|
||||
func (a *AirbusAPI) request(method, endpoint string, data []byte, out interface{}) error {
|
||||
|
|
@ -52,6 +52,11 @@ func (a *AirbusAPI) request(method, endpoint string, data []byte, out interface{
|
|||
|
||||
type AirbusUserId int64
|
||||
|
||||
func NewAirbusUserId(externalid string) AirbusUserId {
|
||||
v, _ := strconv.ParseInt(externalid, 10, 64)
|
||||
return AirbusUserId(v)
|
||||
}
|
||||
|
||||
func (aui AirbusUserId) String() string {
|
||||
return strconv.FormatInt(int64(aui), 10)
|
||||
}
|
||||
|
|
@ -112,8 +117,8 @@ func (a *AirbusAPI) GetChallengeFromName(name string) (*AirbusChallenge, error)
|
|||
return nil, fmt.Errorf("unable to find challenge %q", name)
|
||||
}
|
||||
|
||||
func (a *AirbusAPI) ValidateChallengeFromUser(user *AirbusUser, challenge *AirbusChallenge) (err error) {
|
||||
err = a.request("GET", fmt.Sprintf("/sessions/%d/%s/%s/validate", a.SessionID, challenge.Id.String(), user.Id.String()), nil, nil)
|
||||
func (a *AirbusAPI) ValidateChallengeFromUser(userId AirbusUserId, challengeId AirbusChallengeId) (err error) {
|
||||
err = a.request("GET", fmt.Sprintf("/sessions/%d/%s/%s/validate", a.SessionID, challengeId.String(), userId.String()), nil, nil)
|
||||
return
|
||||
}
|
||||
|
||||
|
|
@ -123,9 +128,9 @@ type AirbusUserAwards struct {
|
|||
Value int64 `json:"value"`
|
||||
}
|
||||
|
||||
func (a *AirbusAPI) AwardUser(user *AirbusUser, value int64, message string) (err error) {
|
||||
func (a *AirbusAPI) AwardUser(userId AirbusUserId, value int64, message string) (err error) {
|
||||
awards := AirbusUserAwards{
|
||||
UserId: user.Id,
|
||||
UserId: userId,
|
||||
Message: message,
|
||||
Value: value,
|
||||
}
|
||||
|
|
@ -147,6 +152,18 @@ type AirbusStatsData struct {
|
|||
BySessions []AirbusStatsSession `json:"by_sessions"`
|
||||
}
|
||||
|
||||
func (s AirbusStatsData) GetSession(sessionId AirbusUUID) *AirbusStatsSession {
|
||||
for _, session := range s.BySessions {
|
||||
if session.UUID == sessionId {
|
||||
return &session
|
||||
}
|
||||
}
|
||||
|
||||
return nil
|
||||
}
|
||||
|
||||
type AirbusUUID string
|
||||
|
||||
type AirbusStatsSession struct {
|
||||
UUID AirbusUUID `json:"uuid"`
|
||||
Name string `json:"name"`
|
||||
|
|
@ -154,6 +171,16 @@ type AirbusStatsSession struct {
|
|||
TeamStats []AirbusTeamStats `json:"team_stats"`
|
||||
}
|
||||
|
||||
func (s AirbusStatsSession) GetTeam(teamId AirbusUUID) *AirbusTeamStats {
|
||||
for _, team := range s.TeamStats {
|
||||
if team.UUID == teamId {
|
||||
return &team
|
||||
}
|
||||
}
|
||||
|
||||
return nil
|
||||
}
|
||||
|
||||
type AirbusTeamStats struct {
|
||||
UUID AirbusUUID `json:"uuid"`
|
||||
Name string `json:"name"`
|
||||
|
|
|
|||
Reference in a new issue