Skip to content

Commit f4c8ee8

Browse files
committed
Update to Jokeapi V2.1.2
1 parent 3801d95 commit f4c8ee8

File tree

3 files changed

+23
-11
lines changed

3 files changed

+23
-11
lines changed

.circleci/.config.yml.kate-swp

-1.34 KB
Binary file not shown.

README.md

Lines changed: 15 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -80,7 +80,8 @@ The format in which the API should respond.
8080
Options are:
8181
`json`,
8282
`yaml`,
83-
`xml`
83+
`xml`,
84+
`txt`
8485

8586
If left blank it will default to `json`.
8687

@@ -173,7 +174,7 @@ A succesful API call will return:
173174

174175
A succesful API call will return:
175176

176-
```python
177+
```xml
177178
<?xml version='1.0'?>
178179
<data>
179180
<category>Dark</category>
@@ -196,7 +197,7 @@ A succesful API call will return:
196197

197198
A succesful API call will return:
198199

199-
```python
200+
```yaml
200201
category: "Programming"
201202
type: "single"
202203
joke: "Your momma is so fat, you need to switch to NTFS to store a picture of her."
@@ -210,6 +211,17 @@ id: 56
210211
error: false
211212
```
212213
214+
215+
### txt
216+
217+
A succesful API call will return:
218+
219+
```
220+
Why does no one like SQLrillex?
221+
222+
He keeps dropping the database.
223+
```
224+
213225
---
214226

215227
## Errors

jokeapi/main.py

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,7 @@ def build_request(
2222
if len(category) > 0:
2323
for c in category:
2424
if not c.lower() in ["programming", "miscellaneous", "dark"]:
25-
raise Exception(
25+
raise ValueError(
2626
'''Invalid category selected. Available categories are:
2727
"programming"
2828
"miscellaneous"
@@ -43,7 +43,7 @@ def build_request(
4343
"racist",
4444
"sexist"
4545
]:
46-
raise Exception(
46+
raise ValueError(
4747
'''\n\n
4848
You have blacklisted flags which are not available.
4949
Available flags are:
@@ -59,13 +59,13 @@ def build_request(
5959
else:
6060
blacklistFlags = None
6161

62-
if response_format not in ["json", "xml", "yaml"]:
62+
if response_format not in ["json", "xml", "yaml", "txt"]:
6363
raise Exception(
6464
"Response format must be either json, xml or yaml."
6565
)
6666
if type:
6767
if type not in ["single", "twopart"]:
68-
raise Exception(
68+
raise ValueError(
6969
'''Invalid joke type.
7070
Available options are "single" or "twopart".'''
7171
)
@@ -75,7 +75,7 @@ def build_request(
7575

7676
if search_string:
7777
if not isinstance(search_string, str):
78-
raise Exception("search_string must be a string.")
78+
raise ValueError("search_string must be a string.")
7979
return
8080
else:
8181
search_string = urllib.parse.quote(search_string)
@@ -89,13 +89,13 @@ def build_request(
8989
range_limit = dict["jokes"]["totalCount"]
9090

9191
if len(id_range) > 2:
92-
raise Exception("id_range must be no longer than 2 items.")
92+
raise ValueError("id_range must be no longer than 2 items.")
9393
elif id_range[0] < 0:
94-
raise Exception(
94+
raise ValueError(
9595
"id_range[0] must be greater than or equal to 0."
9696
)
9797
elif id_range[1] > range_limit:
98-
raise Exception(
98+
raise ValueError(
9999
f"id_range[1] must be less than or equal to {range_limit-1}."
100100
)
101101

0 commit comments

Comments
 (0)