mirror of
https://github.com/gogcom/galaxy-integrations-python-api.git
synced 2026-01-01 03:18:25 -05:00
Compare commits
5 Commits
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
3e34edf5e7 | ||
|
|
0d52b3dda6 | ||
|
|
00fe3dd553 | ||
|
|
20143e3b4f | ||
|
|
0b9b2dc8d3 |
@@ -20,3 +20,5 @@ deploy_package:
|
||||
- curl -X POST --silent --show-error --fail
|
||||
"https://gitlab.gog.com/api/v4/projects/${CI_PROJECT_ID}/repository/tags?tag_name=${VERSION}&ref=${CI_COMMIT_REF_NAME}&private_token=${PACKAGE_DEPLOYER_API_TOKEN}"
|
||||
when: manual
|
||||
except:
|
||||
- tags
|
||||
33
README.md
33
README.md
@@ -1,2 +1,33 @@
|
||||
# galaxy-plugin-api
|
||||
# Galaxy python plugin API
|
||||
|
||||
## Usage
|
||||
|
||||
Implement plugin:
|
||||
|
||||
```python
|
||||
import asyncio
|
||||
from galaxy.api.plugin import Plugin
|
||||
|
||||
class PluginExample(Plugin):
|
||||
# implement methods
|
||||
async def authenticate(self, stored_credentials=None):
|
||||
pass
|
||||
|
||||
# run plugin event loop
|
||||
if __name__ == "__main__":
|
||||
asyncio.run(MockPlugin().run())
|
||||
```
|
||||
|
||||
Use [pyinstaller](https://www.pyinstaller.org/) to create plugin executbale.
|
||||
|
||||
## Development
|
||||
|
||||
Install required packages:
|
||||
```bash
|
||||
pip install -r requirements.txt
|
||||
```
|
||||
|
||||
Run tests:
|
||||
```bash
|
||||
pytest
|
||||
```
|
||||
@@ -44,7 +44,6 @@ class Plugin():
|
||||
|
||||
# implemented by developer
|
||||
self._register_method("init_authentication", self.authenticate)
|
||||
self._register_method("pass_login_credentials", self.pass_login_credentials)
|
||||
self._register_method(
|
||||
"import_owned_games",
|
||||
self.get_owned_games,
|
||||
@@ -255,16 +254,11 @@ class Plugin():
|
||||
# methods
|
||||
async def authenticate(self, stored_credentials=None):
|
||||
"""Overide this method to handle plugin authentication.
|
||||
The method should return one of:
|
||||
- galaxy.api.types.AuthenticationSuccess - on successful authencication
|
||||
- galaxy.api.types.NextStep - when more authentication steps are required
|
||||
Or raise galaxy.api.types.LoginError on authentication failure.
|
||||
The method should return galaxy.api.types.Authentication
|
||||
or raise galaxy.api.types.LoginError on authentication failure.
|
||||
"""
|
||||
raise NotImplementedError()
|
||||
|
||||
async def pass_login_credentials(self, step, credentials):
|
||||
raise NotImplementedError()
|
||||
|
||||
async def get_owned_games(self):
|
||||
raise NotImplementedError()
|
||||
|
||||
|
||||
@@ -5,15 +5,10 @@ from galaxy.api.jsonrpc import ApplicationError
|
||||
from galaxy.api.consts import LocalGameState, PresenceState
|
||||
|
||||
@dataclass
|
||||
class AuthenticationSuccess():
|
||||
class Authentication():
|
||||
user_id: str
|
||||
user_name: str
|
||||
|
||||
@dataclass
|
||||
class NextStep():
|
||||
next_step: str
|
||||
auth_params: dict
|
||||
|
||||
class LoginError(ApplicationError):
|
||||
def __init__(self, current_step, reason):
|
||||
data = {
|
||||
|
||||
2
setup.py
2
setup.py
@@ -2,7 +2,7 @@ from setuptools import setup, find_packages
|
||||
|
||||
setup(
|
||||
name="galaxy.plugin.api",
|
||||
version="0.1",
|
||||
version="0.2",
|
||||
description="Galaxy python plugin API",
|
||||
author='Galaxy team',
|
||||
author_email='galaxy@gog.com',
|
||||
|
||||
@@ -14,7 +14,6 @@ def plugin():
|
||||
"""Return plugin instance with all feature methods mocked"""
|
||||
async_methods = (
|
||||
"authenticate",
|
||||
"pass_login_credentials",
|
||||
"get_owned_games",
|
||||
"get_unlocked_achievements",
|
||||
"get_local_games",
|
||||
|
||||
@@ -1,7 +1,7 @@
|
||||
import asyncio
|
||||
import json
|
||||
|
||||
from galaxy.api.types import AuthenticationSuccess, LoginError
|
||||
from galaxy.api.types import Authentication, LoginError
|
||||
|
||||
def test_success(plugin, readline, write):
|
||||
request = {
|
||||
@@ -11,7 +11,7 @@ def test_success(plugin, readline, write):
|
||||
}
|
||||
|
||||
readline.side_effect = [json.dumps(request), ""]
|
||||
plugin.authenticate.return_value = AuthenticationSuccess("132", "Zenek")
|
||||
plugin.authenticate.return_value = Authentication("132", "Zenek")
|
||||
asyncio.run(plugin.run())
|
||||
plugin.authenticate.assert_called_with()
|
||||
response = json.loads(write.call_args[0][0])
|
||||
@@ -63,7 +63,7 @@ def test_stored_credentials(plugin, readline, write):
|
||||
}
|
||||
}
|
||||
readline.side_effect = [json.dumps(request), ""]
|
||||
plugin.authenticate.return_value = AuthenticationSuccess("132", "Zenek")
|
||||
plugin.authenticate.return_value = Authentication("132", "Zenek")
|
||||
asyncio.run(plugin.run())
|
||||
plugin.authenticate.assert_called_with(stored_credentials={"token": "ABC"})
|
||||
write.assert_called()
|
||||
|
||||
Reference in New Issue
Block a user