cbeer/rubydora — Issue #4: RestApiClient.client ignores parameters after the first call
Author: mbklein
Created: 2011-11-17 06:01:34+00:00
State: open

From [rest_api_client.rb](https://github.com/cbeer/rubydora/blob/master/lib/rubydora/rest_api_client.rb#L13):

```Ruby
def client config = {}
config = self.config.merge(config)
@client ||= RestClient::Resource.new(config[:url], :user => config[:user], :password => config[:password], :timeout => config[:timeout], :open_timeout => config[:timeout])
end
```

The use of `@client ||=` means that any existing `RestClient::Resource` instance will take precedence, causing the passed-in config to be ignored. While I realize that it makes sense to create the client once per `Repository` object, and never change it, the fact that the `client` accessor takes parameters makes it look like it's possible to get more than one flavor of client without re-creating the object anew.

I discovered this while adding SSL client certificate support -- my code worked fine, but my tests initially failed because I tried to call `client` twice, with different `config` parameters (one with and one without the client cert), on the same `Repository` object.

I'm going to assume that this is the desired behavior, add a note to the documentation that `config` only matters the first time the method is called, and work around it. It's tempting (but wrong -- see next sentence) to re-create the client if new options are passed in. But that would prevent initializing the client with a particular set of options and then accessing it as a simple attribute, which probably _is_ the desired behavior.

No action on this issue is necessary; I just wanted to bring it up in case you had something different in mind.