Ejemplo n.º 1
0
        private static void AddFreshDesk(IServiceCollection services, FreshDeskSettings freshDeskSettings)
        {
            if (freshDeskSettings is null)
            {
                throw new ArgumentNullException(nameof(freshDeskSettings));
            }

            // TODO: update tests so these can be re-enabled
            //if (string.IsNullOrEmpty(freshDeskSettings.Domain))
            //    throw new ArgumentException("FreshDesk Domain must be set", nameof(freshDeskSettings));

            //if (string.IsNullOrEmpty(freshDeskSettings.APIKey))
            //    throw new ArgumentException("FreshDesk APIKey must be set", nameof(freshDeskSettings));

            var credentials = new FreshdeskCredentials(freshDeskSettings.APIKey);
            var config      = new FreshdeskConfig
            {
                Domain              = freshDeskSettings.Domain,
                Credentials         = credentials,
                MultiCompanySupport = true,
                RetryWhenThrottled  = true
            };

#pragma warning disable CA2000 // Dispose objects before losing scope - Shouldn't be disposed as all it does is dispose the HttpClient
            var freshDeskClient = new FreshdeskClient(config);
#pragma warning restore CA2000 // Dispose objects before losing scope

            services.AddSingleton(freshDeskClient);
        }
Ejemplo n.º 2
0
 public FreshdeskHttpClient(FreshdeskConfig config)
 {
     _logger             = config.Logger;
     _retryWhenThrottled = config.RetryWhenThrottled;
     _timeout            = config.Timeout;
     _httpClient         = new HttpClient();
     _httpClient.DefaultRequestHeaders.Add("Authorization", $"Basic {config.Credentials.GetEncodedCredentials()}");
 }
 public static FreshdeskConfigInternal FromConfig(FreshdeskConfig config)
 {
     return(new FreshdeskConfigInternal
     {
         ApiBaseUri = $"https://{config.Domain}/api/v2",
         MultiCompanySupport = config.MultiCompanySupport,
         MultiLanguageSupport = config.MultiLanguageSupport,
         MultiTimeZoneSupport = config.MultiTimeZoneSupport,
     });
 }
Ejemplo n.º 4
0
        private static async Task GetAllContactsAsync(string domain, string apiKey)
        {
            var config = new FreshdeskConfig
            {
                Domain             = domain,
                Credentials        = new FreshdeskCredentials(apiKey),
                RetryWhenThrottled = true
            };

            using (var client = new FreshdeskClient(config))
            {
                try
                {
                    var result = await client.Contacts.GetListAsync();

                    var account = await client.Companies.CreateAsync(new FreshdeskCompany
                    {
                        Name = "Fake Company Name, Inc."
                    });

                    var contact = await client.Contacts.CreateAsync(new FreshdeskContact
                    {
                        Active    = true,
                        Name      = "Mr User Name",
                        Email     = "*****@*****.**",
                        CompanyId = account.Id
                    });

                    var ticket = await client.Tickets.CreateAsync(new FreshdeskTicket
                    {
                        RequesterId = contact.Id,
                        Subject     = "Test",
                        Description = "This is a test issue",
                        FrDueBy     = DateTime.UtcNow + TimeSpan.FromHours(5),
                        DueBy       = DateTime.UtcNow + TimeSpan.FromDays(2)
                    });
                }
                catch (Exception ex)
                {
                    throw;
                }
            }
        }