-
Notifications
You must be signed in to change notification settings - Fork 0
/
testing-rvgapi.Rmd
95 lines (79 loc) · 2.38 KB
/
testing-rvgapi.Rmd
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
---
title: "Testing RVGAPI"
author: "Nathan Carter"
date: "January 21, 2017"
output: html_document
---
```{r setup, warning=FALSE}
source( './R/main.R' )
source( './R/my-api-key.R' ) # obviously I don't keep this in the repository
# you can erase that line, or replace it with an import of your API key
```
We fetch a set of matches like this.
```{r}
query <- VGAPI$new( myAPIKey ) # not optional -- you must have a key
query$fetchMatches() # optional parameter is page offset
# e.g., if you get first 50 results in one page, pass 50 as offset to next call
query$getError() # will be null if all this succeeded
query$count()
```
We get a match from it like this.
```{r}
onematch <- query$getMatch( 1 ) # index, from 1 up to the count listed above
inherits( onematch, 'VGMatch' )
onematch$getTime()
onematch$getDuration()
onematch$getGameMode()
onematch$getRegion()
onematch$getEndGameReason()
```
We get the roster for one of the two sides in a match like this.
```{r}
roster <- onematch$getRoster( 1 ) # or 2
inherits( roster, 'VGRoster' )
roster$getStats()
roster$getTeamName()
```
We get the members of that roster like this.
```{r}
first <- roster$getMembers()[[1]]
inherits( first, 'VGPlayer' )
first$getName()
first$getStats()
first$getHeroName()
first$getHeroStats()
```
We get the telemetry data for the match like this.
```{r}
T <- onematch$getTelemetry()
T$getCount()
T$getEvent( 1 )
T$getEvent( T$getCount() )
```
You can filter your match set by time...
```{r}
query <- VGAPI$new( myAPIKey )
# defaults to all matches in last 3 hours, but we can change it...how about the 5 minutes after midnight?
query$setStartTime( '2017-01-11T00:00:00Z' ) # or a POSIXct date-time instance instead
query$setEndTime( '2017-01-11T00:05:00Z' ) # or a POSIXct date-time instance instead
# other filters: setPlayerNames('foo,bar,...'), setTeamNames(same)
query$fetchMatches()
if ( !is.null( query$getError() ) ) {
print( rawToChar( query$getError()$headers ) )
print( rawToChar( query$getError()$content ) )
}
query$count()
```
...or by player or team name.
```{r}
query <- VGAPI$new( myAPIKey )
query$setPlayerNames( 'CrIxX' ) # can be a comma-separated list (no spaces)
# can also do setTeamNames( 'foo,bar,...' )
query$fetchMatches()
if ( !is.null( query$getError() ) ) {
print( rawToChar( query$getError()$headers ) )
print( rawToChar( query$getError()$content ) )
}
query$count()
```
Or filter by both, not shown here.