Skip to content

Commit

Permalink
Enum's explanation
Browse files Browse the repository at this point in the history
  • Loading branch information
somespecialone committed Oct 1, 2024
1 parent 0a2443b commit 4a785b3
Show file tree
Hide file tree
Showing 4 changed files with 68 additions and 5 deletions.
1 change: 1 addition & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -166,5 +166,6 @@ I will be very grateful for helping me get the things right.
- [Steam Market id's storage repo](https://github.com/somespecialone/steam-item-name-ids)
- [steamapi.xpaw.me](https://steamapi.xpaw.me/)
- [Steam Exchange Rate Tracker](https://github.com/somespecialone/sert)
- [ethanfurman/aenum](https://github.com/ethanfurman/aenum)

<!--footer-end-->
20 changes: 15 additions & 5 deletions docs/design.md
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ Designed to be flexible with modest complexity, while being typed and developer
As you can read in [previous](./get_started.md#first-words) chapter, there is two **clients**: public and non-public.
Both represents interaction layer with `SteamCommunity`.
Each **client** instance has separate `session`, therefore as **cookies**, and other properties
(country, currency, ...).
(country, currency, ...).

!!! tip
Think of them as a private-mode window of a web browser. Each **client** instance is a new private mode window,
Expand Down Expand Up @@ -46,20 +46,30 @@ This classes inherit all corresponding mixins. [Inheritance](./client.md#inherit
There is two general types of exceptions: `python` (builtin exceptions, related to invalid arguments values,
broken connection, so on) and `steam`, that raised when code faced error while trying to interact with `Steam`,
as follows: `Steam` cannot return market listings, items not in inventory, malformed response, `Steam`
return error result (`EResult`) deliberately for some reason (lol) or even give your **client** (mainly, by ip) a
rate limit restriction ([more information](./scraping.md)).
return error result (`EResult`) deliberately for some reason (😂) or even give your **client** (mainly, by ip) a
[rate limit restriction](./scraping.md).

### Modules & entrypoints

`Aiosteampy` contains `utils` and `helpers` moduls, each contain useful utilities to make work with **client** easier.
[There is](./utils_helpers.md)
[Is there](./utils_helpers.md)

Alongside with mentioned moduls project have a few `extensions`:

- [user agents](./ext/user_agents.md) - service, which main aim is to help get random user agent for your **client/s**
- [currency converter](./ext/converter.md) - service, aims to help you convert `Steam` currencies

### Enums

At last, within the project exists two special enums `App` and `AppContext` with unusual behaviour (for `python`).
In short, _they extend itself when member is missing_, previous means that hardcoded members are just _predefined_.

!!! warning ""
Generally, `aiosteampy` support all apps and contexts!

More on [dedicated page](./enums.md), worth reading.

## Epilogue

_That's it_. Further information introduce short overview of methods, how things work more detailed and even
hard to say some patterns. Good luck 👋!
hard to say some patterns. Good luck 👋
51 changes: 51 additions & 0 deletions docs/enums.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,51 @@
Let's talk about `App` and `AppContext` enum's a little.

Thankfully to an [aenum](https://github.com/ethanfurman/aenum) package, these enum's extending selves when member is
missing. Therefore, as mentioned before, hardcoded members are just _predefined_.

!!! note ""
You can create `App` and `AppContext` for non-predefined app+context

As instance:

```python
from aiosteampy import App, AppContext

BANANA_APP = App(2923300)
BANANA = AppContext((BANANA_APP, 2)) # with context 2
```

And then use it within your app. Moreover, from now `AppContext` and `App` enums have a new member.

### Caveat

If you print/log `BANANA_APP` you receive something like

```sh
<AppContext.AppContext_2923300_2: (<App.App_2923300: 2923300>, 2)>
```

Not so beautiful, yes. Name is auto-generated, due to inability to know name of the app, if we, for example,
get a `trade offer` with non-predefined app items.

!!! warning "Next version"
Solution comes in next minor version (0.6.4)

As a workaround you can extend enum manually:

```python
from aenum import extend_enum
from aiosteampy import App, AppContext

BANANA_APP = extend_enum(App, "BANANA", 2923300)
BANANA_DEFAULT_CONTEXT = extend_enum(
AppContext,
"BANANA_DEFAULT_CONTEXT",
(BANANA_APP, 2),
) # with context 2
```

Then `repr` of a `AppContext` new member will be:
```sh
<AppContext.BANANA_DEFAULT_CONTEXT: (<App.BANANA: 2923300>, 2)>
```
1 change: 1 addition & 0 deletions mkdocs.yml
Original file line number Diff line number Diff line change
Expand Up @@ -80,6 +80,7 @@ nav:
- "Proxies 🌐": proxies.md
- Session: session.md
- "Scraping 🕷️": scraping.md
- Enums: enums.md
- Client: client.md
- "Market 💹": market.md
- Trade: trade.md
Expand Down

0 comments on commit 4a785b3

Please sign in to comment.