Documentation

This is machine translation

Translated by Microsoft
Mouseover text to see original. Click the button below to return to the English verison of the page.

Note: This page has been translated by MathWorks. Please click here
To view all translated materals including this page, select Japan from the country navigator on the bottom of this page.

fetchUrl

Retrieve data from STATS.com with URL

Syntax

d = fetchUrl(c,urlsuffix)

Description

example

d = fetchUrl(c,urlsuffix) returns STATS.com data using the STATS.com connection c and a custom URL suffix.

Examples

collapse all

Connect to STATS.com using an API key and secret pass code.

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

sBasketball = statsllc(apikey,secret);

sBasketball is the STATS.com connection object. For each object property, see statsllc.

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(sBasketball,urlsuffix)
d = 

  struct with fields:

            status: 'OK'
       recordCount: 450
    startTimestamp: '2016-04-26T15:28:46.2203857Z'
      endTimestamp: '2016-04-26T15:28:46.892265Z'
         timeTaken: 0.6719
        apiResults: [1×1 struct]

STATS.com returns a structure d with these fields:

  • status — Web request status ('OK' denotes a successful web request)

  • recordCount — Number of records returned

  • startTimestamp — Start date and time of the web request

  • endTimestamp — End date and time of the web request

  • timeTaken — Amount of time taken for the web request to complete in seconds

  • apiResults — Returned data

Retrieve data about the first player in the league from the returned data d.apiResults. Access the nested structure to retrieve data.

d.apiResults.league.players{1}
ans = 

  struct with fields:

    isSuspended: 0
      isInjured: 1
     highSchool: [1×1 struct]
...

The structure result contains suspended status, injury status, and high school information along with other fields. For details about these fields, contact STATS.com.

For more data, continue to access the nested structures or structure arrays. For accessing nested structures, see Access Data in Nested Structures (MATLAB).

Input Arguments

collapse all

STATS.com connection, specified as a statsllc object.

URL suffix, specified as a character vector or string scalar. fetchUrl builds a custom URL by appending the URL suffix to the connection URL created using statsllc. The fetchUrl function uses the custom URL to retrieve STATS.com data. To compose the URL suffix, specify query parameter values. For query parameter values, see STATS Developer Center I/O Docs.

Example: '/v1/stats/baseball/mlb/participants' retrieves statistical data for individual baseball players in the sports league named 'mlb'

Data Types: char | string

Output Arguments

collapse all

STATS.com data, returned as a structure with these fields:

STATS.com Data Structure FieldDescription
status

Web request status ('OK' denotes a successful web request)

recordCount

Number of records returned

startTimestamp

Start date and time of the web request

endTimestamp

End date and time of the web request

timeTaken

Number of seconds to complete the web request

apiResults

Returned data

To retrieve individual or team athletic data, access the field apiResults in the structure. For example, enter:

d.apiResults
ans = 

  struct with fields:

    sportId: 1
       name: 'Basketball'
     league: [1×1 struct]

For more data, continue to access the structure fields that contain further data. For accessing nested structures, see Access Data in Nested Structures (MATLAB).

Introduced in R2016b

Was this topic helpful?