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 signal functionality to manage events (after_token_refresh) #52

Closed
wants to merge 5 commits into from

Conversation

Kyria
Copy link
Contributor

@Kyria Kyria commented Nov 30, 2016

Related to #46 (and may fix it)

This adds a base functionality to trigger alarms/signals (or whatever the name you give them) in pycrest.
Basically, you have instances of Signal, each one represents a specific event. These signals, when triggered (using Signal.send(**kwargs) or Signal.send_robust(**kwargs) if you want to silence exception (still logged using logger)), will call all receivers they registered and give them the same arguments.

A receiver is just any callable object you my have (function, class methods, class with __call__()).

The doc has also been updated to show how to use signals in the code (import signal, add/remove receivers)

Currently the only event added is the after_token_refresh signal, fired each time AuthedConnection.refresh() is called with these arguments :

Arguments Type Description
access_token String The new access token used to log in
refresh_token String The refresh token used to refresh
expires_in int The token validity time in seconds

This a really lightweight inspiration from the django's signal that gives the advantage the "core code" only need to know which events he wants to fire, without dealing with list of receivers, etc.

On a side note, and not directly related to this PR main subject, I splitted the tests, moving cache tests and event tests in their own files (and fixing a few pep issues at the same time)

@coveralls
Copy link

coveralls commented Nov 30, 2016

Coverage Status

Coverage decreased (-0.3%) to 99.704% when pulling 30f69ee on Kyria:events into 26d72a4 on pycrest:master.

@coveralls
Copy link

coveralls commented Nov 30, 2016

Coverage Status

Coverage remained the same at 100.0% when pulling 1cbd236 on Kyria:events into 26d72a4 on pycrest:master.

@Kyria Kyria closed this Jun 24, 2017
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

Successfully merging this pull request may close these issues.

None yet

2 participants