Development API Reference¶
The following section outlines the API of gd.py for library developers.
Note
This section is only for gd.py developers, nothing interesting and useful for basic users here.
HTTP Requests Module¶
-
class
gd.
HTTPClient
(*, url: Union[str, yarl.URL] = 'http://www.boomlings.com/database/', use_user_agent: bool = False, forwarded_for: Optional[str] = None, proxy: Optional[str] = None, proxy_auth: Optional[aiohttp.helpers.BasicAuth] = None, timeout: Union[float, int] = 150, max_requests: int = 250, debug: bool = False, **kwargs)[source]¶ Class that handles the main part of the entire gd.py - sending HTTP requests.
-
change_url
(url: Union[str, yarl.URL]) → None[source]¶ Change base for requests. Default base is
http://www.boomlings.com/database/
, but it can be changed.- Parameters
url (
str
) – Base to change HTTPClient base to.
-
set_max_requests
(value: int = 250, *, loop: Optional[asyncio.events.AbstractEventLoop] = None) → None[source]¶ Creates an
asyncio.Semaphore
object with givenvalue
andloop
in order to limit amount of max requests at a time.- Parameters
value (
int
) – Value to set semaphore to. Default is250
.loop (
asyncio.AbstractEventLoop
) – Event loop to pass to semaphore’s constructor.
-
set_debug
(debug: bool = False) → None[source]¶ Set http client debugging.
- Parameters
debug (
bool
) – Whether to set debug on or off.
-
await
fetch
(php: str, data: Optional[Dict[str, Any]] = None, params: Optional[Dict[str, Any]] = None, get_cookies: bool = False, cookie: Optional[str] = None, custom_base: Optional[str] = None, method: Optional[str] = None) → Optional[Union[bytes, int, str]][source]¶ This function is a coroutine. Sends an HTTP Request to a Geometry Dash server and returns the response.
- Parameters
php (
str
) –The endpoint for the request URL, passed like this:
url = 'http://www.boomlings.com/database/' + php + '.php'
params (Union[
dict
,str
]) – Parameters to send with the request. Typedict
is prefered.get_cookies (
bool
) – Indicates whether to fetch a cookie. This is used in different account management actions.cookie (
str
) – Cookie, represented as string. Technically should be catched withget_cookies
set toTrue
.custom_base ([
str
,yarl.URL
]) – Custom base using different Geometry Dash IP. By defaultself.base
is used.method (
str
) – Method to use when requesting. This parameter is case insensetive. By default, ifparameters
is or empty,GET
is used, otherwisePOST
is used.
- Returns
res
with the following rules: Returns anint
, representing server error code, e.g.-1
, if server responded with error. Otherwise, returns response from a server as astr
if successfully decodes it, and on fail returnsbytes
. If a cookie is requested, returns a pair (res
,c
) where c is astr
cookie.- Return type
- Raises
HTTPError – An exception occured during handling request/response.
-
await
request
(route: str, data: Optional[Dict[str, Any]] = None, params: Optional[Dict[str, Any]] = None, custom_base: Optional[str] = None, method: Optional[str] = None, error_codes: Optional[Dict[int, Exception]] = None, exclude: Tuple[Type[BaseException]] = (), should_map: bool = False, get_cookies: bool = False, cookie: Optional[str] = None) → Optional[Union[bytes, int, str]][source]¶ This function is a coroutine. A handy shortcut for fetching response from a server and formatting it. Basically does
HTTPClient.fetch()
and operates on its result.- Parameters
error_codes (Dict[
int
,Exception
]) – A dictionary that response is checked against.Exception
can be any Exception.exclude (Tuple[Type[
BaseException
]]) – Types of errors to ignore.
- Raises
- Returns
If
error_codes
is omitted, return type is same as return ofHTTPClient.fetch()
call. If error is raised and it is inexclude
, returnsNone
.- Return type
-
await
normal_request
(url: str, data: Optional[Union[dict, str]] = None, params: Optional[Union[dict, str]] = None, method: Optional[str] = None, **kwargs) → bytes[source]¶ This function is a coroutine. Same as doing
aiohttp.ClientSession.request()
, wheremethod
is either given one or"GET"
ifdata
is None or omitted, and"POST"
otherwise.
-
-
class
gd.
Session
(**http_args)[source]¶ Implements all requests-related functionality. No docstrings here yet…
Note
See source of the session for more information.
Parameters Creating¶
-
class
gd.
Parameters
[source]¶ Class that allows step-by-step parameter creation. Used in almost all HTTP Requests.
A common usage of this class looks like that:
parameters = ( Parameters().create_new() .put_definer('song', str(...)) .finish() ) await http.request(..., parameters) ...
-
level_secret
¶ Secret used in level operations (e.g.
Level.delete()
)- Type
-
create_new
(game_version: int = 21, binary_version: int = 35, add_basic: bool = True) → gd.utils.params.Parameters[source]¶ Start forming a new dictionary.
- Parameters
type (
str
) – Type of start, use ‘web’ to start with an empty dictionary. When omitted orNone
, adds gameVersion, binaryVersion and gdw to a dict.- Returns
self
- Return type
-
finish
() → Dict[str, str][source]¶ Finishes creating parameters dictionary, and adds
secret
parameter.Puts
Parameters.secret
as secret parameter.- Returns
Fully formatted dictionary.
- Return type
-
finish_level
() → Dict[str, str][source]¶ Same as
Parameters.finish()
, but addsParameters.level_secret
instead.- Returns
Fully formatted dictionary.
- Return type
-
finish_login
() → Dict[str, str][source]¶ Same as
Parameters.finish()
, but addsParameters.login_secret
instead.- Returns
Fully formatted dictionary.
- Return type
-
finish_mod
() → Dict[str, str][source]¶ Same as
Parameters.finish()
, but addsParameters.mod_secret
instead.- Returns
Fully formatted dictionary.
- Return type
-
close
() → Dict[str, str][source]¶ Finishes creating parameters dictionary, without adding anything.
- Returns
Fully formatted parameters dictionary.
- Return type
-
put_definer
(for_what: str, item: Any) → gd.utils.params.Parameters[source]¶ Puts a definer.
- Parameters
for_what (
str
) –Type of parameter to add, represented as string.
Follows this mapping:
'song' -> 'songID' 'user' -> 'targetAccountID' 'search' -> 'str' 'gauntlet' -> 'gauntlet' 'password' -> 'password' 'levelid' -> 'levelID' 'accountid' -> 'accountID' 'itemid' -> 'itemID' 'messageid' -> 'messageID' 'commentid' -> 'commentID' 'requestid' -> 'requestID' 'userid' -> 'userID' 'reward' -> 'rewardType' 'stars' -> 'stars' 'rating' -> 'rating'
item (Any) – Parameter to put.
- Returns
self
- Return type
-
put_recipient
(account_id: int) → gd.utils.params.Parameters[source]¶ Puts recipient of a message/friend request/…
- Parameters
account_id (
int
) – An account ID of the recipient.- Returns
self
- Return type
-
put_is_sender
(t: str) → gd.utils.params.Parameters[source]¶ Puts ‘isSender’ parameter.
- Parameters
t (
str
) – Either'normal'
or'sent'
. If'sent'
, addsisSender=1
.- Returns
self
- Return type
-
put_message
(subject: str, body: str) → gd.utils.params.Parameters[source]¶ Puts message’s subject and body.
- Parameters
- Returns
self
- Return type
-
put_password
(item: str) → gd.utils.params.Parameters[source]¶ Self explanatory. Puts ‘gjp’ parameter.
- Parameters
item (
str
) – A password to put.- Returns
self
- Return type
-
put_username
(item: str) → gd.utils.params.Parameters[source]¶ Self explanatory. Puts ‘userName’ parameter.
- Parameters
item (
str
) – A username to put.- Returns
self
- Return type
-
put_fr_comment
(item: str) → gd.utils.params.Parameters[source]¶ Pretty self explanatory. Puts ‘comment’ parameter.
- Parameters
item (
str
) – A comment to put.- Returns
self
- Return type
-
put_save_data
(data_seq: Sequence[Union[bytes, str]]) → gd.utils.params.Parameters[source]¶ Self explanatory. Puts ‘saveData’ parameter.
- Parameters
- Returns
self
- Return type
-
put_type
(number: Union[int, str] = 0) → gd.utils.params.Parameters[source]¶ Sets ‘type’ parameter to a given number or string.
-
put_percent
(number: int = 0) → gd.utils.params.Parameters[source]¶ Same as
Parameters.put_type()
, but for ‘percent’.
-
put_page
(number: int = 0) → gd.utils.params.Parameters[source]¶ Same as
Parameters.put_type()
, but for ‘page’.
-
put_weekly
(number: int = 0) → gd.utils.params.Parameters[source]¶ Same as
Parameters.put_type()
, but for ‘weekly’.
-
put_total
(number: int = 0) → gd.utils.params.Parameters[source]¶ Same as
Parameters.put_type()
, but for ‘total’.
-
put_mode
(number: int = 0) → gd.utils.params.Parameters[source]¶ Same as
Parameters.put_type()
, but for ‘mode’.
-
put_like
(number: int = 0) → gd.utils.params.Parameters[source]¶ Same as
Parameters.put_type()
, but for ‘like’.
-
put_count
(number: int = 0) → gd.utils.params.Parameters[source]¶ Same as
Parameters.put_type()
, but for ‘count’.
-
put_feature
(number: int = 0) → gd.utils.params.Parameters[source]¶ Same as
Parameters.put_type()
, but for ‘feature’.
-
put_special
(number: int = 0) → gd.utils.params.Parameters[source]¶ Same as
Parameters.put_type()
, but for ‘special’.
-
put_local
(number: int = 0) → gd.utils.params.Parameters[source]¶ Same as
Parameters.put_type()
, but for ‘local’.
-
put_seed
(seed: Union[int, str], prefix: str = 'seed', suffix: str = '') → gd.utils.params.Parameters[source]¶ Puts
'{prefix}{suffix}'
parameter.- Parameters
- Returns
self
- Return type
-
put_rs
(rs: str) → gd.utils.params.Parameters[source]¶ Self explanatory. Puts
'rs'
parameter.- Parameters
rs (
str
) – Random Seed parameter, as string.- Returns
self
- Return type
-
put_chk
(chk: str) → gd.utils.params.Parameters[source]¶ Self explanatory. Puts
'chk'
parameter.- Parameters
chk (
str
) – Check parameter, as string.- Returns
self
- Return type
-
put_comment
(content: str, values: List[Any]) → gd.utils.params.Parameters[source]¶ Puts a comment.
- Parameters
- Returns
self
- Return type
-
comment_for
(type: str, number: int = 0) → gd.utils.params.Parameters[source]¶ Defines type of a comment, and puts parameters required for it.
- Parameters
- Returns
self
- Return type
-
put_login_definer
(username: str, password: str) → gd.utils.params.Parameters[source]¶ Puts parameters for a login request.
- Parameters
username (
str
) – RunsParameters.put_username()
with it.password (
str
) – Adds this as a ‘password’ parameter.
- Returns
self
- Return type
-
put_udid
(udid_string: Optional[str] = None) → gd.utils.params.Parameters[source]¶ Puts
'udid'
parameter.- Parameters
udid_string (
str
) – UDID to put.- Returns
self
- Return type
-
put_uuid
(uuid_string: Optional[str] = None) → gd.utils.params.Parameters[source]¶ Same as
Parameters.put_udid()
, but puts'uuid'
.- Parameters
uuid_string (
str
) – UUID to put.- Returns
self
- Return type
-
put_level_desc
(content: str) → gd.utils.params.Parameters[source]¶ Encodes given content and puts
'levelDesc'
.- Parameters
content (
str
) – Content of the new description, NOT encoded in Base64.- Returns
self
- Return type
-
put_profile_upd
(msg: int, friend_req: int, comments: int, youtube: str, twitter: str, twitch: str) → gd.utils.params.Parameters[source]¶ Puts all parameters required for profile update.
- Parameters
msg (
int
) – Message indicator. Mapped in as ‘mS’.friend_req (
int
) – Friend request indicator. Mapped in as ‘frS’.comments (
int
) – Comment history indicator. Mapped in as ‘cS’.youtube (
str
) – Youtube username. Mapped in as ‘yt’.twitter (
str
) – Twitter username. Mapped in as ‘twitter’.twitch (
str
) – Twitch username. Mapped in as ‘twitch’.
- Returns
self
- Return type
-
put_filters
(filters: Union[dict, gd.utils.filters.Filters]) → gd.utils.params.Parameters[source]¶ Appends level filters.
-
Ciphers and Coders¶
-
class
gd.utils.crypto.xor_cipher.
XORCipher
[source]¶
-
gd.
xor
¶ alias of
gd.utils.crypto.xor_cipher.XORCipher
-
class
gd.
Coder
[source]¶ -
classmethod
gen_rs
(length: int = 10, charset: str = 'abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789') → str[source]¶ Generates a random string of required length.
-
classmethod
encode
(type: str, string: str) → str[source]¶ Encodes a string, combining XOR and Base64 encode methods.
Used in different aspects of gd.py.
-
classmethod
decode
(type: str, string: str, use_bytes: bool = False) → str[source]¶ Decodes a XOR -> Base64 ciphered string.
Note
Due to the fact that decode and encode work almost the same, the following is true:
Coder.decode('message', Coder.encode('message', 'NeKit')) == 'NeKit' # True
-
classmethod