Example #1
0
        /// <summary>
        /// Gets a person from the system.
        /// Invocations of this method are rate-limited, with a restriction of 60 calls per IP address every 60 seconds.
        /// </summary>
        /// <param name="uid"></param>
        /// <param name="authHeader"></param>
        /// <param name="tDXEnvironment"></param>
        /// <returns></returns>
        public async Task <User> GetPersonByUIDAsync(Guid uid, string authHeader, TDXEnvironment tDXEnvironment)
        {
            JsonSerializerSettings jsonSerializerSettings = new JsonSerializerSettings {
                ContractResolver = new CamelCasePropertyNamesContractResolver()
            };

            var bearer = $"Bearer {authHeader}";

            RestClient  restClient  = new RestClient(tDXEnvironment.ClientUrl + (tDXEnvironment.IsSandboxEnvironment ? "SBTDWebApi" : "TDWebApi"));
            RestRequest restRequest = new RestRequest($"api/people/{uid}", Method.GET);

            restRequest.AddHeader("accept", "application/json");
            restRequest.AddHeader("Authorization", bearer);

            if (tDXEnvironment.ProxyURL != null)
            {
                restClient.Proxy = new WebProxy(tDXEnvironment.ProxyURL, tDXEnvironment.ProxyPort);
            }

            TaskCompletionSource <IRestResponse> taskCompletion = new TaskCompletionSource <IRestResponse>();

            RestRequestAsyncHandle handle = restClient.ExecuteAsync(
                restRequest,
                r => taskCompletion.SetResult(r)
                );

            RestResponse response = (RestResponse)(await taskCompletion.Task);

            if (response.StatusCode == HttpStatusCode.NotFound)
            {
                return(null);
            }

            return(JsonConvert.DeserializeObject <User>(response.Content));
        }
Example #2
0
        public static async Task <RestResponse> ExecuteAsync(this RestClient client, RestRequest request)
        {
            TaskCompletionSource <IRestResponse> taskCompletion = new TaskCompletionSource <IRestResponse> ();
            RestRequestAsyncHandle handle = client.ExecuteAsync(request, r => taskCompletion.SetResult(r));

            return((RestResponse)(await taskCompletion.Task));
        }
        private static void ProcessResponse(IRestRequest request, HttpResponse httpResponse,
                                            RestRequestAsyncHandle asyncHandle, Action <IRestResponse, RestRequestAsyncHandle> callback)
        {
            var restResponse = ConvertToRestResponse(request, httpResponse);

            callback(restResponse, asyncHandle);
        }
Example #4
0
        public async Task <GitResponse> GetRepository()
        {
            List <GitRepositoryDto> repositories = new List <GitRepositoryDto>();
            RestClient  restClient = new RestClient(_gitConfig.RepositoryUrl);
            RestRequest request    = new RestRequest(Method.GET);
            TaskCompletionSource <IRestResponse> taskCompletion = new TaskCompletionSource <IRestResponse>();
            RestRequestAsyncHandle handle   = restClient.ExecuteAsync(request, r => taskCompletion.SetResult(r));
            RestResponse           response = (RestResponse)(await taskCompletion.Task);

            if (response.StatusCode == System.Net.HttpStatusCode.OK)
            {
                repositories = JsonConvert.DeserializeObject <List <GitRepositoryDto> >(response.Content);
            }
            GitResponse resp = new GitResponse()
            {
                Repositories = repositories,
                User         = new UserInfo()
                {
                    Email    = _authConfig.UserName,
                    UserName = _authConfig.Email
                }
            };

            return(resp);
        }
        public static async System.Threading.Tasks.Task <IRestResponse <T> > ExecuteAsync <T>(this RestClient client, RestRequest request) where T : new()
        {
            TaskCompletionSource <IRestResponse <T> > taskCompletion = new TaskCompletionSource <IRestResponse <T> >();
            RestRequestAsyncHandle handle = client.ExecuteAsync <T>(request, r => taskCompletion.SetResult(r));

            return((IRestResponse <T>)(await taskCompletion.Task));
        }
