Main Content

statsllc

STATS.com connection

Description

The statsllc function creates a statsllc object. The statsllc object represents a STATS.com connection.

After you create a statsllc object, you can use the object functions to retrieve athlete, team, and event data. You can retrieve data for the sport and time period that you have access to using your credentials. The credentials consist of an API key and secret pass code. To retrieve data for different athletes, teams, events, and time periods, specify query parameters. For credentials, contact STATS.com. For all available query parameters, see STATS Developer Center I/O Docs.

Creation

Description

example

c = statsllc(apikey,secret) creates a STATS.com connection object using an API key and secret pass code. This syntax does not set the properties of the connection object. To retrieve data with a custom URL, use this syntax with fetchUrl. To retrieve data without a custom URL, use this syntax, set the object properties, and run fetch.

example

c = statsllc(apikey,secret,QueryName1,QueryValue1,...,QueryNameN,QueryValueN) creates a STATS.com connection using web service query parameters, as specified by one or more name-value pair arguments. The STATS.com web service defines the query parameters. For details, see STATS Developer Center I/O Docs. To retrieve data, use this syntax with fetch.

Input Arguments

expand all

STATS.com API key, specified as a character vector or string scalar. To request your API key, contact STATS.com.

Data Types: char | string

STATS.com secret pass code, specified as a character vector or string scalar. To request your secret pass code, contact STATS.com.

Data Types: char | string

Web service query parameters, specified as one or more pairs of name-value arguments. A QueryName argument is a character vector or string scalar that specifies the name of the query parameter. A QueryValue argument is a character vector or string scalar that specifies the value of the query parameter.

The web service defines name-value pairs that it accepts as part of a request. For valid name-value pairs, see STATS Developer Center I/O Docs. To understand which name-value pairs you have access to, check your license or contact STATS.com.

Example: 'DataType','stats','LeagueAbbreviation','mlb','Resource','standings','SportName','baseball','VersionNumber','v1' retrieves the standings for the current or most recent baseball season.

Data Types: char | string

Properties

expand all

STATS.com type of data, specified as a character vector.

The type 'stats' means statistical data. The type 'optical' means spatial data derived from video recordings. For other types of data, contact STATS.com.

Data Types: char

Abbreviation for a sports league name, specified as a character vector.

Example: 'mlb'

Data Types: char

Player or team identifier, specified as a character vector.

Example: '548033'

Data Types: char

Type of information to request, specified as a character vector.

To request data for games, specify 'events'. To request statistical data for a player, specify 'stats/players'. For other resources, contact STATS.com.

Data Types: char

Sport name, specified as a character vector.

Example: 'baseball'

Data Types: char

URL, specified as a character vector. STATS.com uses a custom-built URL to make the data request. For details about the URL, contact STATS.com.

The base URL stub for creating the web request is 'http://api.stats.com'.

Data Types: char

STATS.com version number, specified as a character vector. For details about the STATS.com version number, contact STATS.com.

Example: 'v1'

Data Types: char

Object Functions

fetchRetrieve data from STATS.com
fetchUrlRetrieve data from STATS.com with URL

Examples

collapse all

Create a STATS.com connection by using credentials, and then retrieve basketball statistics for individual players.

Connect to STATS.com using an API key and secret pass code. c is the STATS.com connection object.

apikey = 'gkfrq6fabcfehmn2yctrc6j5';
secret = 'aBC5cuBQgc';

c = statsllc(apikey,secret)
c = 

  statsllc with properties:

              DataType: []
    LeagueAbbreviation: []
                Method: []
              Resource: []
             SportName: []
                   URL: 'http://api.stats.com'
         VersionNumber: []

Retrieve basketball statistics for individual players in the sport league named 'nba'. To specify the statistics for retrieval, create a URL suffix.

urlsuffix = '/v1/stats/basketball/nba/participants';

d = fetchUrl(c,urlsuffix);

d contains statistical basketball data for individual players. For details about data retrieval, see fetchUrl.

Retrieving data from STATS.com indicates a successful connection.

Create a STATS.com connection by setting object properties, and then retrieve basketball team data.

Connect to STATS.com using an API key and secret pass code. c is the STATS.com connection object.

apikey = 'gkfrq6fabcfehmn2yctrc6j5';
secret = 'aBC5cuBQgc';

c = statsllc(apikey,secret)
c = 

  statsllc with properties:

              DataType: []
    LeagueAbbreviation: []
                Method: []
              Resource: []
             SportName: []
                   URL: 'http://api.stats.com'
         VersionNumber: []

Set the object properties in sBasketball to create a specific data request. Specify statistical standings data for basketball teams in the sport league named 'nba'.

c.DataType = 'stats';
c.LeagueAbbreviation = 'nba';
c.Resource = 'standings';
c.SportName = 'basketball';
c.VersionNumber = 'v1';

Retrieve basketball team data using the STATS.com connection c.

d = fetch(c);

d contains statistical basketball data for individual players. For details about data retrieval, see fetch.

Retrieving data from STATS.com indicates a successful connection.

Create a STATS.com connection using query parameters, and then retrieve basketball team data for a season.

Connect to STATS.com using an API key and secret pass code. Specify statistical standings data for basketball teams in the sport league named 'nba' using query parameters. c is the STATS.com connection object.

apikey = 'gkfrq6fabcfehmn2yctrc6j5';
secret = 'aBC5cuBQgc';

c = statsllc(apikey,secret, ...
    'DataType','stats','LeagueAbbreviation','nba', ...
    'Resource','standings','SportName','basketball', ...
    'VersionNumber','v1')
c = 

  statsllc with properties:

              DataType: 'stats'
    LeagueAbbreviation: 'nba'
                Method: []
              Resource: 'standings'
             SportName: 'basketball'
                   URL: 'http://api.stats.com'
         VersionNumber: 'v1'

Retrieve the basketball team data for the 2015 season.

d = fetch(c,'season','2015');

d contains statistical basketball data for individual players. For details about data retrieval, see fetch.

Retrieving data from STATS.com indicates a successful connection.

Introduced in R2016b