Skip to content

Commit

Permalink
Updated to 1.0.0
Browse files Browse the repository at this point in the history
Added search parameter 'display_rarity'
Added search parameter 'set_text'
Added 'display_rarity' attribute to 'BrCosmetic' object
Added 'set_text' attribute to 'BrCosmetic' object
Added 'refundable' attribute to 'BrShopEntry' object
Added 'giftable' attribute to 'BrShopEntry' object

Changed time attribute are now 'datetime.datetime' objects instead of 'str'
Update method to get values which set the attributes to 'None' instead of raising an error

Took 54 minutes
  • Loading branch information
Luc1412 committed Nov 18, 2019
1 parent e084928 commit 7428f33
Show file tree
Hide file tree
Showing 6 changed files with 97 additions and 62 deletions.
2 changes: 1 addition & 1 deletion fortnite_api/__init__.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
__version__ = '0.0.1'
__version__ = '1.0.0'

from .api import FortniteAPI
from .enums import *
Expand Down
4 changes: 4 additions & 0 deletions fortnite_api/endpoints.py
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,8 @@ def _parse_search_parameter(self, **search_parameters):
parameters['backendType'] = search_parameters['backend_type']
if search_parameters.__contains__('rarity'):
parameters['rarity'] = search_parameters['rarity']
if search_parameters.__contains__('display_rarity'):
parameters['displayRarity'] = search_parameters['display_rarity']
if search_parameters.__contains__('backend_rarity'):
parameters['backendRarity'] = search_parameters['backend_rarity']
if search_parameters.__contains__('name'):
Expand All @@ -31,6 +33,8 @@ def _parse_search_parameter(self, **search_parameters):
parameters['description'] = search_parameters['description']
if search_parameters.__contains__('set'):
parameters['set'] = search_parameters['set']
if search_parameters.__contains__('set_text'):
parameters['setText'] = search_parameters['setText']
if search_parameters.__contains__('series'):
parameters['series'] = search_parameters['series']
if search_parameters.__contains__('has_small_icon'):
Expand Down
78 changes: 45 additions & 33 deletions fortnite_api/item.py
Original file line number Diff line number Diff line change
@@ -1,63 +1,75 @@
from datetime import datetime

from fortnite_api.enums import BrCosmeticType, BrCosmeticRarity


class BrCosmetic:

def __init__(self, data):
self.id = data['id']
self.type = BrCosmeticType(data['type'])
self.backend_type = data['backendType']
self.rarity = BrCosmeticRarity(data['rarity'])
self.backend_rarity = data['backendRarity']
self.name = data['name']
self.short_description = data['shortDescription']
self.description = data['description']
self.set = data['set']
self.series = data['series']
images = data['images']
self.small_icon = BRCosmeticImage(images['smallIcon']) if images['smallIcon'] is not None else None
self.icon = BRCosmeticImage(images['icon']) if images['icon'] is not None else None
self.featured = BRCosmeticImage(images['featured']) if images['featured'] is not None else None
self.background = BRCosmeticImage(images['background']) if images['background'] is not None else None
self.cover_art = BRCosmeticImage(images['coverArt']) if images['coverArt'] is not None else None
self.decal = BRCosmeticImage(images['decal']) if images['decal'] is not None else None
self.variants = [BrCosmeticVariant(variant) for variant in data['variants']] if data['variants'] is not None else None
self.gameplay_tags = [gameplay_tag for gameplay_tag in data['gameplayTags']] if data['gameplayTags'] is not None else None
self.display_asset_path = data['displayAssetPath']
self.definition = data['definition']
self.required_item_id = data['requiredItemId']
self.built_in_emote_id = data['builtInEmoteId']
self.path = data['path']
self.last_updated = data['lastUpdate'] # TODO: Convert into datetime
self.added = data['added'] # TODO: Convert into datetime
self.id = data.get('id')
self.type = BrCosmeticType(data.get('type'))
self.backend_type = data.get('backendType')
self.rarity = BrCosmeticRarity(data.get('rarity'))
self.display_rarity = data.get('displayRarity')
self.backend_rarity = data.get('backendRarity')
self.name = data.get('name')
self.short_description = data.get('shortDescription')
self.description = data.get('description')
self.set = data.get('set')
self.set_text = data.get('setText')
self.series = data.get('series')
images = data.get('images', {})
self.small_icon = BRCosmeticImage(images.get('smallIcon')) if images.get('smallIcon') is not None else None
self.icon = BRCosmeticImage(images.get('icon')) if images.get('icon') is not None else None
self.featured = BRCosmeticImage(images.get('featured')) if images.get('featured') is not None else None
self.background = BRCosmeticImage(images.get('background')) if images.get('background') is not None else None
self.cover_art = BRCosmeticImage(images.get('coverArt')) if images.get('coverArt') is not None else None
self.decal = BRCosmeticImage(images.get('decal')) if images.get('decal') is not None else None
self.variants = [BrCosmeticVariant(variant) for variant in data.get('variants')] \
if data.get('variants') is not None else None
self.gameplay_tags = [gameplay_tag for gameplay_tag in data.get('gameplayTags')] \
if data.get('gameplayTags') is not None else None
self.display_asset_path = data.get('displayAssetPath')
self.definition = data.get('definition')
self.required_item_id = data.get('requiredItemId')
self.built_in_emote_id = data.get('builtInEmoteId')
self.path = data.get('path')
try:
self.last_updated = datetime.strptime(data.get('lastUpdate'), '%Y-%m-%dT%H:%M:%S%z')
except ValueError:
self.last_updated = None
try:
self.added = datetime.strptime(data.get('added'), '%Y-%m-%dT%H:%M:%S%z')
except ValueError:
self.added = None
self.raw_data = data


