Skip to content
This repository has been archived by the owner on May 4, 2023. It is now read-only.

Commit

Permalink
Merge pull request #1 from trevorphillips/d3
Browse files Browse the repository at this point in the history
finalized d3 endpoints
  • Loading branch information
Trevor Phillips authored Nov 6, 2020
2 parents 0cd9cd6 + 98afbf3 commit 6e69a96
Show file tree
Hide file tree
Showing 12 changed files with 479 additions and 104 deletions.
2 changes: 0 additions & 2 deletions .github/workflows/python-package.yml
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,5 @@ jobs:
run: |
pytest
- name: Codecov Report
env:
CODECOV_TOKEN: ${{ secrets.CODECOV_TOKEN }}
run: |
bash <(curl -s https://codecov.io/bash)
3 changes: 3 additions & 0 deletions Makefile
Original file line number Diff line number Diff line change
@@ -1,3 +1,6 @@
devinstall:
pip install -r requirements.txt

clean:
rm -rf dist
rm -rf build
Expand Down
1 change: 1 addition & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ Current supported features include:
- Battle.net User
- WoW Profile
- WoW Game Data
- Diablo 3 Community
- Diablo 3 Game Data

To gain access to Blizzard's API please register [here](https://develop.battle.net/access/) to obtain a client id and client secret.
Expand Down
2 changes: 1 addition & 1 deletion blizzardapi/api.py
Original file line number Diff line number Diff line change
Expand Up @@ -82,6 +82,6 @@ def _format_oauth_url(self, resource, region):

return url

def get_oauth_resource(self, resource, region, query_params):
def get_oauth_resource(self, resource, region, query_params={}):
url = self._format_oauth_url(resource, region)
return self._request_handler(url, region, query_params)
5 changes: 2 additions & 3 deletions blizzardapi/battlenet/battlenet_oauth_api.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,3 @@
from urllib import parse

from ..api import Api


Expand All @@ -13,7 +11,8 @@ def __init__(self, client_id, client_secret):

def get_user_info(self, region, access_token):
"""
User Authentication - Returns basic information about the user associated with the current bearer token.
User Authentication - Returns basic information about the user
associated with the current bearer token.
"""
resource = "/oauth/userinfo"
query_params = {
Expand Down
2 changes: 2 additions & 0 deletions blizzardapi/diablo3/diablo3_api.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
from .diablo3_community_api import Diablo3CommunityApi
from .diablo3_game_data_api import Diablo3GameDataApi


class Diablo3Api:
def __init__(self, client_id, client_secret):
self.community = Diablo3CommunityApi(client_id, client_secret)
self.game_data = Diablo3GameDataApi(client_id, client_secret)
139 changes: 139 additions & 0 deletions blizzardapi/diablo3/diablo3_community_api.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,139 @@
from ..api import Api


class Diablo3CommunityApi(Api):
"""All Community API methods"""

def __init__(self, client_id, client_secret):
super().__init__(client_id, client_secret)

# D3 Act API

def get_act_index(self, region, locale):
"""
D3 Act API - Returns an index of acts.
"""
resource = "/d3/data/act"
query_params = {"locale": locale}
return super().get_resource(resource, region, query_params)

def get_act(self, region, locale, act_id):
"""
D3 Act API - Returns a single act by ID.
"""
resource = f"/d3/data/act/{act_id}"
query_params = {"locale": locale}
return super().get_resource(resource, region, query_params)

# D3 Artisan and Recipe API

def get_artisan(self, region, locale, artisan_slug):
"""
D3 Artisan and Recipe API - Returns a single artisan by slug.
"""
resource = f"/d3/data/artisan/{artisan_slug}"
query_params = {"locale": locale}
return super().get_resource(resource, region, query_params)

def get_recipe(self, region, locale, artisan_slug, recipe_slug):
"""
D3 Artisan and Recipe API - Returns a single recipe by slug for the
specified artisan.
"""
resource = f"/d3/data/artisan/{artisan_slug}/recipe/{recipe_slug}"
query_params = {"locale": locale}
return super().get_resource(resource, region, query_params)

# D3 Follower API

def get_follower(self, region, locale, follower_slug):
"""
D3 Follower API - Returns a single follower by slug.
"""
resource = f"/d3/data/follower/{follower_slug}"
query_params = {"locale": locale}
return super().get_resource(resource, region, query_params)

# D3 Character Class and Skill API

def get_character_class(self, region, locale, class_slug):
"""
D3 Character Class and Skill API - Returns a single character class by
slug.
"""
resource = f"/d3/data/hero/{class_slug}"
query_params = {"locale": locale}
return super().get_resource(resource, region, query_params)

def get_api_skill(self, region, locale, class_slug, skill_slug):
"""
D3 Character Class and Skill API - Returns a single skill by slug for a
specific character class.
"""
resource = f"/d3/data/hero/{class_slug}/skill/{skill_slug}"
query_params = {"locale": locale}
return super().get_resource(resource, region, query_params)

# D3 Item Type API

def get_item_type_index(self, region, locale):
"""
D3 Item Type API - Returns an index of item types.
"""
resource = "/d3/data/item-type"
query_params = {"locale": locale}
return super().get_resource(resource, region, query_params)

def get_item_type(self, region, locale, item_type_slug):
"""
D3 Item Type API - Returns a single item type by slug.
"""
resource = f"/d3/data/item-type/{item_type_slug}"
query_params = {"locale": locale}
return super().get_resource(resource, region, query_params)

# D3 Item API

def get_item(self, region, locale, item_slug_id):
"""
D3 Item API - Returns a single item by item slug and ID.
"""
resource = f"/d3/data/item/{item_slug_id}"
query_params = {"locale": locale}
return super().get_resource(resource, region, query_params)

# D3 Profile API

def get_api_account(self, region, locale, account_id):
"""
D3 Profile API - Returns the specified account profile.
"""
resource = f"/d3/profile/{account_id}/"
query_params = {"locale": locale}
return super().get_resource(resource, region, query_params)

def get_api_hero(self, region, locale, account_id, hero_id):
"""
D3 Profile API - Returns a single hero.
"""
resource = f"/d3/profile/{account_id}/hero/{hero_id}"
query_params = {"locale": locale}
return super().get_resource(resource, region, query_params)

def get_api_detailed_hero_items(self, region, locale, account_id, hero_id):
"""
D3 Profile API - Returns a list of items for the specified hero.
"""
resource = f"/d3/profile/{account_id}/hero/{hero_id}/items"
query_params = {"locale": locale}
return super().get_resource(resource, region, query_params)

def get_api_detailed_follower_items(
self, region, locale, account_id, hero_id
):
"""
D3 Profile API - Returns a single item by item slug and ID.
"""
resource = f"/d3/profile/{account_id}/hero/{hero_id}/follower-items"
query_params = {"locale": locale}
return super().get_resource(resource, region, query_params)
Loading

0 comments on commit 6e69a96

Please sign in to comment.