Campfire API basic functions
Project description
This module includes several basic functions for asynchronously communicating with Campfire server. It can also receive push notifications. To learn what requests you can send, visit https://github.com/ZeonXX/CampfireApi/tree/master/src/main/java/com/dzen/campfire/api/requests
Installation
Using pip
command:
pip install campfire-basic
Or, clone this repository using git
command:
git clone https://github.com/Camper-CoolDie/campfire-basic
Examples
Requesting
import campfire
import asyncio
async def main():
print(await campfire.send("RProjectVersionGet"))
# {'ABParams': {}, 'version': '1.290'}
asyncio.run(main())
The code above gets the current version of Campfire server and shows it.
Log in
Certain types of requests will raise an exception if you're not
logged in. To proceed with those requests, you need to authorize first.
In this module, this can be done via calling the login()
function,
and to send the request as an authorized user, call the send()
method of
a returned object.
import campfire
import asyncio
req = {
"fandomId": 10,
"languageId": 1
}
async def main():
print(await campfire.send("RFandomsGet", req))
# ApiRequestException: Error occurred while processing request ("ERROR_UNAUTHORIZED")
log = campfire.login("email", "password")
print(await log.send("RFandomsGet", req))
# {'fandom': {'subscribesCount': 1105, 'imageId'...
asyncio.run(main())
Receiving notifications
You can receive every notification Campfire server sends to you, or only a certain type.
import campfire
import asyncio
log = campfire.login("email", "password")
# Generate GCM token, which contains a FCM token we need
token = campfire.token()
async def main():
# Send the token to Campfire server
await log.send("RAccountsAddNotificationsToken", {"token": token.fcm})
# Listen to notifications
def notifi(n):
print(notifi)
# The "final point" where our program will continue listening to notifications
# until we press Ctrl + C or some unexpected exception happens;
# if you want to wait for a single notification, see the next example
await campfire.listen(token, notifi)
asyncio.run(main())
Or, wait for a notification:
import campfire
import asyncio
log = campfire.login("email", "password")
token = campfire.token()
async def main():
await log.send("RAccountsAddNotificationsToken", {"token": token.fcm})
# Wait for a notification
async with campfire.wait(token) as n:
print(n)
# With filter (wait for a subscriber)
async with campfire.wait(token, {"J_N_TYPE": 4}) as n:
print(n["account"]["J_NAME"])
# Timeout!
try:
async with campfire.wait(token, {}, 15.0) as n:
print(n)
except asyncio.TimeoutError:
print("Time is out")
asyncio.run(main())
Getting a resource
You can also request Campfire to get a picture or another sort of a
resource. This can be done almost the same way we request the main
server. To request Media server, if you prefer requesting using
Request class, just replace it with "RequestMedia". Or add a "server = 1"
argument to the send()
function. Returning value will be of type bytes
if RResourcesGet
request sent.
import campfire
import asyncio
async def main():
res = await campfire.send("RResourceGet", {"resourceId": 1}, server = 1)
print(len(res))
# The length of res will be printed
asyncio.run(main())
Project details
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
Built Distribution
File details
Details for the file campfire-basic-1.1.2.tar.gz
.
File metadata
- Download URL: campfire-basic-1.1.2.tar.gz
- Upload date:
- Size: 31.3 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/4.0.2 CPython/3.10.8
File hashes
Algorithm | Hash digest | |
---|---|---|
SHA256 | 997599b41c514440aeccb6a99d3354cc1bd18e5f91b4afef1b5e24bc001562b8 |
|
MD5 | 7d18dfa8d807023289a7e0694753ce83 |
|
BLAKE2b-256 | 208134d18ef9fae2c6e91a270f01485a62b056938286d75284b9c91e3100f0b9 |
File details
Details for the file campfire_basic-1.1.2-py3-none-any.whl
.
File metadata
- Download URL: campfire_basic-1.1.2-py3-none-any.whl
- Upload date:
- Size: 34.3 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/4.0.2 CPython/3.10.8
File hashes
Algorithm | Hash digest | |
---|---|---|
SHA256 | b14b73413d4a1b0b17ca197bd00cfe0f0a96d32e6686975c269003913a8fdef5 |
|
MD5 | 3dd02f369269ad57e79668cdb456a2ed |
|
BLAKE2b-256 | f8d3bb1f14a3c75a379b4ac604ac6b051d7f4d66d926b43c88304781366bda05 |