diff --git a/nso/api.py b/nso/api.py index eaacaec..a9944ac 100644 --- a/nso/api.py +++ b/nso/api.py @@ -195,8 +195,8 @@ def getV2PickupItems(self, country:str) -> dict: """ Unfinished """ - return self._get('/api/v2/pickup_items', + return [ Pickup_Item(**iterable) for iterable in self._get('/api/v2/pickup_items', query = { 'country': country, } - ).json() + ).json() ] diff --git a/nso/structures.py b/nso/structures.py index 7b7f70a..58eb3e5 100644 --- a/nso/structures.py +++ b/nso/structures.py @@ -331,3 +331,103 @@ def __init__(self, **kwargs:dict) -> None: def __str__(self) -> str: return toString(self) + +################################### +# NSOAppletAPI.getV2PickupItems() # +################################### +class Pickup_Item: + """ + response : dict + Keys: + id : str + status : str + countries : list + str + condition_subscription_type : None || str + priority : str + template : str + products : list + product + published_at : str + expired_at : str + display_meta : str + distribution : Distribution + rating_info : Rating_Info + """ + def __init__(self, **kwargs:dict) -> None: + self.id:str = kwargs.get('id') + self.status:str = kwargs.get('status') + self.countries:typing.List[str] = kwargs.get('countries') + self.condition_subscription_type:str = kwargs.get('condition_subscription_type') + self.priority:str = kwargs.get('priority') + self.template:str = kwargs.get('template') + self.products:typing.List[Product] = [ Product(**iterable) for iterable in kwargs.get('products', []) ] + self.published_at:str = kwargs.get('published_at') + self.expired_at:str = kwargs.get('expired_at') + self.display_meta:str = kwargs.get('display_meta') + self.distribution:Distribution = Distribution() if kwargs.get('distribution', {}) is None else Distribution(**kwargs.get('distribution', {})) + self.rating_info:Rating_Info = Rating_Info() if kwargs.get('rating_info', {}) is None else Rating_Info(**kwargs.get('rating_info', {})) + + def __str__(self) -> str: + return toString(self) + +class Product: + """ + iterable : dict + Keys: + nsuid : int + application_id : str + title_name : str + icon_url : str + icon_sizes : list + int + classic_title_id : None || str + classic_title_icon_url : None || str + """ + def __init__(self, **kwargs:dict) -> None: + self.nsuid:int = kwargs.get('nsuid') + self.application_id:str = kwargs.get('application_id') + self.title_name:str = kwargs.get('title_name') + self.icon_url:str = kwargs.get('icon_url') + self.icon_sizes:typing.List[int] = kwargs.get('icon_sizes') + self.classic_title_id:str = kwargs.get('classic_title_id') + self.classic_title_icon_url:str = kwargs.get('classic_title_icon_url') + + def __str__(self) -> str: + return toString(self) + +class Distribution: + """ + iterable : dict + Keys: + language : str + thumbnail_url : str + cover_image_url : str + cover_video_url : str + button : Button + content : None || str + """ + def __init__(self, **kwargs:dict) -> None: + self.language:str = kwargs.get('language') + self.thumbnail_url:str = kwargs.get('thumbnail_url') + self.cover_image_url:str = kwargs.get('cover_image_url') + self.cover_video_url:str = kwargs.get('cover_video_url') + self.button:Button = Button() if kwargs.get('button', {}) is None else Button(**kwargs.get('button', {})) + self.content:str = kwargs.get('content') + + def __str__(self) -> str: + return toString(self) + +class Button: + """ + iterable : dict + Keys: + text : str + url : str + """ + def __init__(self, **kwargs:dict) -> None: + self.text:str = kwargs.get('text') + self.url:str = kwargs.get('url') + + def __str__(self) -> str: + return toString(self) diff --git a/nso/util.py b/nso/util.py index c41e6ab..3275d69 100644 --- a/nso/util.py +++ b/nso/util.py @@ -19,6 +19,6 @@ def toString(self, indent:int = 0) -> str: if hasattr(value, '__dict__'): value = '\n' + toString(value, indent + 1) if isinstance(value, list): - value = '[\n' + ',\n\n'.join( (toString(object, indent + 1) if hasattr(object, '__dict__') else ((' ' * (indent + 1)) + object)) for object in value ) + '\n' + (' ' * indent) + ']' + value = '[\n' + ',\n\n'.join( (toString(object, indent + 1) if hasattr(object, '__dict__') else ((' ' * (indent + 1)) + str(object))) for object in value ) + '\n' + (' ' * indent) + ']' ret.append((key, value)) return (' ' * indent) + 'Object: ' + type(self).__name__ + '\n' + '\n'.join([ (' ' * indent) + '%s: %s' % (key, value) for key, value in ret ])