podio / podio-rb

The official Ruby wrapper for the Podio API used and maintained by the Podio team
https://podio.com
MIT License
66 stars 53 forks source link

Support for hooks which are executed before each request #2

Closed saulius closed 13 years ago

saulius commented 13 years ago

Hi there,

since podio-rb keeps its singleton instance in the thread context for convenience reasons it becomes a bit hard to support multiple users which have different oAuth access tokens assigned for them. In current implementation, reassigning the token on each user's call would mean that Faraday will be reinitialized each time which is a not good thing if you want to support a lot of users. I propose a solution based on hooks which expose the request environment and so therefore one can add any request headers he wants, including modifying the oAuth one. Similarly to way it is implemented in the rest-client https://github.com/archiloque/rest-client. Due to request hook position in the middleware stack, If added token turns to be expired, Faraday will execute oAuth middleware and refresh it, as usually.

Any thought on this? It would be nice to see this merged upstream. Thanks

theflow commented 13 years ago

Hi Saulius,

thanks a lot for the contribution! Can you explain a little bit why instantiating is too heavy to do each time in your use case?

Florian

saulius commented 13 years ago

Hey there,

Well I don't really know whether my implementation is a better alternative in this case, but I just thought that current mechanism of setting the token is a bit too heavy since, correct me if I'm wrong, it's just a matter of setting different http header with appropriate token. When multiple users access the application the token gets reset on each of their requests to Podio.

If you think it's ok as it as, please close this issue. I believe I'll still bug you in the future with the SSL patch which accidentally got in to this pull request :)