Add configuration overrides to Mirren::Client#6
Conversation
Add mirren/errors.rb and mirren/result_ext.rb.
Modify Auth to take :api_key and :api_secret as initialization values. Modify Auth#call to take nonce and path arguments. Modify Header to a simple "function" class, that takes auth and path values and returns the correctly formatted header hash.
Modify .new to take host and auth, in addition to method and request. Add :host, :auth, and :response to attr_reader and remove :path, :get_params, and :post_params. Modify call to make :path a positional argument. Replace #call's if-else with an early return on 'success'. Remove #request_args and place its return value inline in #response. Modify #response to take path, get_params, and post_params as arguments. Modify Mirren::Api methods to reflect changes to Request method signatures.
Allows overriding :host, :api_key, :api_secret values, which default to namespaced ENV values. Modify MockClient Spec support class to reflect the changes to Client. Modify Client integration spec to use new configuration override.
| def initialize(opts = {}) | ||
| @host = opts.fetch(:host, ENV['MIRREN_HOST']) | ||
| api_key = opts.fetch(:api_key, ENV['MIRREN_API_KEY']) | ||
| api_secret = opts.fetch(:api_secret, ENV['MIRREN_API_SECRET']) |
There was a problem hiding this comment.
👍 exactly what I hoped for
|
|
||
| def stub_auth | ||
| Struct.new(:api_key) do | ||
| def call(*) |
There was a problem hiding this comment.
what is the * arg syntax? anonymous vararg? Does ** exist as anonymous keyword args?
There was a problem hiding this comment.
It's a shorthand way of saying: accept any number and/or format of arguments to this method. It's usually paired with a simple call to super inside the method, which automatically collects all of the arguments and passes them to super.
I think an argument could be made that its use, here, is superfluous. I think I added it out of habit, as a way to ensure that the stub_auth Struct instance doesn't care what is passed to its #call method.
There was a problem hiding this comment.
Also, the use of **opts, and similar, in a method call signature, is a way to tell Ruby to coerce the remaining passed in arguments as a hash. It will throw an exception if it can't coerce them. Use of **opts must be the last argument (not counting the implied block argument) specified on the method.
|
Awesome, very straightforward changes. LGTM 👍 |
This provides an easy way to override the default ENV values used to configure the consumer's access to the MiningRigRentals API. This required pulling all references to ENV values, down in the
Apimodule classes, up into theClient. I modified theApi::Authclass to be a sub-configuration object on theClient, that theApirequest methods pass down to theRequestclass.I also refactored the
Requestclass to make it easier to pass values around, without relying too heavily on instance variables andattr_reader.@rschifflin