Open manuelmeurer opened 10 years ago
The domain
is really only there in the service a router, and even then, I believe it can be blank. If you want to make any part of the URL dynamic, simply make sure to mark it as such in the client:
get :something, "http://{api_host}/{api_version}/my_resource"
And don't set the domain at all. If that doesn't suit you, then maybe it might be worth being able to pass a lambda to domain
...
Yeah, I figured I could leave out the domain and add it when defining the resources but that gets very repetitive and isn't very DRY. Having something like this would be great:
class MyApp::Client < Weary::Client
domain { "http://#{MyApp.configuration.api_host}/#{MyApp.configuration.api_version}" }
end
Would you accept a PR that implements this? If so, I can take a crack at it.
I have some inclinations about how this should be implemented, but I'd be open to taking a look at a PR.
Well, if you have time to work on it, that would be just great! :smile_cat:
Can you tell me how you would implement this? Then I can prepare a PR.
I would like to be able to set the domain of my client dynamically because I want to configure it to go to another host in development. I tried this
but since the resources are created as soon as the class is loaded, the values of
MyApp.configuration.api_host
andMyApp.configuration.api_version
which are set at that time are used.Any idea how to fix this? I am happy to implement it myself but it's not immediately obvious to me how to do it without rewriting the whole logic.