From 323c5f57ff96a9bec078e24623e715fbe104108a Mon Sep 17 00:00:00 2001 From: Tom Copeland Date: Fri, 28 Apr 2017 22:54:06 -0400 Subject: [PATCH] Record base_url returned from successful login Per Docusign team: "In the demo environment all account URLs start with demo.docusign.net, however in production there are multiple sub-domains like www, na2, eu, etc. To resolve all you need to do is parse the baseUrl value that is returned from the login call." This seems to also apply to the oauth token, but I'm not sure of the use case there. Thanks to Will Beattie for the report. --- CHANGELOG.md | 3 ++- lib/docusign_rest/client.rb | 10 ++++++++-- 2 files changed, 10 insertions(+), 3 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 0e4c88cc..2466f6f5 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,9 +1,10 @@ # Changelog -## v0.2.1 April ?? 2017 +## v0.2.1 May ?? 2017 ### Features: * Add certificate option to DocusignRest::Client#get_combined_document_from_envelope (Shane Stanford) +* Memoize base_url after successful login attempt. This prevents problems in production when Docusign returns a different subdomain on login as discussed in [here](https://github.com/jondkinney/docusign_rest/pull/102) (Tom Copeland) ### Misc: * Replace monkeypatch with argument usage (Jean-Philippe Moal) diff --git a/lib/docusign_rest/client.rb b/lib/docusign_rest/client.rb index b7fcc4d1..4b2d10fe 100644 --- a/lib/docusign_rest/client.rb +++ b/lib/docusign_rest/client.rb @@ -6,7 +6,7 @@ module DocusignRest class Client # Define the same set of accessors as the DocusignRest module attr_accessor *Configuration::VALID_CONFIG_KEYS - attr_accessor :docusign_authentication_headers, :acct_id + attr_accessor :docusign_authentication_headers, :acct_id, :base_url def initialize(options={}) # Merge the config values from the module and those passed to the client. @@ -80,7 +80,12 @@ def headers(user_defined_headers={}) # # Returns a parsed URI object def build_uri(url) - URI.parse("#{endpoint}/#{api_version}#{url}") + uri_string = if base_url + "#{base_url}#{url}" + else + "#{endpoint}/#{api_version}#{url}" + end + URI.parse(uri_string) end @@ -190,6 +195,7 @@ def get_account_id hashed_response = JSON.parse(response) login_accounts = hashed_response['loginAccounts'] @acct_id ||= login_accounts.first['accountId'] + @base_url = login_accounts.first['baseUrl'] end acct_id