Option to store scopes from response header on client#382
Option to store scopes from response header on client#382jmanian wants to merge 4 commits intoslack-ruby:masterfrom
Conversation
|
I intentionally did not add the option as a request-level parameter, because it would only work on the first request made by each client instance, given that |
Generated by 🚫 Danger |
| include Api::Endpoints | ||
|
|
||
| attr_accessor(*Config::ATTRIBUTES) | ||
| attr_accessor(*Config::ATTRIBUTES, :oauth_scopes) |
There was a problem hiding this comment.
I thought about making this attr_reader :oauth_scopes so that it wouldn't appear that you can set the scopes here. But then it would need to use instance_variable_set from the middleware to set them. Not sure which is better.
| # Configuration parameters: IgnoredMethods. | ||
| Metrics/CyclomaticComplexity: | ||
| Max: 9 | ||
| Max: 10 |
There was a problem hiding this comment.
This rule and PerceivedComplexity were failing on connection with the newly added middleware.
There was a problem hiding this comment.
Generally I just run rubocop -a ; rubocop --auto-gen-config.
|
This is good, but I think we can do better. What do you think of being able to write this: config.connection do |connection, options|
connection.use ::Slack::Web::Faraday::Response::StoreScopes, options
endThis way clients can install any middleware. Another option could be adding config.middleware << ::Slack::Web::Faraday::Response::StoreScopesNot sure which one I prefer, would take either. |
|
@dblock How would your first option work exactly? Would the block be stored in the config as a proc, and then called with the connection instance during the In both cases how would it handle the fact that I'm passing the instance of the client to Also with these options would the user be able to set this at the client instance level, or only at the config level? In my case, since I only need to use this in a specific place with Slack::Web::Client.new(token: token, store_scopes: true).auth_test |
Right, you would
I think you could hide this away. I didn't write the code but I would want the supporting config code to always pass in
It should work in both. If you are having trouble implementing this LMK and I could give it a shot. I don't know whether it's possible - I am only thinking about what the user would want to write, and leaving the implementation to the professionals ;) |
1963b52 to
097b3ca
Compare
Resolves #378
This adds an optional response middleware to the Web client. When used the middleware pulls the OAuth scopes from the response header
x-oauth-scopesand puts them on the instance of the client atclient.oauth_scopes.I wasn't sure the best way to gain access to the client itself from the middleware, so I followed the pattern used by the
Mashifymiddleware to pass in an option. Maybe there's a better way?I'm also not sure about the naming of the middleware class (
StoreScopes) or the config option (store_scopes).No tests or documentation yet.