mirror of
https://github.com/gogcom/galaxy-integrations-python-api.git
synced 2026-01-01 11:28:12 -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
|
- 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}"
|
"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
|
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
|
# implemented by developer
|
||||||
self._register_method("init_authentication", self.authenticate)
|
self._register_method("init_authentication", self.authenticate)
|
||||||
self._register_method("pass_login_credentials", self.pass_login_credentials)
|
|
||||||
self._register_method(
|
self._register_method(
|
||||||
"import_owned_games",
|
"import_owned_games",
|
||||||
self.get_owned_games,
|
self.get_owned_games,
|
||||||
@@ -255,16 +254,11 @@ class Plugin():
|
|||||||
# methods
|
# methods
|
||||||
async def authenticate(self, stored_credentials=None):
|
async def authenticate(self, stored_credentials=None):
|
||||||
"""Overide this method to handle plugin authentication.
|
"""Overide this method to handle plugin authentication.
|
||||||
The method should return one of:
|
The method should return galaxy.api.types.Authentication
|
||||||
- galaxy.api.types.AuthenticationSuccess - on successful authencication
|
or raise galaxy.api.types.LoginError on authentication failure.
|
||||||
- galaxy.api.types.NextStep - when more authentication steps are required
|
|
||||||
Or raise galaxy.api.types.LoginError on authentication failure.
|
|
||||||
"""
|
"""
|
||||||
raise NotImplementedError()
|
raise NotImplementedError()
|
||||||
|
|
||||||
async def pass_login_credentials(self, step, credentials):
|
|
||||||
raise NotImplementedError()
|
|
||||||
|
|
||||||
async def get_owned_games(self):
|
async def get_owned_games(self):
|
||||||
raise NotImplementedError()
|
raise NotImplementedError()
|
||||||
|
|
||||||
|
|||||||
@@ -5,15 +5,10 @@ from galaxy.api.jsonrpc import ApplicationError
|
|||||||
from galaxy.api.consts import LocalGameState, PresenceState
|
from galaxy.api.consts import LocalGameState, PresenceState
|
||||||
|
|
||||||
@dataclass
|
@dataclass
|
||||||
class AuthenticationSuccess():
|
class Authentication():
|
||||||
user_id: str
|
user_id: str
|
||||||
user_name: str
|
user_name: str
|
||||||
|
|
||||||
@dataclass
|
|
||||||
class NextStep():
|
|
||||||
next_step: str
|
|
||||||
auth_params: dict
|
|
||||||
|
|
||||||
class LoginError(ApplicationError):
|
class LoginError(ApplicationError):
|
||||||
def __init__(self, current_step, reason):
|
def __init__(self, current_step, reason):
|
||||||
data = {
|
data = {
|
||||||
|
|||||||
2
setup.py
2
setup.py
@@ -2,7 +2,7 @@ from setuptools import setup, find_packages
|
|||||||
|
|
||||||
setup(
|
setup(
|
||||||
name="galaxy.plugin.api",
|
name="galaxy.plugin.api",
|
||||||
version="0.1",
|
version="0.2",
|
||||||
description="Galaxy python plugin API",
|
description="Galaxy python plugin API",
|
||||||
author='Galaxy team',
|
author='Galaxy team',
|
||||||
author_email='galaxy@gog.com',
|
author_email='galaxy@gog.com',
|
||||||
|
|||||||
@@ -14,7 +14,6 @@ def plugin():
|
|||||||
"""Return plugin instance with all feature methods mocked"""
|
"""Return plugin instance with all feature methods mocked"""
|
||||||
async_methods = (
|
async_methods = (
|
||||||
"authenticate",
|
"authenticate",
|
||||||
"pass_login_credentials",
|
|
||||||
"get_owned_games",
|
"get_owned_games",
|
||||||
"get_unlocked_achievements",
|
"get_unlocked_achievements",
|
||||||
"get_local_games",
|
"get_local_games",
|
||||||
|
|||||||
@@ -1,7 +1,7 @@
|
|||||||
import asyncio
|
import asyncio
|
||||||
import json
|
import json
|
||||||
|
|
||||||
from galaxy.api.types import AuthenticationSuccess, LoginError
|
from galaxy.api.types import Authentication, LoginError
|
||||||
|
|
||||||
def test_success(plugin, readline, write):
|
def test_success(plugin, readline, write):
|
||||||
request = {
|
request = {
|
||||||
@@ -11,7 +11,7 @@ def test_success(plugin, readline, write):
|
|||||||
}
|
}
|
||||||
|
|
||||||
readline.side_effect = [json.dumps(request), ""]
|
readline.side_effect = [json.dumps(request), ""]
|
||||||
plugin.authenticate.return_value = AuthenticationSuccess("132", "Zenek")
|
plugin.authenticate.return_value = Authentication("132", "Zenek")
|
||||||
asyncio.run(plugin.run())
|
asyncio.run(plugin.run())
|
||||||
plugin.authenticate.assert_called_with()
|
plugin.authenticate.assert_called_with()
|
||||||
response = json.loads(write.call_args[0][0])
|
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), ""]
|
readline.side_effect = [json.dumps(request), ""]
|
||||||
plugin.authenticate.return_value = AuthenticationSuccess("132", "Zenek")
|
plugin.authenticate.return_value = Authentication("132", "Zenek")
|
||||||
asyncio.run(plugin.run())
|
asyncio.run(plugin.run())
|
||||||
plugin.authenticate.assert_called_with(stored_credentials={"token": "ABC"})
|
plugin.authenticate.assert_called_with(stored_credentials={"token": "ABC"})
|
||||||
write.assert_called()
|
write.assert_called()
|
||||||
|
|||||||
Reference in New Issue
Block a user