Example #6
0
        static void Main(string[] args)
        {
            if (args.Length < 1)
            {
                Console.WriteLine("Usage: turtles-search symbol1");
                return;
            }

            var symbol = args[0];

            Console.WriteLine($"Searching symbols matching '{symbol}'...");

            var client  = new RestClient("https://finance.yahoo.com");
            var request = new RestRequest($"_finance_doubledown/api/resource/searchassist;searchTerm={symbol}");

            var taskCompletion            = new TaskCompletionSource <IRestResponse>();
            RestRequestAsyncHandle handle = client.ExecuteAsync(
                request, r => taskCompletion.SetResult(r));

            var response  = taskCompletion.Task.Result;
            var theSearch = JsonConvert.DeserializeObject <SearchData>(response.Content);

            foreach (var item in theSearch.Items)
            {
                Console.WriteLine($"{item.Symbol} - {item.Name}");
            }
            Console.WriteLine("");
        }
Example #7
0
        public void SetupClient(Table options)
        {
            Mock <IRestSharpFactory> factoryMock = _container.Mock <IRestSharpFactory>();

            factoryMock.Setup(factory => factory.CreateRequest(It.IsAny <string>(), It.IsAny <Method>()))
            .Returns <string, Method>((resource, method) => (_rest.Request = new RestRequest(resource, method)));

            IRestResponse response = _container.Mock <IRestResponse>().Object;

            var clientMock = _container.Mock <IRestClient>(MockBehavior.Strict);

            clientMock.Setup(client => client.Execute(It.IsAny <IRestRequest>()))
            .Returns(() => response);

            clientMock.Setup(client => client.ExecuteAsync(It.IsAny <IRestRequest>(), It.IsAny <Action <IRestResponse, RestRequestAsyncHandle> >()))
            .Returns <IRestRequest, Action <IRestResponse, RestRequestAsyncHandle> >((request, action) =>
            {
                var handle = new RestRequestAsyncHandle();
                action(response, handle);
                return(handle);
            });

            factoryMock.Setup(factory => factory.CreateClient(It.IsAny <string>()))
            .Returns(() => clientMock.Object);

            _container.Update <IStargateOptions>(options.CreateInstance <StargateOptions>());

            _container.Update <IMimeConverter, XmlMimeConverter>();
            _container.Update <IMimeConverterFactory, MimeConverterFactory>();
            _container.Update <IResourceBuilder, ResourceBuilder>();
            _container.Update <ISimpleValueConverter, SimpleValueConverter>();
            _container.Update <ICodec, Base64Codec>();
            _container.Update <IErrorProvider, ErrorProvider>();
            _container.Update <IStargate, Stargate>();
        }
Example #8
0
        public static async Task <T> ExecuteTask <T>(this IRestClient client, IRestRequest request, Action <IRestResponse> callback)
            where T : ApiResponse, new()
        {
            IRestResponse response;

            try
            {
                //HttpWebRequest requestA = WebRequest.Create("url");
                // HttpWebResponse responseA = (HttpWebResponse)request.GetResponse();

                var webRequest = client.ExecuteAsync(request, callback).WebRequest;
                var result     = new RestRequestAsyncHandle(webRequest);
                if (!webRequest.HaveResponse)
                {
                    var webResponse = await webRequest.GetResponseAsync().ConfigureAwait(false);

                    response = (IRestResponse)webResponse;/* Construct an IRestResponse using webResponse */
                }
                else
                {
                    var webResponse = await webRequest.GetRequestStreamAsync().ConfigureAwait(false);

                    response = (IRestResponse)webResponse;
                }
            }
            catch (Exception ex)
            {
                response = (IRestResponse)ex.InnerException;/* Construct an IRestResponse with error information */
            }
            callback(response);

            return(response.ThrowIfException().Deserialize <T>());
        }
        /// <summary>
        /// Get with filter Wrapper
        /// </summary>
        /// <param name="Parametrs"></param>
        /// <param name="APIMethodURL"></param>
        /// <returns></returns>
        public IEnumerable <T> GetWithFilter(Dictionary <String, object> Parametrs, string APIMethodURL)
        {
            try
            {
                var request = new RestRequest(APIMethodURL, Method.GET)
                {
                    RequestFormat = DataFormat.Json
                };
                if (Parametrs.Count > 0)
                {
                    foreach (var item in Parametrs)
                    {
                        request.AddParameter(item.Key, item.Value, ParameterType.QueryString);
                    }
                }

                TaskCompletionSource <IRestResponse> taskCompletion = new TaskCompletionSource <IRestResponse>();

                RestRequestAsyncHandle handle = _client.ExecuteAsync(request, r => taskCompletion.SetResult(r));

                RestResponse response = (RestResponse)(taskCompletion.Task.Result);
                return(JsonConvert.DeserializeObject <IEnumerable <T> >(response.Content));
            }
            catch (Exception ex)
            {
                return(null);
            }
        }
