Ejemplo n.º 1
0
        public FreshdeskContactDto GetContact(long contactId)
        {
            string responseBody         = String.Empty;
            FreshdeskContactDto contact = null;


            HttpWebRequest request = FreshdeskHttpClient.GetRequestMessage("GET",
                                                                           $"/api/v2/contacts/{contactId}");

            try
            {
                responseBody = GetRequest(request);

                if (!string.IsNullOrEmpty(responseBody))
                {
                    contact = JsonConvert.DeserializeObject <FreshdeskContactDto>(responseBody);
                }
            }
            catch (Exception ex)
            {
                Console.WriteLine(ex.Message);
            }

            return(contact);
        }
Ejemplo n.º 2
0
        public async Task <IEnumerable <AgentDto> > GetAgents2()
        {
            IEnumerable <AgentDto> agentDtos = new List <AgentDto>();

            HttpRequestMessage request = FreshdeskHttpClient.GetRequestMessage(HttpMethod.Get,
                                                                               $"/api/v2/agents?per_page=100");

            try
            {
                var response = await _freshdeskClient.SendAsync(request, HttpCompletionOption.ResponseHeadersRead)
                               .ConfigureAwait(true);

                if (response.IsSuccessStatusCode)
                {
                    var content = await response.Content.ReadAsStringAsync();

                    try
                    {
                        IEnumerable <AgentDto> approvalSummaryJira = JsonConvert.DeserializeObject <IEnumerable <AgentDto> >(content);
                        return(approvalSummaryJira);
                    }
                    catch (Exception)
                    {
                        //Debug.WriteLine(ex.Message);
                    }
                }
            }
            catch (Exception ex)
            {
                Console.WriteLine(ex.Message);
            }

            return(agentDtos);
        }
Ejemplo n.º 3
0
        public IEnumerable <FreshdeskTicket> GetTickets()
        {
            string responseBody            = String.Empty;
            List <FreshdeskTicket> tickets = new List <FreshdeskTicket>();

            int page = 1;

            bool Execute()
            {
                HttpWebRequest request = FreshdeskHttpClient.GetRequestMessage("GET",
                                                                               $"/api/v2/tickets?updated_since={ticketLastSyncDate}&include=stats,description&per_page=100&page={page}&order_by=updated_at&order_type=asc");

                try
                {
                    responseBody = GetRequest(request);

                    if (!string.IsNullOrEmpty(responseBody))
                    {
                        var agentss = JsonConvert.DeserializeObject <IEnumerable <FreshdeskTicket> >(responseBody);

                        if (agentss.ToList().Count > 0)
                        {
                            tickets.AddRange(agentss);
                            return(true);
                        }

                        else
                        {
                            return(false);
                        }
                    }
                    else
                    {
                        return(false);
                    }
                }
                catch (Exception ex)
                {
                    Console.WriteLine(ex.Message);
                    return(false);
                }
            }

            for (int i = 0; i < 10000000; i++)
            {
                if (!Execute())
                {
                    break;
                }

                page++;
            }

            return(from r in tickets
                   where r.Status == 4 || r.Status == 5
                   select r);
        }
Ejemplo n.º 4
0
        public IEnumerable <FreshdeskContactDto> GetContacts()
        {
            string responseBody = String.Empty;
            List <FreshdeskContactDto> contacts = new List <FreshdeskContactDto>();

            int page = 1;

            bool Execute()
            {
                HttpWebRequest request = FreshdeskHttpClient.GetRequestMessage("GET",
                                                                               $"/api/v2/contacts?per_page=100&page={page}&_updated_since={contactLastSyncDate}");

                try
                {
                    responseBody = GetRequest(request);

                    if (!string.IsNullOrEmpty(responseBody))
                    {
                        var agentss = JsonConvert.DeserializeObject <IEnumerable <FreshdeskContactDto> >(responseBody);

                        if (agentss.ToList().Count > 0)
                        {
                            contacts.AddRange(agentss);
                            return(true);
                        }

                        else
                        {
                            return(false);
                        }
                    }
                    else
                    {
                        return(false);
                    }
                }
                catch (Exception ex)
                {
                    Console.WriteLine(ex.Message);
                    return(false);
                }
            }

            for (int i = 0; i < 10000000; i++)
            {
                if (!Execute())
                {
                    break;
                }

                page++;
            }

            return(contacts);
        }
Ejemplo n.º 5
0
        public FreshdeskAccounts GetCompanies()
        {
            string            responseBody       = String.Empty;
            FreshdeskAccounts accounts           = new FreshdeskAccounts();
            FreshdeskAccounts accountsCollection = new FreshdeskAccounts();

            int    page       = 1;
            string dateFilter = $"\"created_at:>%27{accountlastSyncDateString}%27\"";

            void Execute()
            {
                HttpWebRequest request = FreshdeskHttpClient.GetRequestMessage("GET",
                                                                               $"/api/v2/search/companies?page={page}&query={dateFilter}");

                responseBody = GetRequest(request);

                if (!string.IsNullOrEmpty(responseBody))
                {
                    if (page == 1)
                    {
                        accountsCollection = JsonConvert.DeserializeObject <FreshdeskAccounts>(responseBody);
                    }
                    else
                    {
                        accounts = JsonConvert.DeserializeObject <FreshdeskAccounts>(responseBody);

                        if (accounts.Results.Count > 0)
                        {
                            accountsCollection.Results.AddRange(accounts.Results);
                        }
                    }
                }
            }

            try
            {
                Execute();
                decimal noOfPages = Math.Ceiling(((decimal)accountsCollection.Total / (decimal)accountsCollection.Results.Count));

                for (int i = 1; i < noOfPages; i++)
                {
                    ++page;

                    Execute();
                }

                return(accountsCollection);
            }
            catch (Exception ex)
            {
                Console.WriteLine(ex.Message);
            }

            return(accountsCollection);
        }
Ejemplo n.º 6
0
        public FreshdeskRepository()
        {
            var appSettings = ConfigurationManager.AppSettings;

            accountlastSyncDateString = appSettings["AccountLastSyncDate"];
            accountlastSyncDateString = DateTime.Parse(accountlastSyncDateString)
                                        .ToString("yyyy'-'MM'-'dd");
            contactLastSyncDate = appSettings["ContactLastSyncDate"];
            ticketLastSyncDate  = appSettings["TicketLastSyncDate"];
            agentLastSyncDate   = appSettings["AgentLastSyncDate"];
            _freshdeskClient    = FreshdeskHttpClient.GetClient();
        }
Ejemplo n.º 7
0
        public FreshdeskContactDto CreateContact(FreshdeskContactForCreation freshdeskContactForCreation)
        {
            FreshdeskContactDto freshdeskContactDto = null;

            string         responseBody = String.Empty;
            HttpWebRequest request      = FreshdeskHttpClient.GetRequestMessage("POST",
                                                                                $"/api/v2/contacts");

            string data = JsonConvert.SerializeObject(freshdeskContactForCreation);

            byte[] byteArray = Encoding.UTF8.GetBytes(data);
            // Set the ContentLength property of the WebRequest.
            request.ContentLength = byteArray.Length;

            responseBody = WriteRequest(request, byteArray);

            freshdeskContactDto = JsonConvert.DeserializeObject <FreshdeskContactDto>(responseBody);

            return(freshdeskContactDto);
        }