@@ -10,14 +10,16 @@ while also maintaining a readable codebase.
1010
1111You can install jokeapi through [ pip] ( https://pypi.org/project/pip/ ) by using ` pip install jokeapi `
1212
13- So far there are no build from source instructions.
14-
1513---
1614
1715# get_joke
1816
1917The wrapper is structured in such a way that the end-user should only ever have to
20- interact with one function. This function is ` get_joke() `
18+ interact with one function. This function is ` get_joke() ` .
19+
20+ Please note that urllib3, the core dependency of this wrapper automatically abides by
21+ ` Retry-After ` headers, which means you may have to wait a long time for a joke if you
22+ have made a lot of requests recently
2123
2224---
2325
@@ -29,7 +31,8 @@ interact with one function. This function is `get_joke()`
2931 from jokeapi import Jokes # Import the Jokes class
3032
3133 j = Jokes() # Initialise the class
32- j.get_joke() # Retrieve a random joke
34+ joke = j.get_joke(type = " single" , response_format = " txt" ) # Retrieve a random joke
35+ print (joke)
3336```
3437
3538### Parameters
@@ -129,15 +132,66 @@ If left blank it will default to `None`
129132
130133The range in which the selected joke should fall. ID's are decided by the order in which jokes are submitted.
131134The argument passes should be in form of list or tuple, and should not exceed length of 2 items. First item
132- should be minimum 0.
135+ should be minimum 0. Maximum value can be determined [ here ] ( https://sv443.net/jokeapi/v2/info )
133136
134137If left blank it will default to the maximum range.
135138
136139
137140#### Example
138141
139142``` python
140- joke = get_joke(id_range = [10 ,100 ]) # Will return a joke with the ID between 10 and 100
143+ joke = get_joke(id_range = [10 ,100 ]) # Will return a joke with the ID between 10 and 100.
144+ ```
145+
146+ ---
147+
148+ ### auth_token
149+
150+ A string token provided by the api owner. Using it will mean you are whitelisted by the api and can make
151+ more requests than normal users. Defaults to None
152+
153+
154+ #### Example
155+
156+ ``` python
157+ joke = get_joke(auth_token = " aaaaaaaaaaaaaaaaaaaaabbbbbbbbbbbbbbbbbbbbb" ) # Will send the token to the api in a header.
158+ ```
159+
160+ ---
161+
162+ ### user_agent
163+
164+ A string sent the the api that tells the api what browser you are (pretending to be). The default user agent
165+ is Mozilla Firefox from Windows 10 and should work fine, but the functionality is provided in case you wish
166+ to change it
167+
168+
169+ #### Example
170+
171+ ``` python
172+ joke = get_joke(user_agent = " Mozilla/5.0 (Windows NT 10.0; Win64; x64; rv:77.0) Gecko/20100101 Firefox/77.0" )
173+ # This is in fact the default user agent, and tells the API that we are visitng the page from a Firefox 77.0
174+ # browser using Windows 10 64bit.
175+ ```
176+
177+ ---
178+
179+ ### return_headers
180+
181+ A boolean value (True or False) that tells the wrapper if you wish to receive headers in the return from the function.
182+ Defaults to False.
183+
184+
185+ #### Example
186+
187+ ``` python
188+ response = get_joke(return_headers = True )
189+ joke = response[0 ]
190+ headers = response[1 ]
191+ # The function returns the joke and then the headers using the "return x, y" syntax, so you can index it like a list or tuple.
192+
193+ print (f " Joke: { joke} " )
194+ print (f " Headers: { headers} " )
141195```
142196
143197---
@@ -151,7 +205,7 @@ Depending on what format is chosen different things will be returned.
151205
152206A succesful API call will return:
153207
154- ``` python
208+ ``` json
155209 {
156210 "category" : " Miscellaneous" ,
157211 "type" : " twopart" ,
@@ -228,16 +282,14 @@ He keeps dropping the database.
228282
229283The wrapper can raise multiple different errors depending on what you did wrong.
230284
231- ### ValueErrors will always be raised with expected errors.
232-
233285The errors are descriptive enough that you should be able to solve them with the information provided in the error message.
234286If not, feel free to ask me through one of the channels provided below.
235287
236288---
237289
238290Developer contact:
239291
240- [ Discord] ( https://discord.gg/mB989eP )
292+ ! [ Discord] ( https://discord.com/assets/07dca80a102d4149e9736d4b162cff6f.ico ) [ ** Discord ** ] ( https://discord.gg/mB989eP )
241293
242294[ Issue Tracker] ( https://github.com/thenamesweretakenalready/Sv443s-JokeAPI-Python-Wrapper/issues )
243295
0 commit comments