Example #10
0
        public async System.Threading.Tasks.Task <string> ExecuteAsync(
            List <Parameter> parametros,
            string URI,
            Method _method,
            string token,
            string contentType)
        {
            RestResponse response   = new RestResponse();
            RestClient   restClient = new RestClient(URI);

            RestRequest request = new RestRequest(_method);

            request.AddHeader("cache-control", "no-cache");
            request.AddHeader("content-type", contentType);
            request.AddHeader("Authorization", token);
            foreach (Parameter p in parametros)
            {
                request.AddParameter(p);
            }

            TaskCompletionSource <IRestResponse> taskCompletion = new TaskCompletionSource <IRestResponse>();

            RestRequestAsyncHandle handle = restClient.ExecuteAsync(
                request, r => taskCompletion.SetResult(r));

            response = (RestResponse)(await taskCompletion.Task);
            return(response.Content);
        }
Example #11
0
        /// <summary>
        /// Performs a restricted lookup of TeamDynamix people. Will not return full user information for each matching user.
        /// Invocations of this method are rate-limited, with a restriction of 75 calls per IP address every 10 seconds.
        /// </summary>
        /// <param name="searchText"></param>
        /// <param name="authHeader"></param>
        /// <param name="tDXEnvironment"></param>
        /// <param name="maxResults"></param>
        /// <returns></returns>
        public async Task <List <User> > GetPersonLookupAsync(string searchText, string authHeader, TDXEnvironment tDXEnvironment, int maxResults = 50)
        {
            var bearer = $"Bearer {authHeader}";

            RestClient  restClient  = new RestClient(tDXEnvironment.ClientUrl + (tDXEnvironment.IsSandboxEnvironment ? "SBTDWebApi" : "TDWebApi"));
            RestRequest restRequest = new RestRequest($"api/people/lookup", Method.GET);

            restRequest.AddParameter("searchText", searchText);
            restRequest.AddParameter("maxResults", maxResults);

            restRequest.AddHeader("accept", "application/json");
            restRequest.AddHeader("Authorization", bearer);

            if (tDXEnvironment.ProxyURL != null)
            {
                restClient.Proxy = new WebProxy(tDXEnvironment.ProxyURL, tDXEnvironment.ProxyPort);
            }

            TaskCompletionSource <IRestResponse> taskCompletion = new TaskCompletionSource <IRestResponse>();

            RestRequestAsyncHandle handle = restClient.ExecuteAsync(
                restRequest,
                r => taskCompletion.SetResult(r)
                );

            RestResponse response = (RestResponse)(await taskCompletion.Task);

            if (response.StatusCode == HttpStatusCode.NotFound)
            {
                return(null);
            }

            return(JsonConvert.DeserializeObject <List <User> >(response.Content));
        }
Example #12
0
        /// <summary>
        /// Gets all active ticket sources.
        /// Invocations of this method are rate-limited, with a restriction of 60 calls per IP address every 60 seconds.
        /// </summary>
        /// <param name="appID"></param>
        /// <param name="authHeader"></param>
        /// <param name="tDXEnvironment"></param>
        /// <returns>A list of all active ticket sources. (IEnumerable(Of TeamDynamix.Api.Tickets.TicketSource)) </returns>
        public async Task <List <TicketSource> > GetTicketSourcesAsync(int appID, string authHeader, TDXEnvironment tDXEnvironment)
        {
            var bearer = $"Bearer {authHeader}";

            RestClient  restClient  = new RestClient(tDXEnvironment.ClientUrl + (tDXEnvironment.IsSandboxEnvironment ? "SBTDWebApi" : "TDWebApi"));
            RestRequest restRequest = new RestRequest($"api/{appID}/tickets/sources", Method.GET);

            restRequest.AddHeader("accept", "application/json");
            restRequest.AddHeader("Authorization", bearer);

            if (tDXEnvironment.ProxyURL != null)
            {
                restClient.Proxy = new WebProxy(tDXEnvironment.ProxyURL, tDXEnvironment.ProxyPort);
            }

            TaskCompletionSource <IRestResponse> taskCompletion = new TaskCompletionSource <IRestResponse>();

            RestRequestAsyncHandle handle = restClient.ExecuteAsync(
                restRequest,
                r => taskCompletion.SetResult(r)
                );

            RestResponse response = (RestResponse)(await taskCompletion.Task);

            if (response.StatusCode == HttpStatusCode.NotFound)
            {
                return(null);
            }

            return(JsonConvert.DeserializeObject <List <TicketSource> >(response.Content));
        }
