Skip to content

1. Usage

Niels Liebisch edited this page Jan 14, 2017 · 5 revisions

Create a Client

Create a virtualQ client by instantiating a VirtualQ class as follows:

        var apiKey = "YOUR-API-KEY";
        using (IVirtualQ client = new VirtualQ(apiKey))
        {
            // Rest of the code ...
        }

VirtualQ class inherits from IDisposable. If the VirtualQ client is not instantiated inside of a using block, the Dispose method must be called in order to release managed resources when the client is no longer used.

        client.Dispose();

IVirtualQ is the interface of the VirtualQ class and defines several properties that represent a handler that matches an end point in the API:

        ILinesHandler Lines { get; }
        ILineGroupsHandler LineGroups { get; }
        ICallerHandler Callers { get; }


Method Results

All method calls are asynchronous and return an object of type Result or Result<T>.

Result

Property Type Description
RequestWasSuccessful bool Overall result of the API call. True if the request was successful, otherwise false.
Error ErrorResult Contains the error information when RequestWasSuccessful is false.

Result<T>

Property Type Description
RequestWasSuccessful bool Overall result of the API call. True if the request was successful, otherwise false.
Error ErrorResult Contains the error information when RequestWasSuccessful is false.
Value T Value returned by the API call. If RequestWasSuccessful is false, Value should be ignored. The value's type is defined in each method's definition.

ErrorResult

Property Type Description
Status int Response error code.
Code string Code description.
Title string Error title.
Description string Error description.


Configuration

You can provide additional information using the VirtualQClientConfiguration class as follows:

        VirtualQClientConfiguration configuration = new VirtualQClientConfiguration
        {
            ApiBaseAddress = "https://api.example.com"                   // Overrides the default API base Url
            Timeout = TimeSpan.FromMilliseconds(1500),                   // Sets Timeout to 1.5 seconds
        };

        var apiKey = "YOUR-API-KEY";
        using (IVirtualQ client = new VirtualQ(apiKey, configuration))
        {
            // Rest of the code ...
        }

All properties in VirtualQClientConfiguration class are optional.



Proxy

If credentials are needed for proxy configuration set them using the WebProxy.Credentials property as follows:

        string proxyAddress = "proxy.example.com";                  // Proxy URL or IP Address
        int proxyPort = 59784;                                      // Proxy port (optional)
        WebProxy proxy = new WebProxy(proxyAddress, proxyPort);     // Sets proxy configuration using a WebProxy clas
        string username = "USERNAME";
        string password = "PASSWORD";
        proxy.Credentials = new NetworkCredential(username, password);

        VirtualQClientConfiguration configuration = new VirtualQClientConfiguration
        {
            ProxyConfiguration = proxy                              // Sets proxy to virtualQ client's configuration
        };

For more information: TimeSpan, WebProxy



Clone this wiki locally