Leonidas-from-XIV / slacko

A neat interface for Slack
https://leonidas-from-xiv.github.io/slacko
Other
81 stars 11 forks source link

Session-based API #15

Closed jerith closed 7 years ago

jerith commented 7 years ago

This changes the signature of all functions that take a token and has them take a session instead. Like token, session is an abstract type.

For backwards compatibility, token_of_string now returns a session instead. In order to (optionally) provide a different base_url, you need to use the new make_session function instead.

The two API functions that didn't take a token (api_test and oauth_access) now accept an optional ?base_url parameter and are otherwise unchanged.

The slack_notify command line tool now accepts a --base-url option (which does the obvious thing), mostly to demonstrate usage.

jerith commented 7 years ago

I've added basic support for caching identifiers (channel, user, group) in the session, but I didn't want to make this branch bigger (and harder to review) than it already is, so I put that in its own branch: https://github.com/jerith/slacko/tree/session-cache Comparison with this branch: https://github.com/jerith/slacko/compare/session-based...jerith:session-cache

The only change to the public API is the new flush_session_caches function, but all identifier lookups now cache the complete mapping for that identifier type for one minute. It would be useful to update the cache automatically whenever channels_list etc. is called (and update or invalidate it in channels_rename etc.), but I haven't done that yet.

I'd prefer to keep the caching stuff out of this PR in the interests of breaking the work into more manageable chunks, but I'll continue working on it in parallel and rebasing as this PR changes.