Example #13
0
        /// <summary>
        /// Calls HTTP GET method for a given resource.
        /// </summary>
        /// <typeparam name="T"></typeparam>
        /// <param name="resource">Resource to be called.</param>
        /// <param name="payload">Obejct to be added to the payload</param>
        /// <returns></returns>
        public async Task <T> GetAsync <T>(string resource, object payload = null) where T : new()
        {
            TaskCompletionSource <IRestResponse <T> > taskCompletion = new TaskCompletionSource <IRestResponse <T> >();
            var request = new RestRequest(resource, Method.GET);

            request.JsonSerializer = new global::RestSharp.Newtonsoft.Json.NetCore.NewtonsoftJsonSerializer();

            if (payload != null)
            {
                request.AddJsonBody(payload);
            }

            RestRequestAsyncHandle handle = this.client.ExecuteAsync <T>(request, r => taskCompletion.SetResult(r));
            var result = await taskCompletion.Task;

            if (result.ErrorException != null)
            {
                throw result.ErrorException;
            }

            // response error
            if (result.StatusCode != HttpStatusCode.OK && result.StatusCode != HttpStatusCode.Accepted && result.StatusCode != HttpStatusCode.NoContent && result.StatusCode != HttpStatusCode.Created)
            {
                throw new Exception($"Request error. Status Code: {result.StatusCode}. Content: {result.Content}");
            }

            return(result.Data);
        }
Example #14
0
        public virtual async Task <T> Execute <T>(string resource, Method method, Dictionary <string, string> parameter = null, ParameterType parameterType = ParameterType.GetOrPost)
        {
            var request = new RestRequest(resource, method);

            request.AddHeader("Content-Type", "application/x-www-form-urlencoded");
            request.RequestFormat = DataFormat.Json;

            if (parameter != null)
            {
                foreach (KeyValuePair <string, string> entry in parameter)
                {
                    request.AddParameter(entry.Key, entry.Value, parameterType);
                }
            }
            TaskCompletionSource <IRestResponse> taskCompletion = new TaskCompletionSource <IRestResponse>();
            RestRequestAsyncHandle handle = _client.ExecuteAsync(
                request, r => taskCompletion.SetResult(r));

            RestResponse restResponse = (RestResponse)(await taskCompletion.Task);

            if (restResponse.StatusCode != HttpStatusCode.OK)
            {
                throw new ApplicationException(restResponse.Content);
            }

            if (restResponse.Content != null)
            {
                dynamic content = JsonConvert.DeserializeObject <T>(restResponse.Content);
                return(content);
            }
            ;
            return(JsonConvert.DeserializeObject <T>(restResponse.Content));
        }
Example #15
0
        public async Task <string> GetAuthHeaderAsync(AdminTokenParameters adminTokenParameters, TDXEnvironment tDXEnvironment)
        {
            JsonSerializerSettings jsonSerializerSettings = new JsonSerializerSettings {
                ContractResolver = new CamelCasePropertyNamesContractResolver()
            };

            RestClient  restClient  = new RestClient(tDXEnvironment.ClientUrl + (tDXEnvironment.IsSandboxEnvironment ? "SBTDWebApi" : "TDWebApi"));
            RestRequest restRequest = new RestRequest($"api/auth/loginadmin", Method.POST);

            restRequest.AddHeader("accept", "application/json");
            string jsonObject = JsonConvert.SerializeObject(adminTokenParameters, Formatting.Indented, jsonSerializerSettings);

            restRequest.AddParameter("application/json", jsonObject, ParameterType.RequestBody);

            if (tDXEnvironment.ProxyURL != null)
            {
                restClient.Proxy = new WebProxy(tDXEnvironment.ProxyURL, tDXEnvironment.ProxyPort);
            }

            TaskCompletionSource <IRestResponse> taskCompletion = new TaskCompletionSource <IRestResponse>();

            RestRequestAsyncHandle handle = restClient.ExecuteAsync(
                restRequest,
                r => taskCompletion.SetResult(r)
                );

            RestResponse response = (RestResponse)(await taskCompletion.Task);

            if (response.StatusCode == HttpStatusCode.NotFound)
            {
                return(null);
            }

            return(response.Content);
        }
