Compare commits

..

5 Commits
0.1 ... 0.2

Author SHA1 Message Date
Romuald Juchnowicz-Bierbasz
3e34edf5e7 Increment version 2019-02-13 08:23:07 +01:00
Romuald Juchnowicz-Bierbasz
0d52b3dda6 SDK-2526: Refactor authentication 2019-02-12 17:55:28 +01:00
Romuald Juchnowicz-Bierbasz
00fe3dd553 SDK-2520: Skipt deployment for tags 2019-02-11 15:12:57 +01:00
Romuald Juchnowicz-Bierbasz
20143e3b4f SDK-2520: Fix typo 2019-02-11 15:11:18 +01:00
Romuald Juchnowicz-Bierbasz
0b9b2dc8d3 SDK-2520: Add docs 2019-02-11 15:09:23 +01:00
7 changed files with 41 additions and 20 deletions

View File

@@ -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

View File

@@ -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
```

View File

@@ -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()

View File

@@ -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 = {

View File

@@ -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',

View File

@@ -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",

View File

@@ -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()