stattleship / stattleship-r

Stattleship R Wrapper
https://api.stattleship.com/
MIT License
48 stars 14 forks source link

Tanya - Fix for single results, no pages #19

Closed tcash21 closed 8 years ago

tcash21 commented 8 years ago

This is a fix for total stats queries such as this:

league <- "nfl"
sport <- "football"
ep <- 'total_stats'
q_body <- list(player_id = 'nfl-kenny-stills', stat='receptions_total', type='football_passing_stat')
total_stats <- ss_get_result(sport=sport, league=league, ep=ep, query=q_body, version=1, verbose=TRUE, walk=TRUE)

Accomplished this by checking for existence of the link attribute in the header response. Walking the results is skipped if link does not exist.

Btibert3 commented 8 years ago

Was the latest PR from master? I hit an error on the code below, but got around it after installing from current.

options(stringsAsFactors = FALSE)

## remove old package from previous branch
remove.packages("stattleshipR")

## install Tanya's PR
devtools::install_github("stattleship/stattleship-r", ref="tanya-testthat")

## load libraries
library(stattleshipR)
library(dplyr)

## set token
set_token(Sys.getenv("STATTLE_TOKEN"))

## test the sport will but put into proper case
## this should run
sport <- "HOCKEY"
sport <- ss_get_result(sport=sport)

Below I am going to remove that version, and install master and run the same check.

## is this off of the master branch?
remove.packages("stattleshipR")

## install the master branch
devtools::install_github("stattleship/stattleship-r")

## re-run the test
set_token(Sys.getenv("STATTLE_TOKEN"))
sport <- "HOCKEY"
sport <- ss_get_result(sport=sport)

## verify
sport[[1]]$teams