Example #16
0
 //Callback függvény az aszinkron híváshoz
 private static void BejovoAdatok(IRestResponse <List <Comment> > response, RestRequestAsyncHandle arg2)
 {
     foreach (var comment in response.Data)
     {
         Console.WriteLine(comment.email);
         Console.WriteLine(comment.name);
     }
 }
Example #17
0
        private void GetSampleMessagesCallback(
            IRestResponse <List <SampleMessage> > restResponse,
            RestRequestAsyncHandle restRequestAsyncHandle)
        {
            LoadMessagesButton.Content = restResponse.Data.Count;

            MessagesListView.ItemsSource = restResponse.Data;
        }
Example #18
0
        protected async Task <IRestResponse <T> > ExecuteRequestAsync <T>(IRestRequest restRequest)
            where T : new()
        {
            TaskCompletionSource <IRestResponse <T> > taskCompletion = new TaskCompletionSource <IRestResponse <T> >();
            RestRequestAsyncHandle handle = restClient.ExecuteAsync <T>(restRequest, r => taskCompletion.SetResult(r));

            return(await taskCompletion.Task);
        }
Example #19
0
        public RestRequestAsyncHandle ExecuteAsync <T>(IRestRequest request, Action <IRestResponse <T>, RestRequestAsyncHandle> callback)
        {
            var handle = new RestRequestAsyncHandle();

            Request = request;
            callback(new RestResponse <T>(), handle);
            return(handle);
        }
Example #20
0
        public static async Task <T> ExecuteAsync <T> (this RestClient client, RestRequest request)
        {
            TaskCompletionSource <IRestResponse> taskCompletion = new TaskCompletionSource <IRestResponse> ();
            RestRequestAsyncHandle handle = client.ExecuteAsync(request, r => taskCompletion.SetResult(r));
            var response = (RestResponse)(await taskCompletion.Task);

            return(JsonConvert.DeserializeObject <T> (response.Content));
        }
Example #21
0
        private async Task <XboxAPIRestResponse> executeRequest(RestRequest request)
        {
            TaskCompletionSource <IRestResponse> taskCompletion = new TaskCompletionSource <IRestResponse>();

            RestRequestAsyncHandle handle   = restClient.ExecuteAsync(request, r => taskCompletion.SetResult(r));
            IRestResponse          response = (await taskCompletion.Task);

            return(new XboxAPIRestResponse(response.StatusCode, response.Content));
        }
        public void GetAsyncHandler(IRestResponse <List <T> > restResponse, RestRequestAsyncHandle handle)
        {
            var response = DeserialiseObjectList(restResponse);
            var callback = _ListCallbacks[handle];

            response.handle = handle;
            _ListCallbacks.Remove(handle);
            callback(response);
        }
        public GitHubRequestAsyncHandle(GitHubRequest request,
                                        RestRequestAsyncHandle handle)
        {
            Requires.ArgumentNotNull(request, "request");
            Requires.ArgumentNotNull(handle, "handle");

            _request = request;
            _handle  = handle;
        }
Example #24
0
        public Task SendEmailAsync(string email, string subject, string message)
        {
            //_appSettings

            var client = new RestClient();

            client.BaseUrl = new Uri(_appSettings.EmailBaseUrl);
            // client.BaseUrl = new Uri("https://api.elasticemail.com");
            var request = new RestRequest(_appSettings.EmailServiceUrl, Method.POST);

            //request.AddParameter("apikey", "21eddf0a-7467-4b23-a2c0-6134e1bc60f2");
            //request.AddParameter("from", "*****@*****.**");

            request.AddParameter("apikey", _appSettings.EmailApiKey);
            request.AddParameter("from", _appSettings.EmailFromAddress);

            request.AddParameter("to", email);
            request.AddParameter("subject", subject);
            request.AddParameter("body", message);
            request.AddParameter("isTransactional", true.ToString());

            //method 1
            // var respon = client.ExecuteAsync(request);

            //method 2
            //var response = new RestResponse();
            //Task.Run(async () =>
            //{
            //    response = await GetResponseContentAsync(client, request) as RestResponse;
            //}).Wait();
            //var jsonResponse = JsonConvert.DeserializeObject<dynamic>(response.Content);


            //method 3

            TaskCompletionSource <IRestResponse> taskCompletion = new TaskCompletionSource <IRestResponse>();
            RestRequestAsyncHandle handle = client.ExecuteAsync(
                request, r => taskCompletion.SetResult(r));
            RestResponse         response1     = (RestResponse)(taskCompletion.Task.Result);
            ElasticEmailResponse responsemodel = JsonConvert.DeserializeObject <ElasticEmailResponse>(response1.Content);

            if (responsemodel.success)
            {
                var transcationId = responsemodel.data.transactionid;
                var messageId     = responsemodel.data.messageid;
            }
            //same with 3 but with async
            //TaskCompletionSource<IRestResponse> taskCompletion = new TaskCompletionSource<IRestResponse>();
            //RestRequestAsyncHandle handle = client.ExecuteAsync(
            //    request, r => taskCompletion.SetResult(r));

            //RestResponse response1 = (RestResponse)(await taskCompletion.Task);
            //return JsonConvert.DeserializeObject<SomeObject>(response.Content);

            return(Task.CompletedTask);
        }
