-
Notifications
You must be signed in to change notification settings - Fork 2
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #7 from jplacht/feat-storage
Add FIO storage endpoints
- Loading branch information
Showing
12 changed files
with
435 additions
and
3 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,14 @@ | ||
Exposes FIO Storage data for users. | ||
All storage data requires a **FIO API KEY**. You will need to have access to the data the user has in FIO in order to access it. | ||
|
||
Example: | ||
```python | ||
from fio_wrapper import FIO | ||
|
||
fio = FIO(api_key="your_api_key") | ||
|
||
# Get users storage data | ||
user_storage = fio.Sites.get(username="PrUn username") | ||
``` | ||
|
||
::: endpoints.endpoints_v1.storage |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,9 @@ | ||
class AbstractStorage: | ||
def get(self, username: str): | ||
raise NotImplemented() | ||
|
||
def get_specific(self, username: str, specific: str): | ||
raise NotImplemented() | ||
|
||
def planets(self, username: str): | ||
raise NotImplemented() |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,100 @@ | ||
from typing import List | ||
from fio_wrapper.decorator import apikey_required | ||
from fio_wrapper.endpoints.abstracts.abstract_endpoint import AbstractEndpoint | ||
from fio_wrapper.endpoints.abstracts.abstract_storage import AbstractStorage | ||
from fio_wrapper.exceptions import NoStorageData, NotAuthenticated | ||
from fio_wrapper.models.storage_models import StorageList, Storage as StorageModel | ||
|
||
|
||
class Storage(AbstractStorage, AbstractEndpoint): | ||
@apikey_required | ||
def get(self, username: str) -> StorageList: | ||
"""Gets users storage data from FIO | ||
Note: | ||
FIO API Key Required | ||
Args: | ||
username (str): Prosperous Universe username | ||
Raises: | ||
NoStorageData: Username has no storage data | ||
NotAuthenticated: Not authenticated or no appropiate permissions | ||
Returns: | ||
StorageList: List of storages | ||
""" | ||
(status, data) = self._adapter.get( | ||
endpoint=self._adapter.urls.storage_get_url(username=username), | ||
err_codes=[204, 401], | ||
) | ||
|
||
if status == 200: | ||
return StorageList.model_validate(data) | ||
|
||
elif status == 204: | ||
raise NoStorageData("Username has no storage data") | ||
elif status == 401: | ||
raise NotAuthenticated("Not authenticated or no appropiate permissions") | ||
|
||
@apikey_required | ||
def get_specific(self, username: str, specific: str) -> StorageModel: | ||
"""Gets users specific storage data from FIO | ||
Note: | ||
FIO API Key Required | ||
Args: | ||
username (str): Prosperous Universe username | ||
specific (str): StorageId, PlanetId, PlanetNaturalId or PlanetName | ||
Raises: | ||
NoStorageData: Username has no storage data | ||
NotAuthenticated: Not authenticated or no appropiate permissions | ||
Returns: | ||
StorageModel: Storage data | ||
""" | ||
(status, data) = self._adapter.get( | ||
endpoint=self._adapter.urls.storage_get_specific_url( | ||
username=username, specific=specific | ||
), | ||
err_codes=[204, 401], | ||
) | ||
|
||
if status == 200: | ||
return StorageModel.model_validate(data) | ||
|
||
elif status == 204: | ||
raise NoStorageData("Username has no storage data") | ||
elif status == 401: | ||
raise NotAuthenticated("Not authenticated or no appropiate permissions") | ||
|
||
@apikey_required | ||
def planets(self, username: str) -> List[str]: | ||
"""Returns a list of storages from FIO | ||
Note: | ||
FIO API Key Required | ||
Args: | ||
username (str): Prosperous Universe username | ||
Raises: | ||
NoStorageData: Username has no storage data | ||
NotAuthenticated: Not authenticated or no appropiate permissions | ||
Returns: | ||
List[str]: List of StorageIds | ||
""" | ||
(status, data) = self._adapter.get( | ||
endpoint=self._adapter.urls.storage_planets_get_url(username=username), | ||
err_codes=[204, 401], | ||
) | ||
|
||
if status == 200: | ||
return data | ||
elif status == 204: | ||
raise NoStorageData("Username has no storage data") | ||
elif status == 401: | ||
raise NotAuthenticated("Not authenticated or no appropiate permissions") |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,39 @@ | ||
from typing import List, Optional | ||
from datetime import datetime | ||
from pydantic import BaseModel, RootModel, Field, NaiveDatetime | ||
|
||
|
||
class StorageItem(BaseModel): | ||
MaterialId: str = Field(min_length=32) | ||
MaterialName: Optional[str] | ||
MaterialTicker: Optional[str] = Field(max_length=3, default=None) | ||
MaterialCategory: Optional[str] = Field(min_length=32, default=None) | ||
MaterialWeight: float | ||
MaterialVolume: float | ||
MaterialAmount: int | ||
MaterialValue: float | ||
MaterialValueCurrency: Optional[str] | ||
Type: str | ||
TotalWeight: float | ||
TotalVolume: float | ||
|
||
|
||
class Storage(BaseModel): | ||
StorageItems: Optional[List[StorageItem]] | ||
StorageId: str = Field(min_length=32) | ||
AddressableId: str = Field(min_length=32) | ||
Name: Optional[str] | ||
Type: str | ||
UserNameSubmitted: str | ||
Timestamp: datetime | ||
WeightCapacity: int | ||
VolumeCapacity: int | ||
UserNameSubmitted: str | ||
Timestamp: NaiveDatetime | ||
|
||
|
||
class StorageList(RootModel): | ||
root: List[Storage] | ||
|
||
def __iter__(self): | ||
return iter(self.root) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.