-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
3 changed files
with
90 additions
and
2 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,52 @@ | ||
package main | ||
|
||
import ( | ||
"fmt" | ||
"math/rand" | ||
"time" | ||
|
||
"github.com/vements/client-go/vements" | ||
) | ||
|
||
const ( | ||
API_KEY = "" | ||
PROJECT_ID = "" | ||
SCOREBOARD_ID = "" | ||
) | ||
|
||
func main() { | ||
client, _ := vements.NewClient(API_KEY, []string{"production"}, vements.NewConfig()) | ||
id := rand.Intn(1000) | ||
|
||
participantCreateResponse, _ := client.Participant.Create( | ||
vements.ParticipantCreateRequest{ | ||
ProjectId: PROJECT_ID, | ||
Display: fmt.Sprintf("Example Player %v", id), | ||
ExternalId: fmt.Sprintf("example player %v", id), | ||
Image: "", | ||
Extra: nil, | ||
}, | ||
) | ||
|
||
participant := participantCreateResponse.InsertParticipantOne | ||
|
||
fmt.Printf("Participant Created: %+v\n", participantCreateResponse) | ||
|
||
for i := 0; i < 5; i++ { | ||
_, _ = client.Scoreboard.Record( | ||
SCOREBOARD_ID, | ||
vements.ScoreboardScoreRequest{ | ||
ParticipantId: participant.ParticipantId, | ||
Value: rand.Intn(1000) + 1, | ||
Recorded: time.Now(), | ||
}, | ||
) | ||
} | ||
|
||
scoresResponse, _ := client.Scoreboard.Scores(SCOREBOARD_ID, time.Now().Add(time.Hour*-24), time.Now()) | ||
scores := scoresResponse.ScoreboardScores | ||
|
||
for _, score := range scores { | ||
fmt.Printf("Rank: %v Player: %v Total: %v\n", score.Rank, score.Participant.Display, score.Total) | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,36 @@ | ||
## Go Example for Vements | ||
|
||
This directory contains an example of how to use the Vements Client Library for Go to create a client and use that client to create a new participant, scores for that participant, and finally view a scoreboard with those scores. | ||
|
||
### Prerequisites | ||
|
||
Before you can continue, you must have the following: | ||
|
||
- API key | ||
- Project ID | ||
- Scoreboard ID | ||
|
||
To create these resources and get their IDs, create a trial or paid account at [Vements](https://vements.io). Then log into the dashboard and create a new project. Once you have a project, you can create an API key and a scoreboard. Important: create a "read-write" API key. The example will not work with a "read-only" API key. | ||
|
||
### Running the Example | ||
|
||
To run the example, first clone the repo: | ||
|
||
```shell | ||
$ git clone https://github.com/vements/client-go | ||
``` | ||
|
||
Then update the `example.go` file to use your Vements API key and the ID of your project. Change the following lines: | ||
|
||
```go | ||
API_KEY = "put your API key here" | ||
PROJECT_ID = "put your project ID here" | ||
SCOREBOARD_ID = "put your scoreboard ID here" | ||
``` | ||
|
||
Then run the example: | ||
|
||
```shell | ||
$ cd client-go | ||
$ go run example/example.go | ||
``` |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters