Client
The client is the main object used to interact with the bungie api. It holds all your configuration and all relevant functions.
Client
Bases: Singleton
The singleton api client
Attributes:
| Name | Type | Description |
|---|---|---|
bungie_client_id |
str
|
The bungie.net client id |
bungie_client_secret |
str
|
The bungie.net client secret |
bungie_token |
str
|
The bungie.net token |
logger |
Logger
|
If a custom logger should be used |
language |
BungieLanguage
|
The language the manifest entries should be in |
cache |
Optional[CacheBackend]
|
If http requests should be cached. It is recommended that you make use of this to not ratelimit yourself as quickly. |
manifest_storage |
bool | AsyncEngine
|
If manifest entires should be stored, and how. Disabling this stops you from querying the manifest. |
always_return_manifest_information |
bool
|
If manifest information should always be returned on every request. Keep in mind that this will increase requests performed / storage for an increased ease of use. |
api_client_class |
Type[ApiClient]
|
Supply a custom class for |
http_client_class |
Type[HttpClient]
|
Supply a custom class for |
manifest_client_class |
Type[Manifest]
|
Supply a custom class for |
Source code in src/bungio/client.py
48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 337 | |
_invalidate_token(auth)
Invalidate a token
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
auth
|
AuthData
|
The data to invalidate |
required |
Source code in src/bungio/client.py
238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 | |
generate_auth(code)
async
Generate authentication information from a bungie code. For information on how to get that code, visit the official documentation
Staying up to date
This dispatches the Client.on_token_update() event
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
code
|
str
|
The code bungie sent |
required |
Raises:
| Type | Description |
|---|---|
InvalidAuthentication
|
If authentication is invalid |
Returns:
| Type | Description |
|---|---|
AuthData
|
The working authentication info. |
Source code in src/bungio/client.py
175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 | |
get_auth_url(state)
Generate an url which users can use to authenticate with their bungie.net account.
Requires external set up
This requires you to have set up a redirect url (and logic handling that) on bungie.net. More information can be found on the official documentation
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
state
|
str
|
An opaque value used by the client to maintain state between the request and the callback. The parameter should be used for preventing cross-site request forgery as described in section 10.12 of the OAuth 2.0 specification. |
required |
Returns:
| Type | Description |
|---|---|
str
|
The auth url |
Source code in src/bungio/client.py
158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 | |
get_working_auth(auth)
async
Check if tokens need to be refreshed and then do that. Gets called automatically when doing requests with AuthData.
Staying up to date
This dispatches the Client.on_token_update() event
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
auth
|
AuthData
|
The potentially old authentication info. |
required |
Raises:
| Type | Description |
|---|---|
InvalidAuthentication
|
If authentication is invalid |
Returns:
| Type | Description |
|---|---|
AuthData
|
The working authentication info. |
Source code in src/bungio/client.py
255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 | |
on_manifest_update()
async
Dispatched whenever the manifest receives an update by bungie. This is checked for periodically when doing manifest dependant request.
Subclassing
It is highly recommended to subclass the Client and overwrite this function to suite your own needs
Source code in src/bungio/client.py
328 329 330 331 332 333 334 335 336 337 | |
on_token_update(before, after)
async
Dispatched whenever a token is generated, updated, or invalidated.
Subclassing
It is highly recommended to subclass the Client and overwrite this function to suite your own needs
Generation
If the first token is generated, before will be None.
Invalidation
The token can be invalidated if the auth data is expired. To prevent that, make sure your tokens are updated regularly.
If the token is invalidated, after.token will be None.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
before
|
Optional[AuthData]
|
The old auth info |
required |
after
|
AuthData
|
The new auth info |
required |
Source code in src/bungio/client.py
307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 | |