The basic setup....
options(stringsAsFactors=F)
## remove the ##
knitr::opts_chunk$set(comment = NA)
## load the packages
library(httr)
suppressPackageStartupMessages(library(dplyr))
## my token
TOKEN = "9a4b9dc1a4d21eacb566f672c3c662b3"
queryAPI = function(BODY = NA, TOKEN, version=1, ep = "stats") {
## BODY is a list, e.g. list(stat="hits",team_id="bos")
URL = sprintf("https://www.stattleship.com/hockey/nhl/%s", ep)
ACCEPT = sprintf("application/vnd.stattleship.com; version=%d", version)
## test the body
if (is.na(BODY)) {
BODY = list()
}
resp = GET(URL,
add_headers(Authorization =TOKEN,
Accept = ACCEPT,
`Content-Type`="application/json"),
query=BODY)
api_response = content(resp)
return(api_response)
}
q_body = list(stat="hits", team_id="bos")
boston_hits = queryAPI(BODY = q_body, TOKEN)
Warning in if (is.na(BODY)) {: the condition has length > 1 and only the
first element will be used
Lets see what we have
## list the names
names(boston_hits)
[1] "feats" "games" "home_teams" "away_teams"
[5] "winning_teams" "players" "stats"
## length
length(boston_hits$stats)
[1] 20
the names of what came back
lapply(boston_hits$stats, function(x) names(x))
[[1]]
[1] "id" "created_at" "updated_at" "stat"
[5] "statistic_type" "actual" "feat_id"
[[2]]
[1] "id" "created_at" "updated_at" "stat"
[5] "statistic_type" "actual" "feat_id"
[[3]]
[1] "id" "created_at" "updated_at" "stat"
[5] "statistic_type" "actual" "feat_id"
[[4]]
[1] "id" "created_at" "updated_at" "stat"
[5] "statistic_type" "actual" "feat_id"
[[5]]
[1] "id" "created_at" "updated_at" "stat"
[5] "statistic_type" "actual" "feat_id"
[[6]]
[1] "id" "created_at" "updated_at" "stat"
[5] "statistic_type" "actual" "feat_id"
[[7]]
[1] "id" "created_at" "updated_at" "stat"
[5] "statistic_type" "actual" "feat_id"
[[8]]
[1] "id" "created_at" "updated_at" "stat"
[5] "statistic_type" "actual" "feat_id"
[[9]]
[1] "id" "created_at" "updated_at" "stat"
[5] "statistic_type" "actual" "feat_id"
[[10]]
[1] "id" "created_at" "updated_at" "stat"
[5] "statistic_type" "actual" "feat_id"
[[11]]
[1] "id" "created_at" "updated_at" "stat"
[5] "statistic_type" "actual" "feat_id"
[[12]]
[1] "id" "created_at" "updated_at" "stat"
[5] "statistic_type" "actual" "feat_id"
[[13]]
[1] "id" "created_at" "updated_at" "stat"
[5] "statistic_type" "actual" "feat_id"
[[14]]
[1] "id" "created_at" "updated_at" "stat"
[5] "statistic_type" "actual" "feat_id"
[[15]]
[1] "id" "created_at" "updated_at" "stat"
[5] "statistic_type" "actual" "feat_id"
[[16]]
[1] "id" "created_at" "updated_at" "stat"
[5] "statistic_type" "actual" "feat_id"
[[17]]
[1] "id" "created_at" "updated_at" "stat"
[5] "statistic_type" "actual" "feat_id"
[[18]]
[1] "id" "created_at" "updated_at" "stat"
[5] "statistic_type" "actual" "feat_id"
[[19]]
[1] "id" "created_at" "updated_at" "stat"
[5] "statistic_type" "actual" "feat_id"
[[20]]
[1] "id" "created_at" "updated_at" "stat"
[5] "statistic_type" "actual" "feat_id"
And dive a bit further into one of the entries to see what's available
lapply(boston_hits$stats[[1]], function(x) names(x))
$id
NULL
$created_at
NULL
$updated_at
NULL
$stat
NULL
$statistic_type
NULL
$actual
NULL
$feat_id
NULL
A look at one feat entry
lapply(boston_hits$stats[[1]]$feat, function(x) x)
[[1]]
[1] "9b7f412d-bf8e-4a82-89fd-606adb3eabd5"
Totally possible my query didn't resolve properly, but I wasn't expecting to see David Backes returned in results
q_body = list(stat="goals", player_id="nhl-patrick-kane")
kane = queryAPI(BODY = q_body, TOKEN)
Warning in if (is.na(BODY)) {: the condition has length > 1 and only the
first element will be used
What came back
names(kane)
[1] "feats" "games" "home_teams" "away_teams"
[5] "winning_teams" "players" "stats"
names(kane$stats)
NULL
length(kane$stats)
[1] 18
names(kane$stats[[1]])
[1] "id" "created_at" "updated_at" "stat"
[5] "statistic_type" "actual" "feat_id"
Just printing the first entry
kane$stats[[1]]
$id
[1] "38626c6a-ac70-42ea-a79a-829fe8ba1687"
$created_at
[1] "2015-11-30T07:01:13Z"
$updated_at
[1] "2015-11-30T07:01:13Z"
$stat
[1] "goals"
$statistic_type
[1] "HockeyOffensiveStat"
$actual
[1] "2.0"
$feat_id
[1] "15ced369-9a4c-4795-b884-f6ea4b612209"
Take a stab at hat trick goals and pagination
q_body = list(feat="hat_trick_goals")
hatties = queryAPI(BODY = q_body, TOKEN, ep="feats")
what came back
names(hatties)
[1] "games" "home_teams" "away_teams" "winning_teams"
[5] "players" "feats"
names(hatties$feats)
NULL
length(hatties$feats)
[1] 16
The names of the feats
lapply(hatties$feats, function(x) names(x))
[[1]]
[1] "id" "created_at"
[3] "updated_at" "accomplished_vs"
[5] "accomplishment" "actual"
[7] "category" "game_id"
[9] "humanized_stat_type" "level"
[11] "name" "opponent_abbrev"
[13] "opponent_location" "opponent_name"
[15] "opponent_nickname" "sentence"
[17] "sentence_vs" "subject_id"
[19] "subject_name" "subject_team_name"
[21] "subject_team_abbrev" "subject_team_location"
[23] "subject_team_nickname" "subject_type"
[25] "verb" "vs"
[27] "subject"
[[2]]
[1] "id" "created_at"
[3] "updated_at" "accomplished_vs"
[5] "accomplishment" "actual"
[7] "category" "game_id"
[9] "humanized_stat_type" "level"
[11] "name" "opponent_abbrev"
[13] "opponent_location" "opponent_name"
[15] "opponent_nickname" "sentence"
[17] "sentence_vs" "subject_id"
[19] "subject_name" "subject_team_name"
[21] "subject_team_abbrev" "subject_team_location"
[23] "subject_team_nickname" "subject_type"
[25] "verb" "vs"
[27] "subject"
[[3]]
[1] "id" "created_at"
[3] "updated_at" "accomplished_vs"
[5] "accomplishment" "actual"
[7] "category" "game_id"
[9] "humanized_stat_type" "level"
[11] "name" "opponent_abbrev"
[13] "opponent_location" "opponent_name"
[15] "opponent_nickname" "sentence"
[17] "sentence_vs" "subject_id"
[19] "subject_name" "subject_team_name"
[21] "subject_team_abbrev" "subject_team_location"
[23] "subject_team_nickname" "subject_type"
[25] "verb" "vs"
[27] "subject"
[[4]]
[1] "id" "created_at"
[3] "updated_at" "accomplished_vs"
[5] "accomplishment" "actual"
[7] "category" "game_id"
[9] "humanized_stat_type" "level"
[11] "name" "opponent_abbrev"
[13] "opponent_location" "opponent_name"
[15] "opponent_nickname" "sentence"
[17] "sentence_vs" "subject_id"
[19] "subject_name" "subject_team_name"
[21] "subject_team_abbrev" "subject_team_location"
[23] "subject_team_nickname" "subject_type"
[25] "verb" "vs"
[27] "subject"
[[5]]
[1] "id" "created_at"
[3] "updated_at" "accomplished_vs"
[5] "accomplishment" "actual"
[7] "category" "game_id"
[9] "humanized_stat_type" "level"
[11] "name" "opponent_abbrev"
[13] "opponent_location" "opponent_name"
[15] "opponent_nickname" "sentence"
[17] "sentence_vs" "subject_id"
[19] "subject_name" "subject_team_name"
[21] "subject_team_abbrev" "subject_team_location"
[23] "subject_team_nickname" "subject_type"
[25] "verb" "vs"
[27] "subject"
[[6]]
[1] "id" "created_at"
[3] "updated_at" "accomplished_vs"
[5] "accomplishment" "actual"
[7] "category" "game_id"
[9] "humanized_stat_type" "level"
[11] "name" "opponent_abbrev"
[13] "opponent_location" "opponent_name"
[15] "opponent_nickname" "sentence"
[17] "sentence_vs" "subject_id"
[19] "subject_name" "subject_team_name"
[21] "subject_team_abbrev" "subject_team_location"
[23] "subject_team_nickname" "subject_type"
[25] "verb" "vs"
[27] "subject"
[[7]]
[1] "id" "created_at"
[3] "updated_at" "accomplished_vs"
[5] "accomplishment" "actual"
[7] "category" "game_id"
[9] "humanized_stat_type" "level"
[11] "name" "opponent_abbrev"
[13] "opponent_location" "opponent_name"
[15] "opponent_nickname" "sentence"
[17] "sentence_vs" "subject_id"
[19] "subject_name" "subject_team_name"
[21] "subject_team_abbrev" "subject_team_location"
[23] "subject_team_nickname" "subject_type"
[25] "verb" "vs"
[27] "subject"
[[8]]
[1] "id" "created_at"
[3] "updated_at" "accomplished_vs"
[5] "accomplishment" "actual"
[7] "category" "game_id"
[9] "humanized_stat_type" "level"
[11] "name" "opponent_abbrev"
[13] "opponent_location" "opponent_name"
[15] "opponent_nickname" "sentence"
[17] "sentence_vs" "subject_id"
[19] "subject_name" "subject_team_name"
[21] "subject_team_abbrev" "subject_team_location"
[23] "subject_team_nickname" "subject_type"
[25] "verb" "vs"
[27] "subject"
[[9]]
[1] "id" "created_at"
[3] "updated_at" "accomplished_vs"
[5] "accomplishment" "actual"
[7] "category" "game_id"
[9] "humanized_stat_type" "level"
[11] "name" "opponent_abbrev"
[13] "opponent_location" "opponent_name"
[15] "opponent_nickname" "sentence"
[17] "sentence_vs" "subject_id"
[19] "subject_name" "subject_team_name"
[21] "subject_team_abbrev" "subject_team_location"
[23] "subject_team_nickname" "subject_type"
[25] "verb" "vs"
[27] "subject"
[[10]]
[1] "id" "created_at"
[3] "updated_at" "accomplished_vs"
[5] "accomplishment" "actual"
[7] "category" "game_id"
[9] "humanized_stat_type" "level"
[11] "name" "opponent_abbrev"
[13] "opponent_location" "opponent_name"
[15] "opponent_nickname" "sentence"
[17] "sentence_vs" "subject_id"
[19] "subject_name" "subject_team_name"
[21] "subject_team_abbrev" "subject_team_location"
[23] "subject_team_nickname" "subject_type"
[25] "verb" "vs"
[27] "subject"
[[11]]
[1] "id" "created_at"
[3] "updated_at" "accomplished_vs"
[5] "accomplishment" "actual"
[7] "category" "game_id"
[9] "humanized_stat_type" "level"
[11] "name" "opponent_abbrev"
[13] "opponent_location" "opponent_name"
[15] "opponent_nickname" "sentence"
[17] "sentence_vs" "subject_id"
[19] "subject_name" "subject_team_name"
[21] "subject_team_abbrev" "subject_team_location"
[23] "subject_team_nickname" "subject_type"
[25] "verb" "vs"
[27] "subject"
[[12]]
[1] "id" "created_at"
[3] "updated_at" "accomplished_vs"
[5] "accomplishment" "actual"
[7] "category" "game_id"
[9] "humanized_stat_type" "level"
[11] "name" "opponent_abbrev"
[13] "opponent_location" "opponent_name"
[15] "opponent_nickname" "sentence"
[17] "sentence_vs" "subject_id"
[19] "subject_name" "subject_team_name"
[21] "subject_team_abbrev" "subject_team_location"
[23] "subject_team_nickname" "subject_type"
[25] "verb" "vs"
[27] "subject"
[[13]]
[1] "id" "created_at"
[3] "updated_at" "accomplished_vs"
[5] "accomplishment" "actual"
[7] "category" "game_id"
[9] "humanized_stat_type" "level"
[11] "name" "opponent_abbrev"
[13] "opponent_location" "opponent_name"
[15] "opponent_nickname" "sentence"
[17] "sentence_vs" "subject_id"
[19] "subject_name" "subject_team_name"
[21] "subject_team_abbrev" "subject_team_location"
[23] "subject_team_nickname" "subject_type"
[25] "verb" "vs"
[27] "subject"
[[14]]
[1] "id" "created_at"
[3] "updated_at" "accomplished_vs"
[5] "accomplishment" "actual"
[7] "category" "game_id"
[9] "humanized_stat_type" "level"
[11] "name" "opponent_abbrev"
[13] "opponent_location" "opponent_name"
[15] "opponent_nickname" "sentence"
[17] "sentence_vs" "subject_id"
[19] "subject_name" "subject_team_name"
[21] "subject_team_abbrev" "subject_team_location"
[23] "subject_team_nickname" "subject_type"
[25] "verb" "vs"
[27] "subject"
[[15]]
[1] "id" "created_at"
[3] "updated_at" "accomplished_vs"
[5] "accomplishment" "actual"
[7] "category" "game_id"
[9] "humanized_stat_type" "level"
[11] "name" "opponent_abbrev"
[13] "opponent_location" "opponent_name"
[15] "opponent_nickname" "sentence"
[17] "sentence_vs" "subject_id"
[19] "subject_name" "subject_team_name"
[21] "subject_team_abbrev" "subject_team_location"
[23] "subject_team_nickname" "subject_type"
[25] "verb" "vs"
[27] "subject"
[[16]]
[1] "id" "created_at"
[3] "updated_at" "accomplished_vs"
[5] "accomplishment" "actual"
[7] "category" "game_id"
[9] "humanized_stat_type" "level"
[11] "name" "opponent_abbrev"
[13] "opponent_location" "opponent_name"
[15] "opponent_nickname" "sentence"
[17] "sentence_vs" "subject_id"
[19] "subject_name" "subject_team_name"
[21] "subject_team_abbrev" "subject_team_location"
[23] "subject_team_nickname" "subject_type"
[25] "verb" "vs"
[27] "subject"
The first entry
lapply(hatties$feats[[1]], function(x) x)
$id
[1] "64b86c0f-f103-43f4-b5fe-7c2b79edbc24"
$created_at
[1] "2015-11-30T07:02:19Z"
$updated_at
[1] "2015-11-30T07:02:19Z"
$accomplished_vs
[1] "had 3 hat trick goals vs. the Senators"
$accomplishment
[1] "had 3 hat trick goals"
$actual
[1] "3.0"
$category
[1] "single"
$game_id
[1] "852c15d4-2791-438f-855e-d3d3e2826d57"
$humanized_stat_type
[1] "hat trick goals"
$level
[1] "rare"
$name
[1] "hat_trick_goals"
$opponent_abbrev
[1] "OTT"
$opponent_location
[1] "Ottawa"
$opponent_name
[1] "Ottawa"
$opponent_nickname
[1] "Senators"
$sentence
[1] "Mikkel Boedker had 3 hat trick goals"
$sentence_vs
[1] "Mikkel Boedker had 3 hat trick goals vs. the Senators"
$subject_id
[1] "12fefa4f-464a-4823-aa22-25abb755c214"
$subject_name
[1] "Mikkel Boedker"
$subject_team_name
[1] "Arizona"
$subject_team_abbrev
[1] "ARI"
$subject_team_location
[1] "Arizona"
$subject_team_nickname
[1] "Coyotes"
$subject_type
[1] "Player"
$verb
[1] "had 3 hat trick goals"
$vs
[1] "vs. the Senators"
$subject
$subject$type
[1] "player"
$subject$id
[1] "12fefa4f-464a-4823-aa22-25abb755c214"
From the link on pagination, I realized that I need to tweak the function from above to look at the headers.
A quick call to view the headers
URL = "https://www.stattleship.com/hockey/nhl/feats"
ACCEPT = "application/vnd.stattleship.com; version=1"
tmp = GET(URL,
add_headers(Authorization =TOKEN, Accept = ACCEPT, `Content-Type`="application/json"),
query=list(feat="hat_trick_goals"))
tmp$headers
$server
[1] "Cowboy"
$connection
[1] "keep-alive"
$`x-frame-options`
[1] "SAMEORIGIN"
$`x-xss-protection`
[1] "1; mode=block"
$`x-content-type-options`
[1] "nosniff"
$`cache-control`
[1] "public, no-cache"
$`surrogate-control`
[1] "max-age=2592000"
$link
[1] "<https://www.stattleship.com/hockey/nhl/feats?feat=hat_trick_goals&page=7194>; rel=\"last\", <https://www.stattleship.com/hockey/nhl/feats?feat=hat_trick_goals&page=2>; rel=\"next\""
$total
[1] "16"
$`per-page`
[1] "20"
$`surrogate-key`
[1] "feats feat_statistics/9a8437bb-d8ec-4108-8754-c455d1a9d974 feat_statistics/b15e93b9-3656-4f25-85a4-0da678242743 feat_statistics/05455b48-8ab4-41ef-814c-d0468508a08d feat_statistics/71ef279f-66ca-4bc9-899e-d5471822e4c9 feat_statistics/02105879-8b5c-4dd7-a5e3-77b4d8566948 feat_statistics/8bf26d9c-9c28-47cd-9a3c-1e5a95a58706 feat_statistics/c5408709-2db1-4ca9-9ab1-c274cbe994ca feat_statistics/11db27af-a69d-4163-bc5a-639f5e3ca828 feat_statistics/0bf49abb-e86f-41e0-90c0-4ed6b455ddad feat_statistics/c5cde023-5cab-4301-b0c9-797dd5a338e5 feat_statistics/de229976-0fde-4b60-90b4-00f6bc1e83a2 feat_statistics/8287e495-e5a9-4ff1-9219-7e9a27445146 feat_statistics/d461615d-00a2-4f58-8305-5ead4d4abdf3 feat_statistics/f4950d08-8cb4-4701-994c-a4c5fda2f40e feat_statistics/daa6e1ea-0d3e-4b4b-ac92-668dce251347 feat_statistics/3d6bfec4-c47f-4035-bad3-79ba3a0a30ca feat_statistics/de800980-9961-4930-bdcf-0f31c4419da5 feat_statistics/965bccf2-a88f-4f0e-8bfb-539df58799ab feat_statistics/4bd7b29d-7617-4780-a32d-f829375fad4a feat_statistics/f6e1fc7f-c39b-47fe-87f8-4aaa357dea34"
$`content-type`
[1] "application/json; charset=utf-8"
$vary
[1] "Accept-Encoding"
$`content-encoding`
[1] "gzip"
$`x-request-id`
[1] "ff987f95-082a-419d-918a-43d7324a3b34"
$`x-runtime`
[1] "2.072294"
$date
[1] "Thu, 03 Dec 2015 16:17:19 GMT"
$`x-rack-cache`
[1] "miss"
$`strict-transport-security`
[1] "max-age=31536000"
$`transfer-encoding`
[1] "chunked"
$via
[1] "1.1 vegur"
attr(,"class")
[1] "insensitive" "list"
as I get deeper, need to think about how to handle that significantly better than I currently am.
Poke around with the injury report
injuries = queryAPI(BODY = NA, TOKEN, ep="injuries")
What came back
names(injuries)
[1] "players" "seasons" "leagues" "teams" "injuries"
length(injuries)
[1] 5
Look at the first player entry
injuries$players[[1]]
$id
[1] "be23f099-06f1-49b6-a16b-5741f34081e5"
$created_at
[1] "2015-11-30T06:36:09Z"
$updated_at
[1] "2015-11-30T06:36:09Z"
$active
[1] FALSE
$defensive
[1] FALSE
$first_name
[1] "Zach"
$last_name
[1] "Kassian"
$name
[1] "Zach Kassian"
$offensive
[1] FALSE
$position_abbreviation
[1] "U"
$position_name
[1] "Unknown"
$slug
[1] "nhl-zach-kassian"
$sport
[1] "hockey"
$team_id
[1] "80d99c5a-882e-4296-ae9d-048d2830b154"
dive into the injuries list
injuries$injuries[[1]]
$id
[1] "e98a6460-f107-4861-96e4-dbb12d045958"
$created_at
[1] "2015-12-03T05:30:44Z"
$updated_at
[1] "2015-12-03T05:30:44Z"
$location_name
[1] "Spine"
$started_on
[1] "2015-09-17"
$status_updated_at
[1] "2015-09-17T15:31:33Z"
$note
[1] "Horton is dealing with a degenerative spine issue and it is unlikely that he will play hockey again."
$status
[1] "out"
$status_label
[1] "Out indefinitely"
$player_id
NULL
$season_id
[1] "301759de-976d-4daa-a194-cacea1dc02ca"
$team_id
[1] "2d8d4fda-a9b9-4978-abcc-31b9dfb47175"
player_id be populated?The basic setup....
options(stringsAsFactors=F)
## remove the ##
knitr::opts_chunk$set(comment = NA)
## non-cran package to parse json into dataframes
# devtools::install_github("sailthru/tidyjson")
## https://github.com/sailthru/tidyjson
## load the packages
library(httr)
suppressPackageStartupMessages(library(dplyr))
library(tidyjson)
## my token
TOKEN = "9a4b9dc1a4d21eacb566f672c3c662b3"
queryAPI = function(BODY = NA, TOKEN, version=1, ep = "stats") {
## BODY is a list, e.g. list(stat="hits",team_id="bos")
URL = sprintf("https://www.stattleship.com/hockey/nhl/%s", ep)
ACCEPT = sprintf("application/vnd.stattleship.com; version=%d", version)
## test the body
if (is.na(BODY)) {
BODY = list()
}
resp = GET(URL,
add_headers(Authorization =TOKEN,
Accept = ACCEPT,
`Content-Type`="application/json"),
query=BODY)
api_response = content(resp)
return(api_response)
}
queryAPI_verbose = function(BODY = NA, TOKEN, version=1, ep = "stats") {
## BODY is a list, e.g. list(stat="hits",team_id="bos")
URL = sprintf("https://www.stattleship.com/hockey/nhl/%s", ep)
ACCEPT = sprintf("application/vnd.stattleship.com; version=%d", version)
## test the body
if (is.na(BODY)) {
BODY = list()
}
resp = GET(URL,
add_headers(Authorization =TOKEN,
Accept = ACCEPT,
`Content-Type`="application/json"),
query=BODY)
api_response = content(resp)
## return a list of the response, and the parsed content seperately
## overkill but easy
return(list(response = resp,
api_json = api_response))
}
q_body = list(player_id="nhl-john-scott")
scott = queryAPI(BODY=q_body, TOKEN, ep="players")
scott_verbose = queryAPI_verbose(BODY=q_body, TOKEN, ep="players")
names(scott)
[1] "teams" "players"
names(scott$players)
NULL
And the names of the first element
names(scott$players[[1]])
[1] "id" "created_at"
[3] "updated_at" "active"
[5] "defensive" "first_name"
[7] "last_name" "name"
[9] "offensive" "position_abbreviation"
[11] "position_name" "slug"
[13] "sport" "team_id"
How many elements?
length(scott$players)
[1] 20
Inspect the first element
scott$players[[1]]
$id
[1] "85ca490e-589f-4146-9321-8783e78f564d"
$created_at
[1] "2015-11-30T06:00:20Z"
$updated_at
[1] "2015-12-04T03:27:40Z"
$active
[1] TRUE
$defensive
[1] FALSE
$first_name
[1] "Justin"
$last_name
[1] "Abdelkader"
$name
[1] "Justin Abdelkader"
$offensive
[1] TRUE
$position_abbreviation
[1] "U"
$position_name
[1] "Unknown"
$slug
[1] "nhl-justin-abdelkader"
$sport
[1] "hockey"
$team_id
[1] "c2a7d98a-fa2c-446e-9682-a8949854023e"
Not John Scott??
If I remove the query body, perhaps this is how we get players?
players = queryAPI(BODY=q_body, TOKEN, ep="players")
names(players)
[1] "teams" "players"
length(players$players)
[1] 20
names(players$players[[1]])
[1] "id" "created_at"
[3] "updated_at" "active"
[5] "defensive" "first_name"
[7] "last_name" "name"
[9] "offensive" "position_abbreviation"
[11] "position_name" "slug"
[13] "sport" "team_id"
Go through the player slugs
lapply(players$players, function(x) x$slug)
[[1]]
[1] "nhl-justin-abdelkader"
[[2]]
[1] "nhl-pontus-aberg"
[[3]]
[1] "nhl-sena-acolatse"
[[4]]
[1] "nhl-luke-adam"
[[5]]
[1] "nhl-kenny-agostino"
[[6]]
[1] "nhl-andrew-agozzino"
[[7]]
[1] "nhl-jason-akeson"
[[8]]
[1] "nhl-conor-allen"
[[9]]
[1] "nhl-jake-allen"
[[10]]
[1] "nhl-karl-alzner"
[[11]]
[1] "nhl-seth-ambroz"
[[12]]
[1] "nhl-frederik-andersen"
[[13]]
[1] "nhl-niclas-andersen"
[[14]]
[1] "nhl-craig-anderson"
[[15]]
[1] "nhl-josh-anderson"
[[16]]
[1] "nhl-joakim-andersson"
[[17]]
[1] "nhl-andy-andreoff"
[[18]]
[1] "nhl-sven-andrighetto"
[[19]]
[1] "nhl-mike-angelidis"
[[20]]
[1] "nhl-artem-anisimov"
q_body = list(player_id="nhl-john-scott")
scott_verbose = queryAPI_verbose(BODY=q_body, TOKEN, ep="stats")
look at it
stats = scott_verbose$api_json
names(stats)
[1] "stats"
length(stats$feats); length(stats$stats)
[1] 0
[1] 20
print the request
scott_verbose$response$request
<request>
GET https://www.stattleship.com/hockey/nhl/stats?player_id=nhl-john-scott
Output: write_memory
Options:
* useragent: libcurl/7.30.0 r-curl/0.9.3 httr/1.0.0
* customrequest: GET
Headers:
* Authorization: 9a4b9dc1a4d21eacb566f672c3c662b3
* Accept: application/vnd.stattleship.com; version=1
* Content-Type: application/json
print the headers
scott_verbose$response$all_headers
[[1]]
[[1]]$status
[1] 200
[[1]]$version
[1] "HTTP/1.1"
[[1]]$headers
$server
[1] "Cowboy"
$connection
[1] "keep-alive"
$`x-frame-options`
[1] "SAMEORIGIN"
$`x-xss-protection`
[1] "1; mode=block"
$`x-content-type-options`
[1] "nosniff"
$`cache-control`
[1] "public, no-cache"
$`surrogate-control`
[1] "max-age=2592000"
$link
[1] "<https://www.stattleship.com/hockey/nhl/stats?page=7327&player_id=nhl-john-scott>; rel=\"last\", <https://www.stattleship.com/hockey/nhl/stats?page=2&player_id=nhl-john-scott>; rel=\"next\""
$total
[1] "146521"
$`per-page`
[1] "20"
$`surrogate-key`
[1] "feat_statistics feat_statistics/9a8437bb-d8ec-4108-8754-c455d1a9d974 feat_statistics/b15e93b9-3656-4f25-85a4-0da678242743 feat_statistics/05455b48-8ab4-41ef-814c-d0468508a08d feat_statistics/71ef279f-66ca-4bc9-899e-d5471822e4c9 feat_statistics/02105879-8b5c-4dd7-a5e3-77b4d8566948 feat_statistics/8bf26d9c-9c28-47cd-9a3c-1e5a95a58706 feat_statistics/c5408709-2db1-4ca9-9ab1-c274cbe994ca feat_statistics/11db27af-a69d-4163-bc5a-639f5e3ca828 feat_statistics/0bf49abb-e86f-41e0-90c0-4ed6b455ddad feat_statistics/c5cde023-5cab-4301-b0c9-797dd5a338e5 feat_statistics/de229976-0fde-4b60-90b4-00f6bc1e83a2 feat_statistics/8287e495-e5a9-4ff1-9219-7e9a27445146 feat_statistics/d461615d-00a2-4f58-8305-5ead4d4abdf3 feat_statistics/f4950d08-8cb4-4701-994c-a4c5fda2f40e feat_statistics/daa6e1ea-0d3e-4b4b-ac92-668dce251347 feat_statistics/3d6bfec4-c47f-4035-bad3-79ba3a0a30ca feat_statistics/de800980-9961-4930-bdcf-0f31c4419da5 feat_statistics/965bccf2-a88f-4f0e-8bfb-539df58799ab feat_statistics/4bd7b29d-7617-4780-a32d-f829375fad4a feat_statistics/f6e1fc7f-c39b-47fe-87f8-4aaa357dea34"
$`content-type`
[1] "application/json; charset=utf-8"
$vary
[1] "Accept-Encoding"
$`content-encoding`
[1] "gzip"
$`x-request-id`
[1] "14b1ee59-116d-4860-844a-cda580deedb4"
$`x-runtime`
[1] "1.577070"
$date
[1] "Sat, 05 Dec 2015 01:12:58 GMT"
$`x-rack-cache`
[1] "miss"
$`strict-transport-security`
[1] "max-age=31536000"
$`transfer-encoding`
[1] "chunked"
$via
[1] "1.1 vegur"
attr(,"class")
[1] "insensitive" "list"
Look at the first feats
stats$feats[[1]]
NULL
Look at the first stats entry
stats$stats[[1]]
$id
[1] "9a8437bb-d8ec-4108-8754-c455d1a9d974"
$created_at
[1] "2015-11-30T06:18:25Z"
$updated_at
[1] "2015-11-30T06:18:25Z"
$stat
[1] "time_on_ice_secs"
$statistic_type
[1] "HockeyPlayerStat"
$actual
[1] "3900.0"
$feat_id
[1] "ecc0c8df-3533-4302-a6b7-9d0b897ee027"