mirror of
https://github.com/gogcom/galaxy-integrations-python-api.git
synced 2025-12-31 19:08:16 -05:00
Compare commits
16 Commits
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
7b9bcf86a1 | ||
|
|
30b3533e1d | ||
|
|
92b1d8e4df | ||
|
|
4adef2dace | ||
|
|
1430fe39d7 | ||
|
|
c591efc493 | ||
|
|
7c4f3fba5b | ||
|
|
f2e2e41d04 | ||
|
|
25b850d8bb | ||
|
|
403736612a | ||
|
|
3071c2e771 | ||
|
|
23ef34bed5 | ||
|
|
a4b08f8105 | ||
|
|
4d62b8ccb8 | ||
|
|
d759b4aa85 | ||
|
|
9b33397827 |
@@ -34,6 +34,8 @@ pytest
|
||||
|
||||
## Changelog
|
||||
|
||||
### 0.21
|
||||
* Add `Epic` platform.
|
||||
### 0.16
|
||||
* Do not log sensitive data.
|
||||
* Return `LocalGameState` as int (possible combination of flags).
|
||||
|
||||
@@ -0,0 +1 @@
|
||||
__path__ = __import__('pkgutil').extend_path(__path__, __name__)
|
||||
|
||||
@@ -10,6 +10,7 @@ class Platform(Enum):
|
||||
Origin = "origin"
|
||||
Uplay = "uplay"
|
||||
Battlenet = "battlenet"
|
||||
Epic = "epic"
|
||||
|
||||
class Feature(Enum):
|
||||
Unknown = "Unknown"
|
||||
|
||||
@@ -6,7 +6,6 @@ import dataclasses
|
||||
from enum import Enum
|
||||
from collections import OrderedDict
|
||||
import sys
|
||||
import os
|
||||
|
||||
from galaxy.api.jsonrpc import Server, NotificationClient
|
||||
from galaxy.api.consts import Feature
|
||||
@@ -49,6 +48,7 @@ class Plugin():
|
||||
|
||||
# implemented by developer
|
||||
self._register_method("init_authentication", self.authenticate, sensitive_params=["stored_credentials"])
|
||||
self._register_method("pass_login_credentials", self.pass_login_credentials)
|
||||
self._register_method(
|
||||
"import_owned_games",
|
||||
self.get_owned_games,
|
||||
@@ -274,6 +274,9 @@ class Plugin():
|
||||
"""
|
||||
raise NotImplementedError()
|
||||
|
||||
async def pass_login_credentials(self, step, credentials, cookies):
|
||||
raise NotImplementedError()
|
||||
|
||||
async def get_owned_games(self):
|
||||
raise NotImplementedError()
|
||||
|
||||
@@ -316,29 +319,7 @@ class Plugin():
|
||||
async def get_game_times(self):
|
||||
raise NotImplementedError()
|
||||
|
||||
def _prepare_logging(logger_file):
|
||||
root = logging.getLogger()
|
||||
root.setLevel(logging.DEBUG)
|
||||
if logger_file:
|
||||
# ensure destination folder exists
|
||||
os.makedirs(os.path.dirname(os.path.abspath(logger_file)), exist_ok=True)
|
||||
handler = logging.handlers.RotatingFileHandler(
|
||||
logger_file,
|
||||
mode="a",
|
||||
maxBytes=10000000,
|
||||
backupCount=10,
|
||||
encoding="utf-8"
|
||||
)
|
||||
else:
|
||||
handler = logging.StreamHandler()
|
||||
formatter = logging.Formatter('%(asctime)s - %(name)s - %(levelname)s - %(message)s')
|
||||
handler.setFormatter(formatter)
|
||||
root.addHandler(handler)
|
||||
|
||||
def create_and_run_plugin(plugin_class, argv):
|
||||
logger_file = argv[3] if len(argv) >= 4 else None
|
||||
_prepare_logging(logger_file)
|
||||
|
||||
if len(argv) < 3:
|
||||
logging.critical("Not enough parameters, required: token, port")
|
||||
sys.exit(1)
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
from dataclasses import dataclass
|
||||
from typing import List, Optional
|
||||
from typing import List, Dict, Optional
|
||||
|
||||
from galaxy.api.consts import LicenseType, LocalGameState, PresenceState
|
||||
|
||||
@@ -8,6 +8,19 @@ class Authentication():
|
||||
user_id: str
|
||||
user_name: str
|
||||
|
||||
@dataclass
|
||||
class Cookie():
|
||||
name: str
|
||||
value: str
|
||||
domain: Optional[str] = None
|
||||
path: Optional[str] = None
|
||||
|
||||
@dataclass
|
||||
class NextStep():
|
||||
next_step: str
|
||||
auth_params: Dict[str, str]
|
||||
cookies: Optional[List[Cookie]] = None
|
||||
|
||||
@dataclass
|
||||
class LicenseInfo():
|
||||
license_type: LicenseType
|
||||
@@ -23,7 +36,7 @@ class Dlc():
|
||||
class Game():
|
||||
game_id: str
|
||||
game_title: str
|
||||
dlcs: List[Dlc]
|
||||
dlcs: Optional[List[Dlc]]
|
||||
license_info: LicenseInfo
|
||||
|
||||
@dataclass
|
||||
|
||||
20
galaxy/tools.py
Normal file
20
galaxy/tools.py
Normal file
@@ -0,0 +1,20 @@
|
||||
import io
|
||||
import os
|
||||
import zipfile
|
||||
from glob import glob
|
||||
|
||||
def zip_folder(folder):
|
||||
files = glob(os.path.join(folder, "**"), recursive=True)
|
||||
files = [file.replace(folder + os.sep, "") for file in files]
|
||||
files = [file for file in files if file]
|
||||
|
||||
zip_buffer = io.BytesIO()
|
||||
with zipfile.ZipFile(zip_buffer, mode="w", compression=zipfile.ZIP_DEFLATED) as zipf:
|
||||
for file in files:
|
||||
zipf.write(os.path.join(folder, file), arcname=file)
|
||||
return zip_buffer
|
||||
|
||||
def zip_folder_to_file(folder, filename):
|
||||
zip_content = zip_folder(folder).getbuffer()
|
||||
with open(filename, "wb") as archive:
|
||||
archive.write(zip_content)
|
||||
0
galaxy/unittest/__init__.py
Normal file
0
galaxy/unittest/__init__.py
Normal file
@@ -2,5 +2,4 @@ from unittest.mock import MagicMock
|
||||
|
||||
class AsyncMock(MagicMock):
|
||||
async def __call__(self, *args, **kwargs):
|
||||
# pylint: disable=useless-super-delegation
|
||||
return super(AsyncMock, self).__call__(*args, **kwargs)
|
||||
2
setup.py
2
setup.py
@@ -2,7 +2,7 @@ from setuptools import setup, find_packages
|
||||
|
||||
setup(
|
||||
name="galaxy.plugin.api",
|
||||
version="0.18",
|
||||
version="0.23",
|
||||
description="Galaxy python plugin API",
|
||||
author='Galaxy team',
|
||||
author_email='galaxy@gog.com',
|
||||
|
||||
@@ -6,7 +6,7 @@ import pytest
|
||||
|
||||
from galaxy.api.plugin import Plugin
|
||||
from galaxy.api.consts import Platform
|
||||
from tests.async_mock import AsyncMock
|
||||
from galaxy.unittest.mock import AsyncMock
|
||||
|
||||
@pytest.fixture()
|
||||
def reader():
|
||||
|
||||
Reference in New Issue
Block a user