Skip to content

Commit

Permalink
refactor: provide getServiceUrl method and refactor connectors
Browse files Browse the repository at this point in the history
  • Loading branch information
mamoonraja committed Sep 12, 2019
1 parent 88b47b8 commit c4587af
Show file tree
Hide file tree
Showing 3 changed files with 20 additions and 13 deletions.
5 changes: 5 additions & 0 deletions BaseService.cs
Original file line number Diff line number Diff line change
Expand Up @@ -58,6 +58,11 @@ public void SetServiceUrl(string url)
serviceUrl = url;
}

public string GetServiceUrl()
{
return serviceUrl;
}

/// <summary>
/// Returns the authenticator for the service.
/// </summary>
Expand Down
13 changes: 7 additions & 6 deletions Connection/RESTConnector.cs
Original file line number Diff line number Diff line change
Expand Up @@ -260,23 +260,24 @@ public bool? DisableSslVerification
/// </summary>
/// <param name="authenticator">Authenticator used to authenticate service.</param>
/// <param name="function">The name of the function.</param>
/// <param name="serviceUrl">Service Url to connect to.</param>
/// <returns>Returns a RESTConnector object or null on error.</returns>
///
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
};

Expand Down
15 changes: 8 additions & 7 deletions Connection/WSConnector.cs
Original file line number Diff line number Diff line change
Expand Up @@ -322,28 +322,29 @@ public static string FixupURL(string URL)
}

/// <summary>
/// Create a WSConnector for the given service and function.
/// Create a WSConnector for the given service and function.
/// </summary>
/// <param name="authenticator">The authenticator for the service.</param>
/// <param name="function">The name of the function to connect.</param>
/// <param name="args">Additional function arguments.</param>
/// <param name="serviceUrl">Service Url to connect to.</param>
/// <returns>The WSConnector object or null or error.</returns>
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;
Expand Down

0 comments on commit c4587af

Please sign in to comment.