Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse files

Allow setting custom base_urls per-client

  • Loading branch information...
commit 0b5c3a26039d345a9ddfc83cbcd9a74ffcefbd84 1 parent 4c8e0d9
@hmarr hmarr authored
Showing with 28 additions and 0 deletions.
  1. +15 −0 lib/gocardless/client.rb
  2. +13 −0 spec/client_spec.rb
View
15 lib/gocardless/client.rb
@@ -268,6 +268,21 @@ def webhook_valid?(params)
signature_valid?(params)
end
+ # Set the base URL for this client instance. Overrides all other settings
+ # (setting the environment globally, setting the Client class's base URL).
+ #
+ # @param [String] url the base URL to use
+ def base_url=(url)
+ @base_url = url
+ end
+
+ # Get the base URL for the client. If set manually for the instance, that
+ # URL will be returned. Otherwise, it will be deferred to
+ # +Client.base_url+.
+ def base_url
+ @base_url || self.class.base_url
+ end
+
private
# Return the merchant id, throwing a proper error if it's missing.
View
13 spec/client_spec.rb
@@ -469,4 +469,17 @@ def get_params(url)
should be_true
end
end
+
+ describe "base_url" do
+ it "returns a custom base URL when one has been set" do
+ @client.base_url = 'http://test.com/'
+ @client.base_url.should == 'http://test.com/'
+ end
+
+ it "returns the default value when base_url is not set for the instance" do
+ GoCardless::Client.stubs(base_url: 'http://gc.com/')
+ @client.base_url.should == 'http://gc.com/'
+ end
+ end
end
+
Please sign in to comment.
Something went wrong with that request. Please try again.