toddrob99 / MLB-StatsAPI

Python wrapper for MLB Stats API
GNU General Public License v3.0
539 stars 100 forks source link

default current year for draft endpoint #126

Closed Msa360 closed 12 months ago

Msa360 commented 1 year ago

Checks if we are passed the draft month (July) and if not puts the previous year, else the current year.

toddrob99 commented 12 months ago

Thank you for the contribution, but I don't think it's quite that simple. This library could be used in applications that are running constantly without being restarted. If the year is defaulted in the endpoint definition, it will only be set once when the library is loaded. If the application is running through July and into August, the year in the endpoint definition would not be updated to the next year.

However, I found two things while I was looking into this.

  1. There was a bug in the URL builder logic, and the leading slash was not being added when the default year was being inserted. This was resulting in the URL being https://statsapi.mlb.com/api/v1/draft2019 and throwing an error. I am fixing the logic to include leading and trailing slashes even when default path parameter values are used.
  2. The best default appears to be "" (empty string). The API will default to the current year (currently defaulting to 2023). In order to allow a blank default, I am updating the parameter to not be required (the URL builder logic does not allow an empty string for a required parameter).

I am going to close this pull request, and release these two changes in v1.7. Thank you!