Example #25
0
 public void FetchRates()
 {
     foreach (var item in supportedCurrency)
     {
         string resource = string.Format("/finance/converter?a=1&from={0}&to={1}", item.ToUpper(), "INR");
         RestSharp.RestRequest  request = new RestSharp.RestRequest(resource);
         RestSharp.RestClient   client  = new RestSharp.RestClient("http://www.google.com");
         RestRequestAsyncHandle handle  = client.ExecuteAsyncGet(request, AsyncReadUpdateDB, "GET");
     }
 }
        public void GetIdAsyncHandler(IRestResponse <T> restResponse, RestRequestAsyncHandle handle)
        {
            var response = DeserialiseObject <T>(restResponse);

            response.handle = handle;
            var callback = _ItemCallbacks[handle];

            _ItemCallbacks.Remove(handle);
            callback(response);
        }
        private void SlackTokenCallBack(IRestResponse restResponse, RestRequestAsyncHandle arg2)
        {
            string sToken = restResponse.Content;
            //string Token = "{\"ok\":true,\"access_token\":\"xoxp-108334113943-221049390612-246282639767-2e5c136f20e80573ca7ac3c00ee07606\",\"scope\":\"identify,files:write:user\",\"user_id\":\"U6H1FBGJ0\",\"team_name\":\"ExpressBase Systems\",\"team_id\":\"T369U3BTR\"}";

            string    jsonToken  = sToken.Replace("\\", string.Empty);
            SlackJson slackToken = JsonConvert.DeserializeObject <SlackJson>(jsonToken);
            bool      res        = this.ServiceClient.Post <bool>(new SlackAuthRequest {
                IsNew = true, SlackJson = slackToken
            });
        }
Example #28
0
        /// <summary>
        /// Executes the given request using this object's API key.
        /// </summary>
        /// <param name="request">The request to be executed.</param>
        private async Task <RestResponse> execute(RestRequest request)
        {
            RestClient client = new RestClient(baseUrl);

            client.AddDefaultHeader("X-AUTH", apiKey);

            TaskCompletionSource <IRestResponse> taskCompletion = new TaskCompletionSource <IRestResponse>();

            RestRequestAsyncHandle handle = client.ExecuteAsync(request, r => taskCompletion.SetResult(r));

            return((RestResponse)(await taskCompletion.Task));
        }
        public void PutAsyncHandler(IRestResponse response, RestRequestAsyncHandle handle)
        {
            var putResponse = DeserialiseObject <T>(response);

            putResponse.handle = handle;

            var callback = _PutCallbacks[handle];

            _PutCallbacks.Remove(handle);

            callback(putResponse);
        }
        public async Task <IActionResult> ImageFromPath()
        {
            RestClient  client  = new RestClient("https://i.stack.imgur.com/hM8Ah.jpg?s=48&g=1");
            RestRequest request = new RestRequest(Method.GET);

            request.AddHeader("cache-control", "no-cache");
            request.AddHeader("authorization", "Basic aYu7GI");
            TaskCompletionSource <IRestResponse> taskCompletion = new TaskCompletionSource <IRestResponse>();
            RestRequestAsyncHandle handle   = client.ExecuteAsync(request, r => taskCompletion.SetResult(r));
            RestResponse           response = (RestResponse)await taskCompletion.Task;

            return(Ok("data:image/png;base64," + Convert.ToBase64String(response.RawBytes)));
        }