The api() method is the low-level interface for all Yahoo Fantasy API calls. It handles URL construction, parameter encoding (defaulting to format=json), and automatic token refreshing.
Signature: api(method, url, [postData])
method: HTTP method ('GET' or 'POST').url: The full Yahoo API URL (e.g., https://fantasysports.yahooapis.com/fantasy/v2/...).postData (optional): The body for POST requests.
Note on Authentication: If yahooUserToken is set, it uses Bearer token authentication. If not set, it falls back to OAuth 1.0a signature generation using the consumer credentials.
// Example GET request
const data = await client.api('GET', 'https://fantasysports.yahooapis.com/fantasy/v2/games/nfl/summaries?format=json');
// Example POST request
const postData = { key: 'value' };
const result = await client.api('POST', 'https://fantasysports.yahooapis.com/fantasy/v2/some/endpoint', postData);