コード例 #1
0
 public void WriteRestCallFile(string path, ApiProject project)
 {
     if (!Directory.Exists(path))
     {
         Directory.CreateDirectory(path);
     }
     var jsonData = JsonConvert.SerializeObject(project);
     System.IO.File.WriteAllText($"{path}\\{project.Project}.json", jsonData);
 }
コード例 #2
0
 public void RemoveProject(string path, ApiProject apiProject)
 {
     _repository.DeleteRestCallFile($"{path}\\{apiProject.Project}.json");
 }
コード例 #3
0
        public async Task <HttpResponseMessage> SendHttpRequest(string accessToken, string baseUrl, ApiProject apiProjectProject, ApiRoute apiRoute,
                                                                CancellationToken cancellationToken)
        {
            ServicePointManager.ServerCertificateValidationCallback = (message, cert, chain, errors) => true;
            using (var client = new HttpClient())
            {
                client.DefaultRequestHeaders.Accept.Clear();
                client.DefaultRequestHeaders.Accept.Add(new MediaTypeWithQualityHeaderValue("application/json"));

                if (!string.IsNullOrEmpty(apiProjectProject.AuthorizationScheme) &&
                    !string.IsNullOrEmpty(apiProjectProject.AuthorizationParameter))
                {
                    client.DefaultRequestHeaders.Authorization = new AuthenticationHeaderValue(apiProjectProject.AuthorizationScheme, apiProjectProject.GetStringReplacedWithVariable(apiProjectProject.AuthorizationParameter));
                }

                if (apiRoute.HttpVerb == "GET")
                {
                    HttpResponseMessage response = await client.GetAsync($"{baseUrl}/{apiProjectProject.GetStringReplacedWithVariable(apiRoute.Route)}");

                    if (response.IsSuccessStatusCode)
                    {
                        return(response);
                    }
                }
                else if (apiRoute.HttpVerb == "POST")
                {
                    HttpResponseMessage response = await client.PostAsync($"{baseUrl}/{apiProjectProject.GetStringReplacedWithVariable(apiRoute.Route)}", CreateHttpContent(apiRoute.Body));

                    return(response);
                }
                else if (apiRoute.HttpVerb == "PUT")
                {
                    HttpResponseMessage response = await client.PutAsync($"{baseUrl}/{apiProjectProject.GetStringReplacedWithVariable(apiRoute.Route)}", CreateHttpContent(apiRoute.Body));

                    return(response);
                }
                else if (apiRoute.HttpVerb == "DELETE")
                {
                    HttpResponseMessage response = await client.DeleteAsync($"{baseUrl}/{apiProjectProject.GetStringReplacedWithVariable(apiRoute.Route)}");

                    return(response);
                }
            }

            return(new HttpResponseMessage(HttpStatusCode.BadRequest));
            //return String.Empty;
        }
コード例 #4
0
 public void SaveProject(string path, ApiProject apiProject)
 {
     _repository.WriteRestCallFile(path, apiProject);
 }