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

configs on instance levels might be nicer? #43

Open
getand opened this issue Oct 29, 2020 · 1 comment
Open

configs on instance levels might be nicer? #43

getand opened this issue Oct 29, 2020 · 1 comment

Comments

@getand
Copy link
Member

getand commented Oct 29, 2020

Would it make sense to allow to inject configurations into clients as having it on the class level is not so cool for mocking since you cannot use dependency injection?

@johannesengl
Copy link

This would be possible by overriding the Client#build_request(url, **opts) method.
It would be possible to do something like this:

    def build_request(url, **opts)
      url = "#{config[:api_url]}/#{url}"
      opts = opts.deep_merge!({ "headers" => {"Authorization" => "Bearer #{config[:api_token]}"}}) # Add a header to all requests
      opts = opts.deep_merge({"params" => {"token" => config[:project_token]}}) # Add a query param to all requests

      Typhoeus::Request.new(url, **opts.symbolize_keys)
    end

What do you think?

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

No branches or pull requests

2 participants