signalstickers / signalstickers-client

⚙️🐍 A Python client for the Signal stickers API
https://pypi.org/project/signalstickers-client/
GNU Lesser General Public License v3.0
54 stars 9 forks source link

Add a public way to register a pack upload separately from uploading a pack #10

Open ioistired opened 3 years ago

ioistired commented 3 years ago

In Adhesive, I'd like to check if I've been rate limited before proceeding with the conversion process. I propose to separate the pack registration code:

https://github.com/signalstickers/signalstickers-client/blob/2d74c4558ca0b91d7b25e2c5fb05288928c197fb/signalstickers_client/classes/uploader.py#L24-L39

Into a separate public function that returns pack_attrs and pack_key. The caller doesn't care about this data, and treats it as an opaque "token" object to be passed back to the upload code. For backwards compatibility and to maintain a simple API, upload_pack should remain as is with the same interface, wrapping the new function.

romainricard commented 3 years ago

So if I understand correctly, this is the kind of API you'd like?

pack = Pack()
client = StickersClient("foo", "bar")

# So instead of 
client.upload_pack(pack)

# You would do something like
try:
    registration = client.register(pack)
    client.upload_pack_from_registration(pack, registration)
except RateLimitException:
    ...
ioistired commented 3 years ago

In addition to, yea. client.upload_pack(pack) would be equivalent to client.upload_pack_from_registration(pack, client.register(pack)). What do you think?

romainricard commented 3 years ago

Yeah I meant in addition, sorry! I've looked into Signal server code, and it does not seems that a method to get the rate limit status is available.

I can see the point of this use-case, so I'll try to do in the next days!