public async Task <List <Repository> > CreateClient()
        {
            dynamic restClient = _restClientFactory.CreateClient();

            var repositories = await restClient.users.codemazeblog.repos.Get();

            return(repositories);
        }
Beispiel #2
0
        /// <summary>
        /// Gets a response from an endpoint
        /// </summary>
        /// <returns>IRestResponse</returns>
        public string GetResponse(string route)
        {
            var response = _restClientFactory.CreateClient(_baseUri).Execute(
                _restClientFactory.CreateRequest(route, Method.GET));

            return(response.IsSuccessful
                    ? JValue.Parse(response.Content).ToString(Formatting.Indented)
                    : response.Content);
        }
Beispiel #3
0
 public TimeRecordAPIClient(IRestClientFactory restClientFactory, IUserAPIClient userAPIClient, IHttpContextAccessor httpContextAccessor)
 {
     _restClientFactory = restClientFactory;
     _restClient        = _restClientFactory.CreateClient();
     _userAPIClient     = userAPIClient;
     _httpContext       = httpContextAccessor.HttpContext;
     _apiToken          = GetToken();
 }
Beispiel #4
0
        public async Task <List <User> > Users()
        {
            dynamic restClient = _restClientFactory.CreateClient();

            var users = await restClient.User.Get();

            List <User> usersList = new List <User>();

            foreach (var user in users)
            {
                var type = user.GetType();
                if (!type.IsGenericType)
                {
                    User u = JsonConvert.DeserializeObject <User>(user.ToString());
                    usersList.Add(u);
                }
                else
                {
                    foreach (var malformedUsers in user)
                    {
                        User u = JsonConvert.DeserializeObject <User>(malformedUsers.ToString());
                        usersList.Add(u);
                    }
                }
            }

            return(usersList);
        }
 public ApiClient(
     IRestClientFactory clientFactory,
     string baseUrl,
     AuthorityDetails authDetails,
     ILogger <ApiClient> logger)
 {
     Client      = clientFactory.CreateClient(baseUrl);
     RestFactory = clientFactory;
     if (authDetails != null)
     {
         Token = GetToken(authDetails);
     }
     Logger = logger;
 }
Beispiel #6
0
        public async Task PerformAuditing(AuditDetail auditDetail)
        {
            var client  = _restFactory.CreateClient(_baseUrl);
            var request = _restFactory.CreateRequest("api/InssAuditMessaging", RestSharp.Method.POST);

            request = request.AddJsonBody(auditDetail);

            var response = await client.ExecuteAsync(request);

            if (!response.IsSuccessful)
            {
                string errorMessage = $"Auditing Failed: {response.StatusCode}";

                _logger.LogWarning(errorMessage);

                throw new Exception(errorMessage);
            }
        }
Beispiel #7
0
 public UserAPIClient(IRestClientFactory restClientFactory)
 {
     _restClientFactory = restClientFactory;
     _restClient        = _restClientFactory.CreateClient();
 }