From c4587af77b33b63c24a10baa1189cf7ee59314e1 Mon Sep 17 00:00:00 2001 From: Mamoon Raja Date: Thu, 12 Sep 2019 15:09:18 -0400 Subject: [PATCH] refactor: provide getServiceUrl method and refactor connectors --- BaseService.cs | 5 +++++ Connection/RESTConnector.cs | 13 +++++++------ Connection/WSConnector.cs | 15 ++++++++------- 3 files changed, 20 insertions(+), 13 deletions(-) diff --git a/BaseService.cs b/BaseService.cs index a419212..cadd5f3 100644 --- a/BaseService.cs +++ b/BaseService.cs @@ -58,6 +58,11 @@ public void SetServiceUrl(string url) serviceUrl = url; } + public string GetServiceUrl() + { + return serviceUrl; + } + /// /// Returns the authenticator for the service. /// diff --git a/Connection/RESTConnector.cs b/Connection/RESTConnector.cs index 3460dc2..eca60fa 100644 --- a/Connection/RESTConnector.cs +++ b/Connection/RESTConnector.cs @@ -260,23 +260,24 @@ public bool? DisableSslVerification /// /// Authenticator used to authenticate service. /// The name of the function. + /// Service Url to connect to. /// Returns a RESTConnector object or null on error. /// - public static RESTConnector GetConnector(Authenticator authenticator, string function, string url) + public static RESTConnector GetConnector(Authenticator authenticator, string function, string serviceUrl) { - if (string.IsNullOrEmpty(url)) + if (string.IsNullOrEmpty(serviceUrl)) { - throw new ArgumentNullException("The Url must not be empty or null."); + throw new ArgumentNullException("The serviceUrl must not be empty or null."); } - if (Utility.HasBadFirstOrLastCharacter(url)) + if (Utility.HasBadFirstOrLastCharacter(serviceUrl)) { - throw new ArgumentException("The Url property is invalid. Please remove any surrounding {{, }}, or \" characters."); + throw new ArgumentException("The serviceUrl property is invalid. Please remove any surrounding {{, }}, or \" characters."); } RESTConnector connector = new RESTConnector { - URL = url + function, + URL = serviceUrl + function, Authentication = authenticator }; diff --git a/Connection/WSConnector.cs b/Connection/WSConnector.cs index d1ba01a..55940a7 100644 --- a/Connection/WSConnector.cs +++ b/Connection/WSConnector.cs @@ -322,28 +322,29 @@ public static string FixupURL(string URL) } /// - /// Create a WSConnector for the given service and function. + /// Create a WSConnector for the given service and function. /// /// The authenticator for the service. /// The name of the function to connect. /// Additional function arguments. + /// Service Url to connect to. /// The WSConnector object or null or error. - public static WSConnector CreateConnector(Authenticator authenticator, string function, string args, string url) + public static WSConnector CreateConnector(Authenticator authenticator, string function, string args, string serviceUrl) { - if (string.IsNullOrEmpty(url)) + if (string.IsNullOrEmpty(serviceUrl)) { - throw new ArgumentNullException("The Url must not be empty or null."); + throw new ArgumentNullException("The serviceUrl must not be empty or null."); } - if (Utility.HasBadFirstOrLastCharacter(url)) + if (Utility.HasBadFirstOrLastCharacter(serviceUrl)) { - throw new ArgumentException("The Url property is invalid. Please remove any surrounding {{, }}, or \" characters."); + throw new ArgumentException("The serviceUrl property is invalid. Please remove any surrounding {{, }}, or \" characters."); } WSConnector connector = new WSConnector(); connector.Authentication = authenticator; - connector.URL = FixupURL(url) + function + args; + connector.URL = FixupURL(serviceUrl) + function + args; authenticator.Authenticate(connector); return connector;