wom-py 0.1.0__py3-none-any.whl

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
wom/__init__.py ADDED
@@ -0,0 +1,143 @@
1
+ # wom.py - An asynchronous wrapper for the Wise Old Man API.
2
+ # Copyright (c) 2023-present Jonxslays
3
+ #
4
+ # Permission is hereby granted, free of charge, to any person obtaining a copy
5
+ # of this software and associated documentation files (the "Software"), to deal
6
+ # in the Software without restriction, including without limitation the rights
7
+ # to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
8
+ # copies of the Software, and to permit persons to whom the Software is
9
+ # furnished to do so, subject to the following conditions:
10
+ #
11
+ # The above copyright notice and this permission notice shall be included in all
12
+ # copies or substantial portions of the Software.
13
+ #
14
+ # THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
15
+ # IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
16
+ # FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
17
+ # AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
18
+ # LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
19
+ # OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
20
+ # SOFTWARE.
21
+
22
+ """All models, enums, services, etc are exported here in the main
23
+ wom module.
24
+
25
+ !!! tip
26
+
27
+ Know what you're looking for? Hit the search bar ^!
28
+ """
29
+
30
+ from __future__ import annotations
31
+
32
+ from typing import Final
33
+
34
+ __all__ = (
35
+ "client",
36
+ "constants",
37
+ "enums",
38
+ "errors",
39
+ "models",
40
+ "result",
41
+ "routes",
42
+ "serializer",
43
+ "services",
44
+ "Achievement",
45
+ "AchievementMeasure",
46
+ "AchievementProgress",
47
+ "Activities",
48
+ "Activity",
49
+ "BaseEnum",
50
+ "Boss",
51
+ "Bosses",
52
+ "BaseModel",
53
+ "Client",
54
+ "Country",
55
+ "Competition",
56
+ "CompetitionDetail",
57
+ "CompetitionHistoryDataPoint",
58
+ "CompetitionParticipationDetail",
59
+ "CompetitionParticipation",
60
+ "CompetitionProgress",
61
+ "CompetitionStatus",
62
+ "CompetitionType",
63
+ "CompetitionWithParticipations",
64
+ "CompiledRoute",
65
+ "ComputedMetric",
66
+ "ComputedMetrics",
67
+ "DeltaLeaderboardEntry",
68
+ "Err",
69
+ "Gains",
70
+ "GroupDetail",
71
+ "GroupHiscoresActivityItem",
72
+ "GroupHiscoresBossItem",
73
+ "GroupHiscoresComputedMetricItem",
74
+ "GroupHiscoresEntry",
75
+ "GroupHiscoresSkillItem",
76
+ "GroupMemberFragment",
77
+ "GroupMembership",
78
+ "Group",
79
+ "GroupRole",
80
+ "GroupStatistics",
81
+ "HttpErrorResponse",
82
+ "HttpSuccessResponse",
83
+ "Membership",
84
+ "Metric",
85
+ "NameChangeData",
86
+ "NameChangeDetail",
87
+ "NameChange",
88
+ "NameChangeStatus",
89
+ "Ok",
90
+ "Participation",
91
+ "Period",
92
+ "PlayerAchievementProgress",
93
+ "PlayerBuild",
94
+ "PlayerCompetitionStanding",
95
+ "PlayerMembership",
96
+ "Player",
97
+ "PlayerDetail",
98
+ "PlayerParticipation",
99
+ "PlayerType",
100
+ "Record",
101
+ "RecordLeaderboardEntry",
102
+ "Result",
103
+ "Route",
104
+ "Serializer",
105
+ "Skill",
106
+ "Skills",
107
+ "SnapshotData",
108
+ "Snapshot",
109
+ "StatisticsSnapshot",
110
+ "Team",
111
+ "Top5ProgressResult",
112
+ "UnwrapError",
113
+ "WomError",
114
+ )
115
+
116
+ __packagename__: Final[str] = "wom.py"
117
+ __version__: Final[str] = "0.1.0"
118
+ __author__: Final[str] = "Jonxslays"
119
+ __copyright__: Final[str] = "2023-present Jonxslays"
120
+ __description__: Final[str] = "An asynchronous wrapper for the Wise Old Man API."
121
+ __url__: Final[str] = "https://github.com/Jonxslays/wom.py"
122
+ __docs__: Final[str] = "https://jonxslays.github.io/wom.py"
123
+ __repository__: Final[str] = __url__
124
+ __license__: Final[str] = "MIT"
125
+ __git_sha__: Final[str] = "[d194af2]"
126
+
127
+ from . import client
128
+ from . import constants
129
+ from . import enums
130
+ from . import errors
131
+ from . import models
132
+ from . import result
133
+ from . import routes
134
+ from . import serializer
135
+ from . import services
136
+ from .client import *
137
+ from .enums import *
138
+ from .errors import *
139
+ from .models import *
140
+ from .result import *
141
+ from .routes import *
142
+ from .serializer import *
143
+ from .services import *
wom/__main__.py ADDED
@@ -0,0 +1,29 @@
1
+ # wom.py - An asynchronous wrapper for the Wise Old Man API.
2
+ # Copyright (c) 2023-present Jonxslays
3
+ #
4
+ # Permission is hereby granted, free of charge, to any person obtaining a copy
5
+ # of this software and associated documentation files (the "Software"), to deal
6
+ # in the Software without restriction, including without limitation the rights
7
+ # to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
8
+ # copies of the Software, and to permit persons to whom the Software is
9
+ # furnished to do so, subject to the following conditions:
10
+ #
11
+ # The above copyright notice and this permission notice shall be included in all
12
+ # copies or substantial portions of the Software.
13
+ #
14
+ # THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
15
+ # IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
16
+ # FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
17
+ # AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
18
+ # LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
19
+ # OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
20
+ # SOFTWARE.
21
+
22
+ """Main module entry point, provides version info and exits."""
23
+
24
+ from __future__ import annotations
25
+
26
+ from wom import _cli
27
+
28
+ if __name__ == "__main__":
29
+ _cli.info()
wom/_cli.py ADDED
@@ -0,0 +1,45 @@
1
+ # wom.py - An asynchronous wrapper for the Wise Old Man API.
2
+ # Copyright (c) 2023-present Jonxslays
3
+ #
4
+ # Permission is hereby granted, free of charge, to any person obtaining a copy
5
+ # of this software and associated documentation files (the "Software"), to deal
6
+ # in the Software without restriction, including without limitation the rights
7
+ # to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
8
+ # copies of the Software, and to permit persons to whom the Software is
9
+ # furnished to do so, subject to the following conditions:
10
+ #
11
+ # The above copyright notice and this permission notice shall be included in all
12
+ # copies or substantial portions of the Software.
13
+ #
14
+ # THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
15
+ # IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
16
+ # FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
17
+ # AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
18
+ # LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
19
+ # OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
20
+ # SOFTWARE.
21
+
22
+ """Provides cli functionality for versioning info."""
23
+
24
+ from __future__ import annotations
25
+
26
+ import platform
27
+ from pathlib import Path
28
+
29
+ from wom import __git_sha__
30
+ from wom import __version__
31
+
32
+
33
+ def info() -> None:
34
+ """Prints package/system info and exits."""
35
+ path = Path(__file__).parent.absolute()
36
+ py_impl = platform.python_implementation()
37
+ py_ver = platform.python_version()
38
+ py_c = platform.python_compiler()
39
+ p = platform.uname()
40
+
41
+ print(f"wom.py v{__version__} from {__git_sha__}")
42
+ print(f"@ {path}")
43
+ print(f"{py_impl} {py_ver} {py_c}")
44
+ print(f"{p.system} {p.node} {p.release} {p.machine}")
45
+ print(p.version)
wom/client.py ADDED
@@ -0,0 +1,276 @@
1
+ # wom.py - An asynchronous wrapper for the Wise Old Man API.
2
+ # Copyright (c) 2023-present Jonxslays
3
+ #
4
+ # Permission is hereby granted, free of charge, to any person obtaining a copy
5
+ # of this software and associated documentation files (the "Software"), to deal
6
+ # in the Software without restriction, including without limitation the rights
7
+ # to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
8
+ # copies of the Software, and to permit persons to whom the Software is
9
+ # furnished to do so, subject to the following conditions:
10
+ #
11
+ # The above copyright notice and this permission notice shall be included in all
12
+ # copies or substantial portions of the Software.
13
+ #
14
+ # THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
15
+ # IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
16
+ # FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
17
+ # AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
18
+ # LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
19
+ # OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
20
+ # SOFTWARE.
21
+
22
+ """This module houses the wom.py [`Client`][wom.Client].
23
+
24
+ Services related to different WOM endpoints are available for use on
25
+ the client. All functionality is encompassed in these service methods.
26
+
27
+ !!! example
28
+
29
+ ```py
30
+ from wom import Client
31
+
32
+ client = Client(user_agent="@your_discord_handle#1234")
33
+
34
+ result = await client.players.search_players("Jonxslays", limit=1)
35
+
36
+ if result.is_ok:
37
+ print(result.unwrap())
38
+ else:
39
+ print(f"ERROR: {result.unwrap_err()}")
40
+
41
+ await client.close()
42
+ ```
43
+ """
44
+
45
+ from __future__ import annotations
46
+
47
+ import typing as t
48
+
49
+ from wom import serializer
50
+ from wom import services
51
+
52
+ __all__ = ("Client",)
53
+
54
+ ServiceT = t.TypeVar("ServiceT")
55
+
56
+
57
+ class Client:
58
+ """An asynchronous client used for interacting with the
59
+ Wise Old Man API.
60
+
61
+ Args:
62
+ api_key: The optional WOM api key to use with requests.
63
+
64
+ Keyword Args:
65
+ user_agent: The optional user agent to use with requests. If none is
66
+ provided a library default will be used. Defaults to `None`.
67
+
68
+ api_base_url: The optional alternate api base url to use for requests.
69
+ Useful for development against a local version of the WOM api.
70
+ Defaults to `None`.
71
+
72
+ !!! note
73
+
74
+ None of the arguments are required, although user agent is highly
75
+ encouraged.
76
+
77
+ ??? example
78
+
79
+ ```py
80
+ from os import environ
81
+
82
+ import wom
83
+
84
+ client = wom.Client(
85
+ environ["WOM_API_KEY"], # The WOM api key if you have one
86
+ user_agent="@me#1234", # Identifier, i.e. discord username
87
+ api_base_url=environ["LOCAL_WOM_DOMAIN"],
88
+ # Typically you won't need to change the base url
89
+ )
90
+
91
+ # ... Use the client
92
+
93
+ await client.close() # Close the client
94
+ ```
95
+ """
96
+
97
+ __slots__ = (
98
+ "_competitions",
99
+ "_deltas",
100
+ "_efficiency",
101
+ "_groups",
102
+ "_http",
103
+ "_names",
104
+ "_players",
105
+ "_records",
106
+ "_serializer",
107
+ )
108
+
109
+ def __init__(
110
+ self,
111
+ api_key: str | None = None,
112
+ *,
113
+ user_agent: str | None = None,
114
+ api_base_url: str | None = None,
115
+ ) -> None:
116
+ self._serializer = serializer.Serializer()
117
+ self._http = services.HttpService(api_key, user_agent, api_base_url)
118
+ self.__init_core_services()
119
+
120
+ @property
121
+ def competitions(self) -> services.CompetitionService:
122
+ """The [`CompetitionService`][wom.CompetitionService] used to
123
+ make competition related requests.
124
+ """
125
+ return self._competitions
126
+
127
+ @property
128
+ def deltas(self) -> services.DeltaService:
129
+ """The [`DeltaService`][wom.DeltaService] used to make delta
130
+ related requests.
131
+ """
132
+ return self._deltas
133
+
134
+ @property
135
+ def efficiency(self) -> services.EfficiencyService:
136
+ """The [`EfficiencyService`][wom.EfficiencyService] used to make
137
+ efficiency related requests.
138
+ """
139
+ return self._efficiency
140
+
141
+ @property
142
+ def groups(self) -> services.GroupService:
143
+ """The [`GroupService`][wom.GroupService] used to make group
144
+ related requests.
145
+ """
146
+ return self._groups
147
+
148
+ @property
149
+ def names(self) -> services.NameChangeService:
150
+ """The [`NameChangeService`][wom.NameChangeService] used to make
151
+ name change related requests.
152
+ """
153
+ return self._names
154
+
155
+ @property
156
+ def players(self) -> services.PlayerService:
157
+ """The [`PlayerService`][wom.PlayerService] used to
158
+ make player related requests.
159
+ """
160
+ return self._players
161
+
162
+ @property
163
+ def records(self) -> services.RecordService:
164
+ """The [`RecordService`][wom.RecordService] used to
165
+ make record related requests.
166
+ """
167
+ return self._records
168
+
169
+ def __init_service(self, service: t.Type[ServiceT]) -> ServiceT:
170
+ if not issubclass(service, services.BaseService):
171
+ raise TypeError(f"{service.__name__!r} can not be initialized as a service.")
172
+
173
+ return service(self._http, self._serializer) # type: ignore[return-value]
174
+
175
+ def __init_core_services(self) -> None:
176
+ self._deltas = self.__init_service(services.DeltaService)
177
+ self._groups = self.__init_service(services.GroupService)
178
+ self._players = self.__init_service(services.PlayerService)
179
+ self._records = self.__init_service(services.RecordService)
180
+ self._names = self.__init_service(services.NameChangeService)
181
+ self._efficiency = self.__init_service(services.EfficiencyService)
182
+ self._competitions = self.__init_service(services.CompetitionService)
183
+
184
+ def set_api_key(self, api_key: str) -> None:
185
+ """Sets the api key used by the http service.
186
+
187
+ Args:
188
+ api_key: The new api key to use.
189
+
190
+ ??? example
191
+
192
+ ```py
193
+ import wom
194
+
195
+ client = wom.Client(...)
196
+
197
+ client.set_api_key("abc123")
198
+ ```
199
+ """
200
+ self._http.set_api_key(api_key)
201
+
202
+ def unset_api_key(self) -> None:
203
+ """Un-sets the current api key so it isn't sent with requests.
204
+
205
+ ??? example
206
+
207
+ ```py
208
+ import wom
209
+
210
+ client = wom.Client(api_key="abc123")
211
+
212
+ client.unset_api_key()
213
+ ```
214
+ """
215
+ self._http.unset_api_key()
216
+
217
+ def set_user_agent(self, user_agent: str) -> None:
218
+ """Sets the user agent used by the http service.
219
+
220
+ Args:
221
+ user_agent: The new user agent to use.
222
+
223
+ ??? example
224
+
225
+ ```py
226
+ import wom
227
+
228
+ client = wom.Client(...)
229
+
230
+ client.set_user_agent("@Hi#0000")
231
+ ```
232
+ """
233
+ self._http.set_user_agent(user_agent)
234
+
235
+ def set_api_base_url(self, base_url: str) -> None:
236
+ """Sets the api base url used by the http service.
237
+
238
+ Args:
239
+ base_url: The new base url to use.
240
+
241
+ ??? example
242
+
243
+ ```py
244
+ import wom
245
+
246
+ client = wom.Client(...)
247
+
248
+ client.set_api_base_url("https://api.wiseoldman.net/v2")
249
+ ```
250
+ """
251
+ self._http.set_base_url(base_url)
252
+
253
+ async def close(self) -> None:
254
+ """Closes the existing client session, if it's still open.
255
+
256
+ !!! tip
257
+
258
+ Only call this once, at the end of your program or if you are done
259
+ with the client completely.
260
+
261
+ !!! warning
262
+
263
+ If this is not called before your program terminates, you will
264
+ receive an error in your console.
265
+
266
+ ??? example
267
+
268
+ ```py
269
+ import wom
270
+
271
+ client = wom.Client(...)
272
+
273
+ await client.close()
274
+ ```
275
+ """
276
+ await self._http.close()
wom/constants.py ADDED
@@ -0,0 +1,30 @@
1
+ # wom.py - An asynchronous wrapper for the Wise Old Man API.
2
+ # Copyright (c) 2023-present Jonxslays
3
+ #
4
+ # Permission is hereby granted, free of charge, to any person obtaining a copy
5
+ # of this software and associated documentation files (the "Software"), to deal
6
+ # in the Software without restriction, including without limitation the rights
7
+ # to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
8
+ # copies of the Software, and to permit persons to whom the Software is
9
+ # furnished to do so, subject to the following conditions:
10
+ #
11
+ # The above copyright notice and this permission notice shall be included in all
12
+ # copies or substantial portions of the Software.
13
+ #
14
+ # THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
15
+ # IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
16
+ # FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
17
+ # AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
18
+ # LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
19
+ # OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
20
+ # SOFTWARE.
21
+
22
+ from __future__ import annotations
23
+
24
+ from typing import Final
25
+
26
+ import wom
27
+
28
+ WOM_BASE_URL: Final[str] = "https://api.wiseoldman.net/v2"
29
+ USER_AGENT_BASE: Final[str] = f"(wom.py v{wom.__version__}) -"
30
+ DEFAULT_USER_AGENT: Final[str] = f"{USER_AGENT_BASE} No contact info provided"