Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

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

Open
ioistired opened this issue Feb 3, 2021 · 3 comments
Assignees

Comments

@ioistired
Copy link
Contributor

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:

# Register the pack and getting authorizations
# - "Hey, I'm {USER} and I'd like to upload {nb_stickers} stickers"
# - "Hey, no problem, here are your credentials for uploading content"
register_req = await http.get(SERVICE_STICKER_FORM_URL.format(
nb_stickers=pack.nb_stickers_with_cover),
auth=(signal_user, signal_password),
timeout=None,
)
if register_req.status_code == 401:
raise RuntimeError("Invalid authentication")
if register_req.status_code == 413:
# Yes, it comes faster than you'll expect
raise RuntimeError(
"Service rate limit exceeded, please try again later.")
pack_attrs = register_req.json()

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
Copy link
Member

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
Copy link
Contributor Author

ioistired commented Feb 8, 2021

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
Copy link
Member

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!

@romainricard romainricard self-assigned this Feb 11, 2021
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants