praw-dev/praw — pull request #147 by Damgaard (2013-01-01 16:55:32+00:00)
Title: Oauth

Like I said in the reddit thread, I wanted to get in some documentation changes before the big 1.1, that is mainly what the first commit is about as well as modifying the new oauth code to match the documentation standard in the other parts of the codebase.

I refactored oauth away from objects and into an extension of Reddit. This way we don't have to pass around `requst_fn`, we avoid duplication, maintain that `objects` only contain Things, a subset of Things or stuff affecting things. It also makes Oauth implemented more like regular login. Having Oauth be a subset of Reddit rather than an independent class should not be a problem, as there won't be a need for more than 1 instance of the class.

As it is now, it's impossible to change Oauth client. So I would like to add a method `set_oauth_client` that sets `client_id`, `client_secret` and `redirect_url` much likes `login`. Another method `set_oauth_credentials` that takes an access token and/or a refresh token, which would allow for changing who you're authenticated as in programs rather than having to initialize a new Reddit instance just to log in or asking the user to re-authenticate. Then `access_token` and `refresh_token` can be removed from the Reddit initialization.

I would also like to abstract away refreshing access tokens. I think this can be done by creating a callable class, say `OAuth_access_token`, that would decorator `helpers._request`. It would be placed between `Memoize` and `Sleepafter`. It would check if the access token was still valid, and if not either refresh it or raise an `APIException`. It would work much like `Memoize`.

I also think `_handle_request` can be refactored into `helpers._request`, but it's not that important and can wait. Stuff like testing for Oauth is more importment.

Before going ahead with those changes I wanted to hear your thought on both them and these two commits. I'll try and catch you on IRC later, that might be faster.

And a happy New Year to you :)