class BRCosmeticImage:

def __init__(self, data):
self.hash = data['hash']
self.url = data['url']
self.hash = data.get('hash')
self.url = data.get('url')
self.raw_data = data


class BrCosmeticVariant:

def __init__(self, data):
self.type = data['type']
self.type = data.get('type')
self.options = None
self.raw_data = data

if data['options']:
if data.get('options'):
self.options = []
for variant in data['options']:
for variant in data.get('options'):
self.options.append(variant)


class BrCosmeticVariantOption:

def __init__(self, data):
self.name = data['name']
self.image = BRCosmeticImage(data['image'])
self.name = data.get('name')
self.image = BRCosmeticImage(data.get('image'))
self.raw_data = data

35 changes: 21 additions & 14 deletions fortnite_api/news.py
Original file line number Diff line number Diff line change
@@ -1,29 +1,36 @@
from datetime import datetime


class News:

def __init__(self, data):
self.br = GameModeNews(data['br'])
self.stw = GameModeNews(data['stw'])
self.creative = GameModeNews(data['creative'])
self.br = GameModeNews(data.get('br'))
self.stw = GameModeNews(data.get('stw'))
self.creative = GameModeNews(data.get('creative'))
self.raw_data = data


class GameModeNews:

def __init__(self, data):
self.last_modified = data['lastModified'] # TODO: Convert into datetime
self.entries = [NewsEntry(entry) for entry in data['messages']]
try:
self.last_modified = datetime.strptime(data.get('lastModified'), '%Y-%m-%dT%H:%M:%S%z')
except ValueError:
self.last_modified = None
self.entries = [NewsEntry(entry) for entry in data.get('messages')]
self.raw_data = data


class NewsEntry:

def __init__(self, data):
self.image_url = data['image']
self.hidden = data['hidden']
self.message_type = data['messageType']
self.type = data['type']
self.banner = data['adspace']
self.title = data['title']
self.description = data['body']
self.spotlight = data['spotlight']
self.raw_data = data
self.image_url = data.get('image')
self.hidden = data.get('hidden')
self.layout = data.get('layout')
self.message_type = data.get('messageType')
self.type = data.get('type')
self.banner = data.get('adspace')
self.title = data.get('title')
self.description = data.get('body')
self.spotlight = data.get('spotlight')
self.raw_data = data
34 changes: 21 additions & 13 deletions fortnite_api/shop.py
Original file line number Diff line number Diff line change
@@ -1,27 +1,35 @@
from datetime import datetime

from fortnite_api.item import BrCosmetic


class BrShop:

def __init__(self, data):
self.hash = data['hash']
self.date = data['date'] # TODO: Convert into datetime
self.featured = [BrShopEntry(item_data) for item_data in data['featured']] if data['featured'] else None
self.daily = [BrShopEntry(item_data) for item_data in data['daily']] if data['daily'] else None
self.votes = [BrShopEntry(item_data) for item_data in data['votes']] if data['votes'] else None
self.vote_winners = [BrShopEntry(item_data) for item_data in data['voteWinners']] if data['voteWinners'] else None
self.hash = data.get('hash')
try:
self.date = datetime.strptime(data.get('date'), '%Y-%m-%dT%H:%M:%S%z')
except ValueError:
self.date = None
self.featured = [BrShopEntry(item_data) for item_data in data.get('featured')] if data.get('featured') else None
self.daily = [BrShopEntry(item_data) for item_data in data.get('daily')] if data.get('daily') else None
self.votes = [BrShopEntry(item_data) for item_data in data.get('votes')] if data.get('votes') else None
self.vote_winners = [BrShopEntry(item_data) for item_data in data.get('voteWinners')] \
if data.get('voteWinners') else None
self.raw_data = data


class BrShopEntry:

def __init__(self, data):
self.regular_price = data['regularPrice']
self.final_price = data['finalPrice']
self.regular_price = data.get('regularPrice')
self.final_price = data.get('finalPrice')
self.discount = self.regular_price - self.final_price
self.is_bundle = data['isBundle']
self.panel = data['panel']
self.sort_priority = data['sortPriority']
self.banner = data['banner']
self.items = [BrCosmetic(item_data) for item_data in data['items']]
self.is_bundle = data.get('isBundle')
self.refundable = data.get('refundable')
self.giftable = data.get('giftable')
self.panel = data.get('panel')
self.sort_priority = data.get('sortPriority')
self.banner = data.get('banner')
self.items = [BrCosmetic(item_data) for item_data in data.get('items')]
self.raw_data = data
6 changes: 5 additions & 1 deletion tests.py
Original file line number Diff line number Diff line change
@@ -1,3 +1,7 @@
import fortnite_api

fortnite_api.FortniteAPI()
fn = fortnite_api.FortniteAPI()


if __name__ == '__main__':
pass

0 comments on commit 7428f33

Please sign in to comment.