Skip to content

Commit

Permalink
V2 (#27)
Browse files Browse the repository at this point in the history
2.0.0 version of client
  • Loading branch information
jaebradley authored May 13, 2019
2 parents 37b962c + 3889aa3 commit 9c4f5b2
Show file tree
Hide file tree
Showing 55 changed files with 5,012 additions and 1,361 deletions.
14 changes: 8 additions & 6 deletions .travis.yml
Original file line number Diff line number Diff line change
@@ -1,10 +1,12 @@
language: python
python:
- "2.7"
# command to install dependencies
install: "pip install -r requirements.txt"
# command to run tests
- "3.6"
- "3.6-dev"
- "3.7-dev"
install:
- pip install -r requirements.txt
script:
- nosetests --with-coverage # Add me to run nose with coverage
- pip install -e .
- pytest --cov=./
after_success:
- coveralls
- codecov
21 changes: 21 additions & 0 deletions LICENSE
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
MIT License

Copyright (c) 2019 Jae Bradley

Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
in the Software without restriction, including without limitation the rights
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
copies of the Software, and to permit persons to whom the Software is
furnished to do so, subject to the following conditions:

The above copyright notice and this permission notice shall be included in all
copies or substantial portions of the Software.

THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
SOFTWARE.
33 changes: 13 additions & 20 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -16,61 +16,54 @@ with relevant metadata.
### Get Contests for a Sport

```python
from draftkings_client import DraftKingsClient, Sport
from draft_kings.client import contests, Sport

DraftKingsClient.get_contests(sport=Sport.nba)
contests(sport=Sport.nba)
```

### Get Available Players for a Draft Group

```python
from draftkings_client import DraftKingsClient
from draft_kings.client import available_players

return DraftKingsClient.get_available_players(draft_group_id=1)
return available_players(draft_group_id=1)
```

### Get Draft Group Details

```python
from draftkings_client import DraftKingsClient
from draft_kings.client import draft_group_details

return DraftKingsClient.get_draft_group_details(draft_group_id=1)
return draft_group_details(draft_group_id=1)
```

### Get Countries

Get all country information that DraftKings uses to make country-specific requests

```python
from draftkings_client import DraftKingsClient
from draft_kings.client import countries

return DraftKingsClient.get_countries(include_unlicensed=True)
return countries()
```

### Get Regions

Get all region information for the specified country code that DraftKings uses to make region-specific requests

```python
from draftkings_client import DraftKingsClient
from draft_kings.client import regions

return DraftKingsClient.get_regions(country_code='US')
return regions(country_code='US')
```

### Get Contest Details

```python
from draftkings_client import DraftKingsClient

return DraftKingsClient.get_contest_details(contest_id=1)
```

### Get Draftables

Get all draftable competitors
Get all draftable players

```python
from draftkings_client import DraftKingsClient
from draft_kings.client import draftables

return DraftKingsClient.get_draftables(draft_group_id=1)
return draftables(draft_group_id=1)
```
91 changes: 0 additions & 91 deletions README.rst

This file was deleted.

1 change: 1 addition & 0 deletions draft_kings/__init__.py
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@

80 changes: 80 additions & 0 deletions draft_kings/client.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,80 @@
import requests

from draft_kings import urls
from draft_kings.data import Sport
from draft_kings.response_translators import translate_players, translate_contests, translate_countries, \
translate_draft_group, translate_regions, translate_draftables

"""
The API takes a sport query parameter that's different than then sports API endpoint
"""
SPORT_TO_CONTESTS_QUERY_PARAMETER = {
Sport.NFL: "NFL",
Sport.NHL: "NHL",
Sport.NBA: "NBA",
Sport.CFL: "CFL",
Sport.COLLEGE_FOOTBALL: "CFB",
Sport.MIXED_MARTIAL_ARTS: "MMA",
Sport.NASCAR: "NAS",
Sport.SOCCER: "SOC",
Sport.EUROLEAGUE_BASKETBALL: "EL",
Sport.MLB: "MLB",
Sport.TENNIS: "TEN",
Sport.LEAGUE_OF_LEGENDS: "LOL",
Sport.GOLF: "GOLF",
Sport.COLLEGE_BASKETBALL: "CBB"
}


def contests(sport):
response = requests.get(url=urls.CONTESTS_URL,
params={'sport': SPORT_TO_CONTESTS_QUERY_PARAMETER[sport]})

response.raise_for_status()

return translate_contests(response=response.json())


def available_players(draft_group_id):
response = requests.get(url=urls.AVAILABLE_PLAYERS_URL,
params={'draftGroupId': draft_group_id})

response.raise_for_status()

return translate_players(response=response.json())


def draft_group_details(draft_group_id):
response = requests.get(url=urls.draft_group_url(draft_group_id),
params={'format': 'json'})

response.raise_for_status()

return translate_draft_group(response.json())


def countries():
response = requests.get(url=urls.COUNTRIES_URL,
params={'format': 'json'})

response.raise_for_status()

return translate_countries(response.json())


def regions(country_code):
response = requests.get(url=urls.regions_url(country_code),
params={'format': 'json'})

response.raise_for_status()

return translate_regions(response.json())


def draftables(draft_group_id):
response = requests.get(url=urls.draftables_url(draft_group_id),
params={'format': 'json'})

response.raise_for_status()

return translate_draftables(response.json())
40 changes: 40 additions & 0 deletions draft_kings/data.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,40 @@
from enum import Enum


class Sport(Enum):
NFL = "NFL"
NHL = "NHL"
NBA = "NBA"
NASCAR = "NASCAR"
SOCCER = "SOCCER"
GOLF = "GOLF"
CFL = "CFL"
COLLEGE_FOOTBALL = "COLLEGE FOOTBALL"
COLLEGE_BASKETBALL = "COLLEGE BASKETBALL"
MIXED_MARTIAL_ARTS = "MIXED MARTIAL ARTS"
EUROLEAGUE_BASKETBALL = "EUROLEAGUE BASKETBALL"
MLB = "MLB"
TENNIS = "TENNIS"
LEAGUE_OF_LEGENDS = "LEAGUE OF LEGENDS"
ARENA_FOOTBALL_LEAGUE = "ARENA FOOTBALL LEAGUE"

"""
https://api.draftkings.com/sites/US-DK/sports/v1/sports?format=json
"""
SPORT_ID_TO_SPORT = {
1: Sport.NFL,
2: Sport.MLB,
3: Sport.NHL,
4: Sport.NBA,
6: Sport.COLLEGE_BASKETBALL,
5: Sport.COLLEGE_FOOTBALL,
9: Sport.MIXED_MARTIAL_ARTS,
10: Sport.NASCAR,
11: Sport.LEAGUE_OF_LEGENDS,
12: Sport.SOCCER,
13: Sport.GOLF,
14: Sport.CFL,
15: Sport.EUROLEAGUE_BASKETBALL,
16: Sport.TENNIS,
17: Sport.ARENA_FOOTBALL_LEAGUE,
}
Loading

0 comments on commit 9c4f5b2

Please sign in to comment.