Skip to content

Commit 8be70b8

Browse files
authored
Support for /canvas (#27)
* Rename files with _ in their name to - * Enable color theme switching * Fixed typo RSA API is wrong since the A in RSA stands of "API" so I changed it to Random Stuff API * Change latest version to 5 * Remove `self` from example self was not needed and would raise error when trying to run it * Fix typo * Code formatting | Removed unnecessary code * Format file * Add image method constants * Remove kiss from ONE_IMAGE_METHODS * add ALL_METHODS constant * Format file * Rename FOUR_IMAGE_METHODS to TEXT_METHODS * Helper functions to validate required image/text * Update gitignore * Support for /canvas endpoint * Split stuff into functions * Code formatting * Async support for /canvas endpoint * Format code with black
1 parent 9a6a844 commit 8be70b8

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

42 files changed

+851
-510
lines changed

.gitignore

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -137,4 +137,5 @@ tests
137137
test.bat
138138

139139
# useless files
140-
delete.md
140+
delete.*
141+
test.*

docs/docs/getting_started.md renamed to docs/docs/getting-started.md

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -37,12 +37,12 @@ Some other methods are:
3737
## Async usage
3838
This library also supports async usage to use in asynchrounous enivornments.
3939

40-
For async usage, We use [`AsyncClient`](sections/clients/async_client.md) class which is an async version of `Client` class.
40+
For async usage, We use [`AsyncClient`](sections/clients/async-client.md) class which is an async version of `Client` class.
4141
```py
4242
import randomstuff
4343
import asyncio
4444

45-
async def coro(self):
45+
async def coro():
4646
async with randomstuff.AsyncClient(api_key="api-key") as client:
4747
response = await client.get_ai_response('Hi there.')
4848
print(response.message)
@@ -52,4 +52,4 @@ loop.run_until_complete(coro())
5252
```
5353

5454
!!! info "Information"
55-
This class is exactly same as Client class except all methods are coroutine and asynchrounous. By similar, We mean that all methods have the same name.
55+
This class is exactly same as Client class except all methods are coroutine and asynchrounous. By similar, We mean that all methods have the same name.

docs/docs/index.md

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,13 @@
11
# Welcome to randomstuff.py
22

3-
An easy to use and pythonic API wrapper around Random Stuff API.
3+
An easy to use and pythonic API wrapper around Random Stuff API.
44

55
## Features
66

77
* Easy to use, Organized & Object oriented design
88
* Wraps entire API including version 3 and 4
99
* Feature rich, Decent errors handling
10-
* Up-to-date — Always kept up-to-date with latest updates
10+
* Up-to-date — Always kept up-to-date with latest updates
1111

1212
!!! info "Get Started"
13-
Please see the [Get Started](getting_started.md) page to see examples to quickly get started.
13+
Please see the [Get Started](getting-started.md) page to see examples to quickly get started.

docs/docs/sections/clients/client.md

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@
33
The main client class to make API calls.
44

55
!!! warning "Non-async class"
6-
All functions in this class are blocking meaning they are not suitable for async programs like Discord bots etc. Please have a look at [`AsyncClient`](async_client.md)
6+
All functions in this class are blocking meaning they are not suitable for async programs like Discord bots etc. Please have a look at [`AsyncClient`](async-client.md)
77

88
=== "Parameters/Attributes"
99

@@ -43,7 +43,7 @@ The main client class to make API calls.
4343
| `server` | The [AI server](../topics/lists.md#ai-servers) to use. Default is `primary`. | Optional[`str`] |
4444
| `master` | The bot's master AKA creator, This is used in responses. | Optional[`str`] |
4545
| `bot` | The bot's name, This is used in responses. | Optional[`str`] |
46-
| `uid` | The [Unique ID](../topics/unique_id.md) to use. | Optional[`str`] |
46+
| `uid` | The [Unique ID](../topics/unique-id.md) to use. | Optional[`str`] |
4747

4848

4949
=== "Parameters (Version 3)"
@@ -55,10 +55,10 @@ The main client class to make API calls.
5555
| `type` | The type of AI response. Either `stable` or `unstable` | Optional[`str`] |
5656
| `dev_name` | The bot's dev AKA creator, This is used in responses. | Optional[`str`] |
5757
| `bot_name` | The bot's name, This is used in responses. | Optional[`str`] |
58-
| `unqiue_id` | The [Unique ID](../topics/unique_id.md) to use. | Optional[`str`] |
58+
| `unqiue_id` | The [Unique ID](../topics/unique-id.md) to use. | Optional[`str`] |
5959

6060
=== "Returns"
61-
- [`AIResponse`](../data_classes/ai_response.md) : The obtained response.
61+
- [`AIResponse`](../data-classes/ai-response.md) : The obtained response.
6262

6363
* ### **`get_image(type: str = 'any')`**
6464

@@ -140,4 +140,4 @@ The main client class to make API calls.
140140
with Client(...) as client:
141141
# do things here
142142
```
143-
as soon as with block ends, The session is closed.
143+
as soon as with block ends, The session is closed.

docs/docs/sections/data_classes/ai_response.md renamed to docs/docs/sections/data-classes/ai-response.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,4 +14,4 @@ Represents the response returned in `Client.get_ai_response()` method.
1414
| `server` | The [AI server](../topics/lists.md#ai-servers) to use. Default is `primary`. | Optional[`str`] |
1515
| `master` | The bot's master AKA creator, This is used in responses. | Optional[`str`] |
1616
| `bot` | The bot's name, This is used in responses. | Optional[`str`] |
17-
| `uid` | The [Unique ID](../topics/unique_id.md) to use. | Optional[`str`] |
17+
| `uid` | The [Unique ID](../topics/unique-id.md) to use. | Optional[`str`] |
Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,2 +1,2 @@
11
# `Forbidden`
2-
Represents 403 & 401 responses returned by RSA API, Usually raised upon forbidden plans or missing API keys.
2+
Represents 403 & 401 responses returned by Random Stuff API, Usually raised upon forbidden plans or missing API keys.

docs/docs/sections/topics/faq.md

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@ These are some questions that you might have, If your question is not here, Join
55
[https://api-info.pgamerx.com/register](https://api-info.pgamerx.com/register) | Steps are pretty straight forward.
66

77
### What version of API should I be using?
8-
The latest version is always the best. Currently latest version is version 4. To use the latest version, Simply remove `version` kwarg from your Client instance.
8+
The latest version is always the best. Currently latest version is version 5. To use the latest version, Simply remove `version` kwarg from your Client instance.
99

1010
### Why do I get `PlanNotAllowed` error on `get_joke()`, `get_image()` etc. method when I have a plan?
1111
Plans are only supported in following methods:
@@ -19,4 +19,4 @@ To use the other methods, You will have to use normal API key (API key with no p
1919
All objects are frozen dataclasses meaning their attributes cannot be changed.
2020

2121
### What is unique ID?
22-
Please see the [Unique ID](unique_id.md) page.
22+
Please see the [Unique ID](unique-id.md) page.
File renamed without changes.

docs/mkdocs.yml

Lines changed: 20 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@ site_name: randomstuff.py
22
theme:
33
name: material
44
palette:
5-
- accent: green
5+
# - accent: green # setting this disables color theme switching for some reason
66
- scheme: default
77
toggle:
88
icon: material/lightbulb
@@ -31,32 +31,32 @@ theme:
3131
nav:
3232
- Home:
3333
- Introduction: index.md
34-
- Getting Started: getting_started.md
34+
- Getting Started: getting-started.md
3535

3636
- Clients:
3737
- Client: sections/clients/client.md
38-
- AsyncClient: sections/clients/async_client.md
38+
- AsyncClient: sections/clients/async-client.md
3939

4040
- Data Classes:
41-
- Home: sections/data_classes/index.md
42-
- AIResponse: sections/data_classes/ai_response.md
43-
- Joke: sections/data_classes/joke.md
44-
- JokeFlags: sections/data_classes/joke_flags.md
45-
- Waifu: sections/data_classes/waifu.md
46-
- Weather: sections/data_classes/weather.md
47-
- WeatherLocation: sections/data_classes/weather_location.md
48-
- WeatherForecast: sections/data_classes/weather_forecast.md
49-
- CurrentWeather: sections/data_classes/current_weather.md
41+
- Home: sections/data-classes/index.md
42+
- AIResponse: sections/data-classes/ai-response.md
43+
- Joke: sections/data-classes/joke.md
44+
- JokeFlags: sections/data-classes/joke-flags.md
45+
- Waifu: sections/data-classes/waifu.md
46+
- Weather: sections/data-classes/weather.md
47+
- WeatherLocation: sections/data-classes/weather-location.md
48+
- WeatherForecast: sections/data-classes/weather-forecast.md
49+
- CurrentWeather: sections/data-classes/current-weather.md
5050

5151
- Errors:
5252
- Home: sections/errors/index.md
5353
- Forbidden: sections/errors/forbidden.md
54-
- BadAPIKey: sections/errors/bad_api_key.md
55-
- PlanNotAllowed: sections/errors/plan_not_allowed.md
56-
- ArgumentError: sections/errors/argument_error.md
57-
- UnknownArgument: sections/errors/unknown_argument.md
58-
- BadArgument: sections/errors/bad_argument.md
59-
- HTTPError: sections/errors/http_error.md
54+
- BadAPIKey: sections/errors/bad-api-key.md
55+
- PlanNotAllowed: sections/errors/plan-not-allowed.md
56+
- ArgumentError: sections/errors/argument-error.md
57+
- UnknownArgument: sections/errors/unknown-argument.md
58+
- BadArgument: sections/errors/bad-argument.md
59+
- HTTPError: sections/errors/http-error.md
6060

6161
- Submodules:
6262
- utils: sections/submodules/utils.md
@@ -65,10 +65,10 @@ nav:
6565
- FAQ: sections/topics/faq.md
6666
- Warnings: sections/topics/warnings.md
6767
- Lists: sections/topics/lists.md
68-
- Unique ID: sections/topics/unique_id.md
68+
- Unique ID: sections/topics/unique-id.md
6969

7070
- What's new?:
71-
- What's new: sections/whats_new.md
71+
- What's new: sections/whats-new.md
7272

7373
extra:
7474
homepage: https://github.com/nerdguyahmad/randomstuff.py

examples/ai_plans.py

Lines changed: 24 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -5,19 +5,31 @@
55
"""
66
import randomstuff
77

8-
with randomstuff.Client(key="api-key-here") as client: # Input the API key that has the paid plan. Please note that you cannot use plans with version 2 of API!
9-
"""Below are examples for all the plans choose the one for the plan you have"""
10-
response = client.get_ai_response(message="The message", plan='') # No plan (Normal aka Free)
11-
print(response.message)
8+
with randomstuff.Client(
9+
key="api-key-here"
10+
) as client: # Input the API key that has the paid plan. Please note that you cannot use plans with version 2 of API!
11+
"""Below are examples for all the plans choose the one for the plan you have"""
12+
response = client.get_ai_response(
13+
message="The message", plan=""
14+
) # No plan (Normal aka Free)
15+
print(response.message)
1216

13-
response = client.get_ai_response(message="The message", plan="pro") # Pro plan
14-
print(response.message)
17+
response = client.get_ai_response(
18+
message="The message", plan="pro"
19+
) # Pro plan
20+
print(response.message)
1521

16-
response = client.get_ai_response(message="The message", plan="ultra") # Ultra plan
17-
print(response.message)
22+
response = client.get_ai_response(
23+
message="The message", plan="ultra"
24+
) # Ultra plan
25+
print(response.message)
1826

19-
response = client.get_ai_response(message="The message", plan="biz") # Biz plan
20-
print(response.message)
27+
response = client.get_ai_response(
28+
message="The message", plan="biz"
29+
) # Biz plan
30+
print(response.message)
2131

22-
response = client.get_ai_response(message="The message", plan="mega") # Mega plan
23-
print(response.message)
32+
response = client.get_ai_response(
33+
message="The message", plan="mega"
34+
) # Mega plan
35+
print(response.message)

examples/async_usage.py

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,12 @@
11
import randomstuff
22
import asyncio
33

4+
45
async def coro():
5-
async with randomstuff.AsyncClient(api_key="key") as client:
6-
response = await client.get_ai_response("Hello world")
7-
print(response.message)
6+
async with randomstuff.AsyncClient(api_key="key") as client:
7+
response = await client.get_ai_response("Hello world")
8+
print(response.message)
9+
810

911
loop = asyncio.get_event_loop()
1012
loop.run_until_complete(coro())

examples/different_ai_servers.py

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,4 +6,6 @@
66
import randomstuff
77

88
with randomstuff.Client(key="api-key-here") as client:
9-
client.get_ai_response(message="Hi", server="primary") # Pass in type in server argument. Choose from `primary`, `backup` and `unstable`.
9+
client.get_ai_response(
10+
message="Hi", server="primary"
11+
) # Pass in type in server argument. Choose from `primary`, `backup` and `unstable`.

examples/different_api_versions.py

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,9 @@
88
"""
99
import randomstuff
1010

11-
with randomstuff.Client(key="api-key-here", version="4") as client: # Pass in API version in version argument. Choose one from 2 or 3 or 4 (v4 is beta).
11+
with randomstuff.Client(
12+
key="api-key-here", version="4"
13+
) as client: # Pass in API version in version argument. Choose one from 2 or 3 or 4 (v4 is beta).
1214

13-
"""Put your rest of code here. You have to change nothing when changing API versions. Wrapper deals with that itself."""
14-
...
15+
"""Put your rest of code here. You have to change nothing when changing API versions. Wrapper deals with that itself."""
16+
...

examples/jokes.py

Lines changed: 34 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -2,19 +2,39 @@
22

33
with randomstuff.Client(key="api-key") as client:
44

5-
joke = client.get_joke(type="any") # Available joke types: ('pun', 'spooky', 'dev', 'any')
5+
joke = client.get_joke(
6+
type="any"
7+
) # Available joke types: ('pun', 'spooky', 'dev', 'any')
68

7-
print("Category: ", joke.category) # The category of the joke.
8-
print("Joke Type: ", joke.type) # The type of joke, Can either be `single` or `twopart`.
9-
print("Joke: ", joke.joke) # Actual joke. , if the joke type is single, This is a string otherwise it is a dictionary with two keys "setup" and "delivery".
10-
print("ID: ", joke.id) # The joke's ID. Every joke has a unique ID.
11-
print("Safe: ", joke.safe) # Determines if the joke is safe or not. If this is `True`, the joke is safe.
12-
print("Language: ", joke.lang) # The language of joke.
9+
print("Category: ", joke.category) # The category of the joke.
10+
print(
11+
"Joke Type: ", joke.type
12+
) # The type of joke, Can either be `single` or `twopart`.
13+
print(
14+
"Joke: ", joke.joke
15+
) # Actual joke. , if the joke type is single, This is a string otherwise it is a dictionary with two keys "setup" and "delivery".
16+
print("ID: ", joke.id) # The joke's ID. Every joke has a unique ID.
17+
print(
18+
"Safe: ", joke.safe
19+
) # Determines if the joke is safe or not. If this is `True`, the joke is safe.
20+
print("Language: ", joke.lang) # The language of joke.
1321

14-
print("\n=== Flags ===\n")
15-
print("NSFW: ", joke.flags.nsfw) # Determines if the joke is NSFW or not. If this is `True`, The joke is NSFW.
16-
print("Religious: ", joke.flags.religious) # Determines if the joke is religious or not. If this is `True`, The joke is religious.
17-
print("Political: ", joke.flags.political) # Determines if the joke is political or not. If this is `True`, The joke is political.
18-
print("Racist: ", joke.flags.racist) # Determines if the joke is racist or not. If this is `True`, The joke is racist.
19-
print("Sexist: ", joke.flags.sexist) # Determines if the joke is sexist or not. If this is `True`, The joke is sexist.
20-
print("Explicit: ", joke.flags.explicit) # Determines if the joke is explicit or not. If this is `True`, The joke is explicit.
22+
print("\n=== Flags ===\n")
23+
print(
24+
"NSFW: ", joke.flags.nsfw
25+
) # Determines if the joke is NSFW or not. If this is `True`, The joke is NSFW.
26+
print(
27+
"Religious: ", joke.flags.religious
28+
) # Determines if the joke is religious or not. If this is `True`, The joke is religious.
29+
print(
30+
"Political: ", joke.flags.political
31+
) # Determines if the joke is political or not. If this is `True`, The joke is political.
32+
print(
33+
"Racist: ", joke.flags.racist
34+
) # Determines if the joke is racist or not. If this is `True`, The joke is racist.
35+
print(
36+
"Sexist: ", joke.flags.sexist
37+
) # Determines if the joke is sexist or not. If this is `True`, The joke is sexist.
38+
print(
39+
"Explicit: ", joke.flags.explicit
40+
) # Determines if the joke is explicit or not. If this is `True`, The joke is explicit.

randomstuff/__init__.py

Lines changed: 11 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -14,16 +14,18 @@
1414
from .errors import *
1515
from .joke import *
1616
from .waifu import *
17+
1718
# To use randomstuff.utils module import it manually.
1819

19-
__title__ = 'randomstuff.py'
20-
__summary__ = 'An easy to use and feature rich wrapper for Random Stuff API'
21-
__uri__ = 'https://github.com/nerdguyahmad/randomstuff.py'
22-
__email__ = '[email protected]'
23-
__author__ = 'nerdguyahmad'
24-
__version__ = '2.0.0a'
25-
__license__ = 'MIT'
26-
__copyright__ = '2021-present nerdguyahmad.'
20+
__title__ = "randomstuff.py"
21+
__summary__ = "An easy to use and feature rich wrapper for Random Stuff API"
22+
__uri__ = "https://github.com/nerdguyahmad/randomstuff.py"
23+
__email__ = "[email protected]"
24+
__author__ = "nerdguyahmad"
25+
__version__ = "2.0.0a"
26+
__license__ = "MIT"
27+
__copyright__ = "2021-present nerdguyahmad."
28+
2729

2830
def get_version():
29-
return __version__
31+
return __version__

0 commit comments

Comments
 (0)