diff --git a/.github/workflows/python-package.yml b/.github/workflows/python-package.yml index 1bd27ca..0fc6b9d 100644 --- a/.github/workflows/python-package.yml +++ b/.github/workflows/python-package.yml @@ -37,7 +37,5 @@ jobs: run: | pytest - name: Codecov Report - env: - CODECOV_TOKEN: ${{ secrets.CODECOV_TOKEN }} run: | bash <(curl -s https://codecov.io/bash) diff --git a/Makefile b/Makefile index 87354bb..0e845a3 100644 --- a/Makefile +++ b/Makefile @@ -1,3 +1,6 @@ +devinstall: + pip install -r requirements.txt + clean: rm -rf dist rm -rf build diff --git a/README.md b/README.md index 3606ade..14d52fd 100644 --- a/README.md +++ b/README.md @@ -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. diff --git a/blizzardapi/api.py b/blizzardapi/api.py index 5b28ba2..f12cbe5 100644 --- a/blizzardapi/api.py +++ b/blizzardapi/api.py @@ -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) diff --git a/blizzardapi/battlenet/battlenet_oauth_api.py b/blizzardapi/battlenet/battlenet_oauth_api.py index d1101af..0c456c2 100644 --- a/blizzardapi/battlenet/battlenet_oauth_api.py +++ b/blizzardapi/battlenet/battlenet_oauth_api.py @@ -1,5 +1,3 @@ -from urllib import parse - from ..api import Api @@ -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 = { diff --git a/blizzardapi/diablo3/diablo3_api.py b/blizzardapi/diablo3/diablo3_api.py index d9a4012..34e3a9f 100644 --- a/blizzardapi/diablo3/diablo3_api.py +++ b/blizzardapi/diablo3/diablo3_api.py @@ -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) diff --git a/blizzardapi/diablo3/diablo3_community_api.py b/blizzardapi/diablo3/diablo3_community_api.py new file mode 100644 index 0000000..cd92f73 --- /dev/null +++ b/blizzardapi/diablo3/diablo3_community_api.py @@ -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) diff --git a/blizzardapi/wow/wow_game_data_api.py b/blizzardapi/wow/wow_game_data_api.py index a62938d..cb65999 100644 --- a/blizzardapi/wow/wow_game_data_api.py +++ b/blizzardapi/wow/wow_game_data_api.py @@ -13,7 +13,7 @@ def get_achievement_categories_index(self, region, locale): """ Achievement API - Returns an index of achievement categories. """ - resource = f"/data/wow/achievement-category/index" + resource = "/data/wow/achievement-category/index" query_params = {"namespace": f"static-{region}", "locale": locale} return super().get_resource(resource, region, query_params) @@ -31,7 +31,7 @@ def get_achievements_index(self, region, locale): """ Achievement API - Returns an index of achievements. """ - resource = f"/data/wow/achievement/index" + resource = "/data/wow/achievement/index" query_params = {"namespace": f"static-{region}", "locale": locale} return super().get_resource(resource, region, query_params) @@ -67,7 +67,7 @@ def get_azerite_essences_index(self, region, locale): """ Azerite Essence API - Returns an index of azerite essences. """ - resource = f"/data/wow/azerite-essence/index" + resource = "/data/wow/azerite-essence/index" query_params = {"namespace": f"static-{region}", "locale": locale} return super().get_resource(resource, region, query_params) @@ -93,7 +93,7 @@ def get_connected_realms_index(self, region, locale): """ Connected Realm API - Returns an index of connected realms. """ - resource = f"/data/wow/connected-realm/index" + resource = "/data/wow/connected-realm/index" query_params = {"namespace": f"dynamic-{region}", "locale": locale} return super().get_resource(resource, region, query_params) @@ -111,7 +111,7 @@ def get_creature_families_index(self, region, locale): """ Creature API - Returns an index of creature families. """ - resource = f"/data/wow/creature-family/index" + resource = "/data/wow/creature-family/index" query_params = {"namespace": f"static-{region}", "locale": locale} return super().get_resource(resource, region, query_params) @@ -127,7 +127,7 @@ def get_creature_types_index(self, region, locale): """ Creature API - Returns an index of creature types. """ - resource = f"/data/wow/creature-type/index" + resource = "/data/wow/creature-type/index" query_params = {"namespace": f"static-{region}", "locale": locale} return super().get_resource(resource, region, query_params) @@ -169,7 +169,7 @@ def get_guild_crest_components_index(self, region, locale): """ Guild Crest API - Returns an index of guild crest media. """ - resource = f"/data/wow/guild-crest/index" + resource = "/data/wow/guild-crest/index" query_params = {"namespace": f"static-{region}", "locale": locale} return super().get_resource(resource, region, query_params) @@ -195,7 +195,7 @@ def get_item_classes_index(self, region, locale): """ Item API - Returns an index of item classes. """ - resource = f"/data/wow/item-class/index" + resource = "/data/wow/item-class/index" query_params = {"namespace": f"static-{region}", "locale": locale} return super().get_resource(resource, region, query_params) @@ -211,7 +211,7 @@ def get_item_sets_index(self, region, locale): """ Item API - Returns an index of item sets. """ - resource = f"/data/wow/item-set/index" + resource = "/data/wow/item-set/index" query_params = {"namespace": f"static-{region}", "locale": locale} return super().get_resource(resource, region, query_params) @@ -255,7 +255,7 @@ def get_journal_expansions_index(self, region, locale): """ Journal API - Returns an index of journal expansions. """ - resource = f"/data/wow/journal-expansion/index" + resource = "/data/wow/journal-expansion/index" query_params = {"namespace": f"static-{region}", "locale": locale} return super().get_resource(resource, region, query_params) @@ -271,7 +271,7 @@ def get_journal_encounters_index(self, region, locale): """ Journal API - Returns an index of journal encounters. """ - resource = f"/data/wow/journal-encounter/index" + resource = "/data/wow/journal-encounter/index" query_params = {"namespace": f"static-{region}", "locale": locale} return super().get_resource(resource, region, query_params) @@ -287,7 +287,7 @@ def get_journal_instances_index(self, region, locale): """ Journal API - Returns an index of journal instances. """ - resource = f"/data/wow/journal-instance/index" + resource = "/data/wow/journal-instance/index" query_params = {"namespace": f"static-{region}", "locale": locale} return super().get_resource(resource, region, query_params) @@ -313,21 +313,23 @@ def get_modified_crafting_index(self, region, locale): """ Modified Crafting API - Returns the parent index for Modified Crafting. """ - resource = f"/data/wow/modified-crafting/index" + resource = "/data/wow/modified-crafting/index" query_params = {"namespace": f"static-{region}", "locale": locale} return super().get_resource(resource, region, query_params) def get_modified_crafting_category_index(self, region, locale): """ - Modified Crafting API - Returns the index of Modified Crafting categories. + Modified Crafting API - Returns the index of Modified Crafting + categories. """ - resource = f"/data/wow/modified-crafting/category/index" + resource = "/data/wow/modified-crafting/category/index" query_params = {"namespace": f"static-{region}", "locale": locale} return super().get_resource(resource, region, query_params) def get_modified_crafting_category(self, region, locale, category_id): """ - Modified Crafting API - Returns the index of Modified Crafting categories. + Modified Crafting API - Returns the index of Modified Crafting + categories. """ resource = f"/data/wow/modified-crafting/category/{category_id}" query_params = {"namespace": f"static-{region}", "locale": locale} @@ -335,9 +337,10 @@ def get_modified_crafting_category(self, region, locale, category_id): def get_modified_crafting_reagent_slot_type_index(self, region, locale): """ - Modified Crafting API - Returns the index of Modified Crafting reagent slot types. + Modified Crafting API - Returns the index of Modified Crafting reagent + slot types. """ - resource = f"/data/wow/modified-crafting/reagent-slot-type/index" + resource = "/data/wow/modified-crafting/reagent-slot-type/index" query_params = {"namespace": f"static-{region}", "locale": locale} return super().get_resource(resource, region, query_params) @@ -345,7 +348,8 @@ def get_modified_crafting_reagent_slot_type( self, region, locale, slot_type_id ): """ - Modified Crafting API - Returns a Modified Crafting reagent slot type by ID. + Modified Crafting API - Returns a Modified Crafting reagent slot type + by ID. """ resource = ( f"/data/wow/modified-crafting/reagent-slot-type/{slot_type_id}" @@ -359,7 +363,7 @@ def get_mounts_index(self, region, locale): """ Mount API - Returns an index of mounts. """ - resource = f"/data/wow/mount/index" + resource = "/data/wow/mount/index" query_params = {"namespace": f"static-{region}", "locale": locale} return super().get_resource(resource, region, query_params) @@ -375,9 +379,10 @@ def get_mount(self, region, locale, mount_id): def get_mythic_keystone_affixes_index(self, region, locale): """ - Mythic Keystone Affix API - Returns an index of mythic keystone affixes. + Mythic Keystone Affix API - Returns an index of mythic keystone + affixes. """ - resource = f"/data/wow/keystone-affix/index" + resource = "/data/wow/keystone-affix/index" query_params = {"namespace": f"static-{region}", "locale": locale} return super().get_resource(resource, region, query_params) @@ -393,7 +398,8 @@ def get_mythic_keystone_affix_media( self, region, locale, keystone_affix_id ): """ - Mythic Keystone Affix API - Returns media for a mythic keystone affix by ID. + Mythic Keystone Affix API - Returns media for a mythic keystone affix + by ID. """ resource = f"/data/wow/media/keystone-affix/{keystone_affix_id}" query_params = {"namespace": f"static-{region}", "locale": locale} @@ -403,9 +409,10 @@ def get_mythic_keystone_affix_media( def get_mythic_keystone_dungeons_index(self, region, locale): """ - Mythic Keystone Dungeon API - Returns an index of Mythic Keystone dungeons. + Mythic Keystone Dungeon API - Returns an index of Mythic Keystone + dungeons. """ - resource = f"/data/wow/mythic-keystone/dungeon/index" + resource = "/data/wow/mythic-keystone/dungeon/index" query_params = {"namespace": f"dynamic-{region}", "locale": locale} return super().get_resource(resource, region, query_params) @@ -419,18 +426,20 @@ def get_mythic_keystone_dungeon(self, region, locale, dungeon_id): def get_mythic_keystone_index(self, region, locale): """ - Mythic Keystone Dungeon API - Returns an index of links to other documents related to + Mythic Keystone Dungeon API - Returns an index of links to other + documents related to Mythic Keystone dungeons. """ - resource = f"/data/wow/mythic-keystone/index" + resource = "/data/wow/mythic-keystone/index" query_params = {"namespace": f"dynamic-{region}", "locale": locale} return super().get_resource(resource, region, query_params) def get_mythic_keystone_periods_index(self, region, locale): """ - Mythic Keystone Dungeon API - Returns an index of Mythic Keystone periods. + Mythic Keystone Dungeon API - Returns an index of Mythic Keystone + periods. """ - resource = f"/data/wow/mythic-keystone/period/index" + resource = "/data/wow/mythic-keystone/period/index" query_params = {"namespace": f"dynamic-{region}", "locale": locale} return super().get_resource(resource, region, query_params) @@ -444,9 +453,10 @@ def get_mythic_keystone_period(self, region, locale, period_id): def get_mythic_keystone_seasons_index(self, region, locale): """ - Mythic Keystone Dungeon API - Returns an index of Mythic Keystone seasons. + Mythic Keystone Dungeon API - Returns an index of Mythic Keystone + seasons. """ - resource = f"/data/wow/mythic-keystone/season/index" + resource = "/data/wow/mythic-keystone/season/index" query_params = {"namespace": f"dynamic-{region}", "locale": locale} return super().get_resource(resource, region, query_params) @@ -464,8 +474,8 @@ def get_mythic_keystone_leaderboards_index( self, region, locale, connected_realm_id ): """ - Mythic Keystone Leaderboard API - Returns an index of Mythic Keystone Leaderboard dungeon - instances for a connected realm. + Mythic Keystone Leaderboard API - Returns an index of Mythic Keystone + Leaderboard dungeon instances for a connected realm. """ resource = f"/data/wow/connected-realm/{connected_realm_id}/mythic-leaderboard/index" query_params = {"namespace": f"dynamic-{region}", "locale": locale} @@ -475,7 +485,8 @@ def get_mythic_keystone_leaderboard( self, region, locale, connected_realm_id, dungeon_id, period_id ): """ - Mythic Keystone Leaderboard API - Returns a weekly Mythic Keystone Leaderboard by period. + Mythic Keystone Leaderboard API - Returns a weekly Mythic Keystone + Leaderboard by period. """ resource = f"/data/wow/connected-realm/{connected_realm_id}/mythic-leaderboard/{dungeon_id}/period/{period_id}" query_params = {"namespace": f"dynamic-{region}", "locale": locale} @@ -485,7 +496,8 @@ def get_mythic_keystone_leaderboard( def get_mythic_raid_leaderboard(self, region, locale, raid, faction): """ - Mythic Raid Leaderboard API - Returns the leaderboard for a given raid and faction. + Mythic Raid Leaderboard API - Returns the leaderboard for a given raid + and faction. """ resource = f"/data/wow/leaderboard/hall-of-fame/{raid}/{faction}" query_params = {"namespace": f"dynamic-{region}", "locale": locale} @@ -497,7 +509,7 @@ def get_pets_index(self, region, locale): """ Pet API - Returns an index of battle pets. """ - resource = f"/data/wow/pet/index" + resource = "/data/wow/pet/index" query_params = {"namespace": f"static-{region}", "locale": locale} return super().get_resource(resource, region, query_params) @@ -521,7 +533,7 @@ def get_pet_abilities_index(self, region, locale): """ Pet API - Returns an index of pet abilities. """ - resource = f"/data/wow/pet-ability/index" + resource = "/data/wow/pet-ability/index" query_params = {"namespace": f"static-{region}", "locale": locale} return super().get_resource(resource, region, query_params) @@ -547,7 +559,7 @@ def get_playable_classes_index(self, region, locale): """ Playable Class API - Returns an index of playable classes. """ - resource = f"/data/wow/playable-class/index" + resource = "/data/wow/playable-class/index" query_params = {"namespace": f"static-{region}", "locale": locale} return super().get_resource(resource, region, query_params) @@ -569,7 +581,8 @@ def get_playable_class_media(self, region, locale, playable_class_id): def get_pvp_talent_slots(self, region, locale, class_id): """ - Playable Class API - Returns the PvP talent slots for a playable class by ID. + Playable Class API - Returns the PvP talent slots for a playable class + by ID. """ resource = f"/data/wow/playable-class/{class_id}/pvp-talent-slots" query_params = {"namespace": f"static-{region}", "locale": locale} @@ -581,7 +594,7 @@ def get_playable_races_index(self, region, locale): """ Playable Race API - Returns an index of playable races. """ - resource = f"/data/wow/playable-race/index" + resource = "/data/wow/playable-race/index" query_params = {"namespace": f"static-{region}", "locale": locale} return super().get_resource(resource, region, query_params) @@ -597,9 +610,10 @@ def get_playable_race(self, region, locale, playable_race_id): def get_playable_specializations_index(self, region, locale): """ - Playable Specialization API - Returns an index of playable specializations. + Playable Specialization API - Returns an index of playable + specializations. """ - resource = f"/data/wow/playable-specialization/index" + resource = "/data/wow/playable-specialization/index" query_params = {"namespace": f"static-{region}", "locale": locale} return super().get_resource(resource, region, query_params) @@ -613,7 +627,8 @@ def get_playable_specialization(self, region, locale, spec_id): def get_playable_specialization_media(self, region, locale, spec_id): """ - Playable Specialization API - Returns media for a playable specialization by ID. + Playable Specialization API - Returns media for a playable + specialization by ID. """ resource = f"/data/wow/media/playable-specialization/{spec_id}" query_params = {"namespace": f"static-{region}", "locale": locale} @@ -625,7 +640,7 @@ def get_power_types_index(self, region, locale): """ Power Type API - Returns an index of power types. """ - resource = f"/data/wow/power-type/index" + resource = "/data/wow/power-type/index" query_params = {"namespace": f"static-{region}", "locale": locale} return super().get_resource(resource, region, query_params) @@ -643,7 +658,7 @@ def get_professions_index(self, region, locale): """ Profession API - Returns an index of professions. """ - resource = f"/data/wow/profession/index" + resource = "/data/wow/profession/index" query_params = {"namespace": f"static-{region}", "locale": locale} return super().get_resource(resource, region, query_params) @@ -697,7 +712,7 @@ def get_pvp_seasons_index(self, region, locale): """ PvP Season API - Returns an index of PvP seasons. """ - resource = f"/data/wow/pvp-season/index" + resource = "/data/wow/pvp-season/index" query_params = {"namespace": f"dynamic-{region}", "locale": locale} return super().get_resource(resource, region, query_params) @@ -721,7 +736,8 @@ def get_pvp_leaderboards_index(self, region, locale, pvp_season_id): def get_pvp_leaderboard(self, region, locale, pvp_season_id, pvp_bracket): """ - PvP Season API - Returns the PvP leaderboard of a specific PvP bracket for a PvP season. + PvP Season API - Returns the PvP leaderboard of a specific PvP bracket + for a PvP season. """ resource = f"/data/wow/pvp-season/{pvp_season_id}/pvp-leaderboard/{pvp_bracket}" query_params = {"namespace": f"dynamic-{region}", "locale": locale} @@ -749,7 +765,7 @@ def get_pvp_tiers_index(self, region, locale): """ PvP Tier API - Returns an index of PvP tiers. """ - resource = f"/data/wow/pvp-tier/index" + resource = "/data/wow/pvp-tier/index" query_params = {"namespace": f"static-{region}", "locale": locale} return super().get_resource(resource, region, query_params) @@ -767,7 +783,7 @@ def get_quests_index(self, region, locale): """ Quest API - Returns the parent index for quests. """ - resource = f"/data/wow/quest/index" + resource = "/data/wow/quest/index" query_params = {"namespace": f"static-{region}", "locale": locale} return super().get_resource(resource, region, query_params) @@ -781,10 +797,11 @@ def get_quest(self, region, locale, quest_id): def get_quest_categories_index(self, region, locale): """ - Quest API - Returns an index of quest categories (such as quests for a specific class, + Quest API - Returns an index of quest categories (such as quests for a + specific class, profession, or storyline). """ - resource = f"/data/wow/quest/category/index" + resource = "/data/wow/quest/category/index" query_params = {"namespace": f"static-{region}", "locale": locale} return super().get_resource(resource, region, query_params) @@ -800,7 +817,7 @@ def get_quest_areas_index(self, region, locale): """ Quest API - Returns an index of quest areas. """ - resource = f"/data/wow/quest/area/index" + resource = "/data/wow/quest/area/index" query_params = {"namespace": f"static-{region}", "locale": locale} return super().get_resource(resource, region, query_params) @@ -814,10 +831,11 @@ def get_quest_area(self, region, locale, quest_area_id): def get_quest_types_index(self, region, locale): """ - Quest API - Returns an index of quest types (such as PvP quests, raid quests, or account + Quest API - Returns an index of quest types (such as PvP quests, raid + quests, or account quests). """ - resource = f"/data/wow/quest/type/index" + resource = "/data/wow/quest/type/index" query_params = {"namespace": f"static-{region}", "locale": locale} return super().get_resource(resource, region, query_params) @@ -835,7 +853,7 @@ def get_realms_index(self, region, locale): """ Realm API - Returns an index of realms. """ - resource = f"/data/wow/realm/index" + resource = "/data/wow/realm/index" query_params = {"namespace": f"dynamic-{region}", "locale": locale} return super().get_resource(resource, region, query_params) @@ -853,7 +871,7 @@ def get_regions_index(self, region, locale): """ Region API - Returns an index of regions. """ - resource = f"/data/wow/region/index" + resource = "/data/wow/region/index" query_params = {"namespace": f"dynamic-{region}", "locale": locale} return super().get_resource(resource, region, query_params) @@ -871,7 +889,7 @@ def get_reputation_factions_index(self, region, locale): """ Reputations API - Returns an index of reputation factions. """ - resource = f"/data/wow/reputation-faction/index" + resource = "/data/wow/reputation-faction/index" query_params = {"namespace": f"static-{region}", "locale": locale} return super().get_resource(resource, region, query_params) @@ -887,7 +905,7 @@ def get_reputation_tiers_index(self, region, locale): """ Reputations API - Returns an index of reputation tiers. """ - resource = f"/data/wow/reputation-tiers/index" + resource = "/data/wow/reputation-tiers/index" query_params = {"namespace": f"static-{region}", "locale": locale} return super().get_resource(resource, region, query_params) @@ -923,7 +941,7 @@ def get_talents_index(self, region, locale): """ Talent API - Returns an index of talents. """ - resource = f"/data/wow/talent/index" + resource = "/data/wow/talent/index" query_params = {"namespace": f"static-{region}", "locale": locale} return super().get_resource(resource, region, query_params) @@ -939,7 +957,7 @@ def get_pvp_talents_index(self, region, locale): """ Talent API - Returns an index of PvP talents. """ - resource = f"/data/wow/pvp-talent/index" + resource = "/data/wow/pvp-talent/index" query_params = {"namespace": f"static-{region}", "locale": locale} return super().get_resource(resource, region, query_params) @@ -957,7 +975,7 @@ def get_titles_index(self, region, locale): """ Title API - Returns an index of titles. """ - resource = f"/data/wow/title/index" + resource = "/data/wow/title/index" query_params = {"namespace": f"static-{region}", "locale": locale} return super().get_resource(resource, region, query_params) @@ -975,6 +993,6 @@ def get_token_index(self, region, locale): """ WoW Token API - Returns the WoW Token index. """ - resource = f"/data/wow/token/index" + resource = "/data/wow/token/index" query_params = {"namespace": f"dynamic-{region}", "locale": locale} return super().get_resource(resource, region, query_params) diff --git a/blizzardapi/wow/wow_profile_api.py b/blizzardapi/wow/wow_profile_api.py index b0d1af6..795551a 100644 --- a/blizzardapi/wow/wow_profile_api.py +++ b/blizzardapi/wow/wow_profile_api.py @@ -13,7 +13,7 @@ def get_account_profile_summary(self, region, locale, access_token): """ Account Profile API - Returns a profile summary for an account. """ - resource = f"/profile/user/wow" + resource = "/profile/user/wow" query_params = { "namespace": f"profile-{region}", "locale": locale, @@ -25,7 +25,8 @@ def get_protected_character_profile_summary( self, region, locale, access_token, realm_id, character_id ): """ - Account Profile API - Returns a protected profile summary for a character. + Account Profile API - Returns a protected profile summary for a + character. """ resource = ( f"/profile/user/wow/protected-character/{realm_id}-{character_id}" @@ -39,9 +40,10 @@ def get_protected_character_profile_summary( def get_account_collections_index(self, region, locale, access_token): """ - Account Profile API - Returns an index of collection types for an account. + Account Profile API - Returns an index of collection types for an + account. """ - resource = f"/profile/user/wow/collections" + resource = "/profile/user/wow/collections" query_params = { "namespace": f"profile-{region}", "locale": locale, @@ -53,9 +55,10 @@ def get_account_mounts_collection_summary( self, region, locale, access_token ): """ - Account Profile API - Returns a summary of the mounts an account has obtained. + Account Profile API - Returns a summary of the mounts an account has + obtained. """ - resource = f"/profile/user/wow/collections/mounts" + resource = "/profile/user/wow/collections/mounts" query_params = { "namespace": f"profile-{region}", "locale": locale, @@ -67,9 +70,10 @@ def get_account_pets_collection_summary( self, region, locale, access_token ): """ - Account Profile API - Returns a summary of the battle pets an account has obtained. + Account Profile API - Returns a summary of the battle pets an account + has obtained. """ - resource = f"/profile/user/wow/collections/pets" + resource = "/profile/user/wow/collections/pets" query_params = { "namespace": f"profile-{region}", "locale": locale, @@ -83,7 +87,8 @@ def get_character_achievements_summary( self, region, locale, realm_slug, character_name ): """ - Character Achievements API - Returns a summary of the achievements a character has completed. + Character Achievements API - Returns a summary of the achievements a + character has completed. """ resource = f"/profile/wow/character/{realm_slug}/{character_name}/achievements" query_params = {"namespace": f"profile-{region}", "locale": locale} @@ -93,7 +98,8 @@ def get_character_achievement_statistics( self, region, locale, realm_slug, character_name ): """ - Character Achievements API - Returns a character's statistics as they pertain to achievements. + Character Achievements API - Returns a character's statistics as they + pertain to achievements. """ resource = f"/profile/wow/character/{realm_slug}/{character_name}/achievements/statistics" query_params = {"namespace": f"profile-{region}", "locale": locale} @@ -105,7 +111,8 @@ def get_character_appearance_summary( self, region, locale, realm_slug, character_name ): """ - Character Appearance API - Returns a summary of a character's appearance settings. + Character Appearance API - Returns a summary of a character's + appearance settings. """ resource = ( f"/profile/wow/character/{realm_slug}/{character_name}/appearance" @@ -119,7 +126,8 @@ def get_character_collections_index( self, region, locale, realm_slug, character_name ): """ - Character Collections API - Returns an index of collection types for a character. + Character Collections API - Returns an index of collection types for + a character. """ resource = ( f"/profile/wow/character/{realm_slug}/{character_name}/collections" @@ -131,7 +139,8 @@ def get_character_mounts_collection_index( self, region, locale, realm_slug, character_name ): """ - Character Collections API - Returns a summary of the mounts a character has obtained. + Character Collections API - Returns a summary of the mounts a character + has obtained. """ resource = f"/profile/wow/character/{realm_slug}/{character_name}/collections/mounts" query_params = {"namespace": f"profile-{region}", "locale": locale} @@ -141,7 +150,8 @@ def get_character_pets_collection_index( self, region, locale, realm_slug, character_name ): """ - Character Collections API - Returns a summary of the battle pets a character has obtained. + Character Collections API - Returns a summary of the battle pets a + character has obtained. """ resource = f"/profile/wow/character/{realm_slug}/{character_name}/collections/pets" query_params = {"namespace": f"profile-{region}", "locale": locale} @@ -153,7 +163,8 @@ def get_character_encounters_summary( self, region, locale, realm_slug, character_name ): """ - Character Encounters API - Returns a summary of a character's encounters. + Character Encounters API - Returns a summary of a character's + encounters. """ resource = ( f"/profile/wow/character/{realm_slug}/{character_name}/encounters" @@ -165,7 +176,8 @@ def get_character_dungeons( self, region, locale, realm_slug, character_name ): """ - Character Encounters API - Returns a summary of a character's completed dungeons. + Character Encounters API - Returns a summary of a character's + completed dungeons. """ resource = f"/profile/wow/character/{realm_slug}/{character_name}/encounters/dungeons" query_params = {"namespace": f"profile-{region}", "locale": locale} @@ -173,7 +185,8 @@ def get_character_dungeons( def get_character_raids(self, region, locale, realm_slug, character_name): """ - Character Encounters API - Returns a summary of a character's completed raids. + Character Encounters API - Returns a summary of a character's + completed raids. """ resource = f"/profile/wow/character/{realm_slug}/{character_name}/encounters/raids" query_params = {"namespace": f"profile-{region}", "locale": locale} @@ -185,7 +198,8 @@ def get_character_equipment_summary( self, region, locale, realm_slug, character_name ): """ - Character Equipment API - Returns a summary of the items equipped by a character. + Character Equipment API - Returns a summary of the items equipped by a + character. """ resource = ( f"/profile/wow/character/{realm_slug}/{character_name}/equipment" @@ -199,7 +213,8 @@ def get_character_hunter_pets_summary( self, region, locale, realm_slug, character_name ): """ - Character Hunter Pets API - If the character is a hunter, returns a summary of the character's hunter pets. + Character Hunter Pets API - If the character is a hunter, returns a + summary of the character's hunter pets. """ resource = ( f"/profile/wow/character/{realm_slug}/{character_name}/hunter-pets" @@ -213,7 +228,8 @@ def get_character_media_summary( self, region, locale, realm_slug, character_name ): """ - Character Media API - Returns a summary of the media assets available for a character (such as an avatar render). + Character Media API - Returns a summary of the media assets available + for a character (such as an avatar render). """ resource = f"/profile/wow/character/{realm_slug}/{character_name}/character-media" query_params = {"namespace": f"profile-{region}", "locale": locale} @@ -225,7 +241,8 @@ def get_character_mythic_keystone_profile_index( self, region, locale, realm_slug, character_name ): """ - Character Mythic Keystone Profile API - Returns the Mythic Keystone profile index for a character. + Character Mythic Keystone Profile API - Returns the Mythic Keystone + profile index for a character. """ resource = f"/profile/wow/character/{realm_slug}/{character_name}/mythic-keystone-profile" query_params = {"namespace": f"profile-{region}", "locale": locale} @@ -235,7 +252,8 @@ def get_character_mythic_keystone_profile_season_details( self, region, locale, realm_slug, character_name, season_id ): """ - Character Mythic Keystone Profile API - Returns the Mythic Keystone season details for a character. + Character Mythic Keystone Profile API - Returns the Mythic Keystone + season details for a character. """ resource = f"/profile/wow/character/{realm_slug}/{character_name}/mythic-keystone-profile/season/{season_id}" query_params = {"namespace": f"profile-{region}", "locale": locale} @@ -247,7 +265,8 @@ def get_character_professions_summary( self, region, locale, realm_slug, character_name ): """ - Character Professions API - Returns a summary of professions for a character. + Character Professions API - Returns a summary of professions for a + character. """ resource = ( f"/profile/wow/character/{realm_slug}/{character_name}/professions" @@ -271,7 +290,8 @@ def get_character_profile_status( self, region, locale, realm_slug, character_name ): """ - Character Profile API - Returns the status and a unique ID for a character. + Character Profile API - Returns the status and a unique ID for a + character. """ resource = ( f"/profile/wow/character/{realm_slug}/{character_name}/status" @@ -307,7 +327,8 @@ def get_character_pvp_summary( def get_character_quests(self, region, locale, realm_slug, character_name): """ - Character Quests API - Returns a character's active quests as well as a link to the character's completed quests. + Character Quests API - Returns a character's active quests as well as a + link to the character's completed quests. """ resource = ( f"/profile/wow/character/{realm_slug}/{character_name}/quests" @@ -319,7 +340,8 @@ def get_character_completed_quests( self, region, locale, realm_slug, character_name ): """ - Character Quests API - Returns a list of quests that a character has completed. + Character Quests API - Returns a list of quests that a character has + completed. """ resource = f"/profile/wow/character/{realm_slug}/{character_name}/quests/completed" query_params = {"namespace": f"profile-{region}", "locale": locale} @@ -331,7 +353,8 @@ def get_character_reputations_summary( self, region, locale, realm_slug, character_name ): """ - Character Reputations API - Returns a summary of a character's reputations. + Character Reputations API - Returns a summary of a character's + reputations. """ resource = ( f"/profile/wow/character/{realm_slug}/{character_name}/reputations" @@ -345,7 +368,8 @@ def get_character_specializations_summary( self, region, locale, realm_slug, character_name ): """ - Character Specializations API - Returns a summary of a character's specializations. + Character Specializations API - Returns a summary of a character's + specializations. """ resource = f"/profile/wow/character/{realm_slug}/{character_name}/specializations" query_params = {"namespace": f"profile-{region}", "locale": locale} @@ -357,7 +381,8 @@ def get_character_statistics_summary( self, region, locale, realm_slug, character_name ): """ - Character Statistics API - Returns a statistics summary for a character. + Character Statistics API - Returns a statistics summary for a + character. """ resource = ( f"/profile/wow/character/{realm_slug}/{character_name}/statistics" @@ -371,7 +396,8 @@ def get_character_titles_summary( self, region, locale, realm_slug, character_name ): """ - Character Titles API - Returns a summary of titles a character has obtained. + Character Titles API - Returns a summary of titles a character has + obtained. """ resource = ( f"/profile/wow/character/{realm_slug}/{character_name}/titles" diff --git a/codecov.yml b/codecov.yml new file mode 100644 index 0000000..9b7c16f --- /dev/null +++ b/codecov.yml @@ -0,0 +1,2 @@ +ignore: + - "setup.py" diff --git a/tests/test_diablo3_community_api.py b/tests/test_diablo3_community_api.py new file mode 100644 index 0000000..97fa548 --- /dev/null +++ b/tests/test_diablo3_community_api.py @@ -0,0 +1,191 @@ +from blizzardapi import BlizzardApi + + +class TestDiablo3CommunityApi: + def setup(self): + self.api = BlizzardApi("client_id", "client_secret") + self.api.diablo3.community._access_token = "access_token" + + # D3 Act API + + def test_get_act_index(self, success_response_mock): + self.api.diablo3.community.get_act_index("us", "en_US") + params = { + "locale": "en_US", + "access_token": "access_token", + } + success_response_mock.assert_called_with( + "https://us.api.blizzard.com/d3/data/act", + params=params, + ) + + def test_get_act(self, success_response_mock): + self.api.diablo3.community.get_act("us", "en_US", 1) + params = { + "locale": "en_US", + "access_token": "access_token", + } + success_response_mock.assert_called_with( + "https://us.api.blizzard.com/d3/data/act/1", + params=params, + ) + + # D3 Artisan and Recipe API + + def test_get_artisan(self, success_response_mock): + self.api.diablo3.community.get_artisan("us", "en_US", "blacksmith") + params = { + "locale": "en_US", + "access_token": "access_token", + } + success_response_mock.assert_called_with( + "https://us.api.blizzard.com/d3/data/artisan/blacksmith", + params=params, + ) + + def test_get_recipe(self, success_response_mock): + self.api.diablo3.community.get_recipe( + "us", "en_US", "blacksmith", "apprentice-flamberge" + ) + params = { + "locale": "en_US", + "access_token": "access_token", + } + success_response_mock.assert_called_with( + "https://us.api.blizzard.com/d3/data/artisan/blacksmith/recipe/apprentice-flamberge", + params=params, + ) + + # D3 Follower API + + def test_get_follower(self, success_response_mock): + self.api.diablo3.community.get_follower("us", "en_US", "templar") + params = { + "locale": "en_US", + "access_token": "access_token", + } + success_response_mock.assert_called_with( + "https://us.api.blizzard.com/d3/data/follower/templar", + params=params, + ) + + # D3 Character Class and Skill API + + def test_get_character_class(self, success_response_mock): + self.api.diablo3.community.get_character_class( + "us", "en_US", "barbarian" + ) + params = { + "locale": "en_US", + "access_token": "access_token", + } + success_response_mock.assert_called_with( + "https://us.api.blizzard.com/d3/data/hero/barbarian", + params=params, + ) + + def test_get_api_skill(self, success_response_mock): + self.api.diablo3.community.get_api_skill( + "us", "en_US", "barbarian", "bash" + ) + params = { + "locale": "en_US", + "access_token": "access_token", + } + success_response_mock.assert_called_with( + "https://us.api.blizzard.com/d3/data/hero/barbarian/skill/bash", + params=params, + ) + + # D3 Item Type API + + def test_get_item_type_index(self, success_response_mock): + self.api.diablo3.community.get_item_type_index("us", "en_US") + params = { + "locale": "en_US", + "access_token": "access_token", + } + success_response_mock.assert_called_with( + "https://us.api.blizzard.com/d3/data/item-type", + params=params, + ) + + def test_get_item_type(self, success_response_mock): + self.api.diablo3.community.get_item_type("us", "en_US", "sword2h") + params = { + "locale": "en_US", + "access_token": "access_token", + } + success_response_mock.assert_called_with( + "https://us.api.blizzard.com/d3/data/item-type/sword2h", + params=params, + ) + + # D3 Item API + + def test_get_item(self, success_response_mock): + self.api.diablo3.community.get_item( + "us", "en_US", "corrupted-ashbringer-Unique_Sword_2H_104_x1" + ) + params = { + "locale": "en_US", + "access_token": "access_token", + } + success_response_mock.assert_called_with( + "https://us.api.blizzard.com/d3/data/item/corrupted-ashbringer-Unique_Sword_2H_104_x1", + params=params, + ) + + # D3 Profile API + + def test_get_api_account(self, success_response_mock): + self.api.diablo3.community.get_api_account( + "us", "en_US", "Battletag#1234" + ) + params = { + "locale": "en_US", + "access_token": "access_token", + } + success_response_mock.assert_called_with( + "https://us.api.blizzard.com/d3/profile/Battletag#1234/", + params=params, + ) + + def test_get_api_hero(self, success_response_mock): + self.api.diablo3.community.get_api_hero( + "us", "en_US", "Battletag#1234", 1 + ) + params = { + "locale": "en_US", + "access_token": "access_token", + } + success_response_mock.assert_called_with( + "https://us.api.blizzard.com/d3/profile/Battletag#1234/hero/1", + params=params, + ) + + def test_get_api_detailed_hero_items(self, success_response_mock): + self.api.diablo3.community.get_api_detailed_hero_items( + "us", "en_US", "Battletag#1234", 1 + ) + params = { + "locale": "en_US", + "access_token": "access_token", + } + success_response_mock.assert_called_with( + "https://us.api.blizzard.com/d3/profile/Battletag#1234/hero/1/items", + params=params, + ) + + def test_get_api_detailed_follower_items(self, success_response_mock): + self.api.diablo3.community.get_api_detailed_follower_items( + "us", "en_US", "Battletag#1234", 1 + ) + params = { + "locale": "en_US", + "access_token": "access_token", + } + success_response_mock.assert_called_with( + "https://us.api.blizzard.com/d3/profile/Battletag#1234/hero/1/follower-items", + params=params, + ) diff --git a/tests/test_wow_profile_api.py b/tests/test_wow_profile_api.py index fc226c3..f012e78 100644 --- a/tests/test_wow_profile_api.py +++ b/tests/test_wow_profile_api.py @@ -279,9 +279,7 @@ def test_get_character_mythic_keystone_profile_index( "access_token": "access_token", } success_response_mock.assert_called_with( - "{0}/profile/wow/character/blackmoore/ayanda/mythic-keystone-profile".format( - "https://us.api.blizzard.com" - ), + "https://us.api.blizzard.com/profile/wow/character/blackmoore/ayanda/mythic-keystone-profile", params=params, ) @@ -297,9 +295,7 @@ def test_get_character_mythic_keystone_profile_season_details( "access_token": "access_token", } success_response_mock.assert_called_with( - "{0}/profile/wow/character/blackmoore/ayanda/mythic-keystone-profile/season/1".format( - "https://us.api.blizzard.com" - ), + "https://us.api.blizzard.com/profile/wow/character/blackmoore/ayanda/mythic-keystone-profile/season/1", params=params, )