Skip to content

Commit ad758b0

Browse files
author
Mateusz Silaczewski
committedMar 23, 2020
subscription settings
1 parent 9062944 commit ad758b0

File tree

4 files changed

+34
-7
lines changed

4 files changed

+34
-7
lines changed
 

‎setup.py

+1-1
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22

33
setup(
44
name="galaxy.plugin.api",
5-
version="0.64",
5+
version="0.65",
66
description="GOG Galaxy Integrations Python API",
77
author='Galaxy team',
88
author_email='galaxy@gog.com',

‎src/galaxy/api/consts.py

+10
Original file line numberDiff line numberDiff line change
@@ -152,3 +152,13 @@ class PresenceState(Enum):
152152
Online = "online"
153153
Offline = "offline"
154154
Away = "away"
155+
156+
157+
class SubscriptionDiscovery(Flag):
158+
"""Possible capabilities which inform what methods of subscriptions ownership detection are supported.
159+
160+
:param AUTOMATIC: integration can retrieve the proper status of subscription ownership.
161+
:param USER_ENABLED: integration can handle override of ~class::`Subscription.owned` value to True
162+
"""
163+
AUTOMATIC = 1
164+
USER_ENABLED = 2

‎src/galaxy/api/types.py

+13-1
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
from dataclasses import dataclass
22
from typing import Dict, List, Optional
33

4-
from galaxy.api.consts import LicenseType, LocalGameState, PresenceState
4+
from galaxy.api.consts import LicenseType, LocalGameState, PresenceState, SubscriptionDiscovery
55

66

77
@dataclass
@@ -217,17 +217,29 @@ class UserPresence:
217217
in_game_status: Optional[str] = None
218218
full_status: Optional[str] = None
219219

220+
220221
@dataclass
221222
class Subscription:
222223
"""Information about a subscription.
223224
224225
:param subscription_name: name of the subscription, will also be used as its identifier.
225226
:param owned: whether the subscription is owned or not, None if unknown.
226227
:param end_time: unix timestamp of when the subscription ends, None if unknown.
228+
:param subscription_discovery: combination of settings that can be manually
229+
chosen by user to determine subscription handling behaviour. For example, if the integration cannot retrieve games
230+
for subscription when user doesn't own it, then USER_ENABLED should not be used.
231+
If the integration cannot determine subscription ownership for a user then AUTOMATIC should not be used.
232+
227233
"""
228234
subscription_name: str
229235
owned: Optional[bool] = None
230236
end_time: Optional[int] = None
237+
subscription_discovery: SubscriptionDiscovery = SubscriptionDiscovery.AUTOMATIC | \
238+
SubscriptionDiscovery.USER_ENABLED
239+
240+
def __post_init__(self):
241+
assert self.subscription_discovery in [SubscriptionDiscovery.AUTOMATIC, SubscriptionDiscovery.USER_ENABLED,
242+
SubscriptionDiscovery.AUTOMATIC | SubscriptionDiscovery.USER_ENABLED]
231243

232244

233245
@dataclass

‎tests/test_subscriptions.py

+10-5
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
import pytest
22

33
from galaxy.api.types import Subscription, SubscriptionGame
4+
from galaxy.api.consts import SubscriptionDiscovery
45
from galaxy.api.errors import FailedParsingManifest, BackendError, UnknownError
56
from galaxy.unittest.mock import async_return_value
67

@@ -17,8 +18,8 @@ async def test_get_subscriptions_success(plugin, read, write):
1718

1819
plugin.get_subscriptions.return_value = async_return_value([
1920
Subscription("1"),
20-
Subscription("2", False),
21-
Subscription("3", True, 1580899100)
21+
Subscription("2", False, subscription_discovery=SubscriptionDiscovery.AUTOMATIC),
22+
Subscription("3", True, 1580899100, SubscriptionDiscovery.USER_ENABLED)
2223
])
2324
await plugin.run()
2425
plugin.get_subscriptions.assert_called_with()
@@ -30,16 +31,19 @@ async def test_get_subscriptions_success(plugin, read, write):
3031
"result": {
3132
"subscriptions": [
3233
{
33-
"subscription_name": "1"
34+
"subscription_name": "1",
35+
'subscription_discovery': 3
3436
},
3537
{
3638
"subscription_name": "2",
37-
"owned": False
39+
"owned": False,
40+
'subscription_discovery': 1
3841
},
3942
{
4043
"subscription_name": "3",
4144
"owned": True,
42-
"end_time": 1580899100
45+
"end_time": 1580899100,
46+
'subscription_discovery': 2
4347
}
4448
]
4549
}
@@ -77,6 +81,7 @@ async def test_get_subscriptions_failure_generic(plugin, read, write, error, cod
7781
}
7882
]
7983

84+
8085
@pytest.mark.asyncio
8186
async def test_get_subscription_games_success(plugin, read, write):
8287
plugin.prepare_subscription_games_context.return_value = async_return_value(5)

0 commit comments

Comments
 (0)
Please sign in to comment.