Пример #1
0
        public override async Task <bool> TestAuthentication(
            ProviderUpdateContext context,
            IDictionary <string, object> configuration,
            Guid organizationId,
            Guid userId,
            Guid providerDefinitionId)
        {
            var hubspotCrawlJobData = new HubSpotCrawlJobData(configuration);

            try
            {
                var client = _hubspotClientFactory.CreateNew(hubspotCrawlJobData);
                var result = await client.GetContactsFromAllListsAsync(new List <string>(), 1, 0);

                return(result != null);
            }
            catch (Exception exception)
            {
                _log.Warn(() => "Could not add HubSpot provider", exception);
                return(false);
            }
        }
Пример #2
0
        public override async Task <AccountInformation> GetAccountInformation(ExecutionContext context, [NotNull] CrawlJobData jobData, Guid organizationId, Guid userId, Guid providerDefinitionId)
        {
            if (jobData == null)
            {
                throw new ArgumentNullException(nameof(jobData));
            }

            var hubspotCrawlJobData = jobData as HubSpotCrawlJobData;

            if (hubspotCrawlJobData == null)
            {
                throw new Exception("Wrong CrawlJobData type");
            }

            var client = _hubspotClientFactory.CreateNew(hubspotCrawlJobData);

            return(await Task.FromResult(client.GetAccountInformation()));
        }
Пример #3
0
        public IEnumerable <object> GetData(CrawlJobData jobData)
        {
            var hubspotcrawlJobData = jobData as HubSpotCrawlJobData;

            if (hubspotcrawlJobData == null)
            {
                yield break;
            }

            var client = _clientFactory.CreateNew(hubspotcrawlJobData);

            //crawl data from provider and yield objects

            foreach (var folder in client.GetFolders())
            {
                yield return(folder);

                foreach (var file in client.GetFilesForFolder(folder.Id))
                {
                    yield return(file);
                }
            }
        }
Пример #4
0
        public async Task <IEnumerable <object> > GetDataAsync(CrawlJobData jobData)
        {
            if (jobData == null)
            {
                throw new ArgumentNullException(nameof(jobData));
            }

            if (!(jobData is HubSpotCrawlJobData crawlerJobData))
            {
                return(EmptyResult);
            }

            var client = _clientFactory.CreateNew(crawlerJobData);

            var settings = await client.GetSettingsAsync();

            if (settings == null)
            {
                _log.Error("Settings could not be obtained from HubSpot");
                return(EmptyResult);
            }

            var dailyLimit = await client.GetDailyLimitAsync();

            if (dailyLimit.currentUsage >= dailyLimit.usageLimit)
            {
                _log.Error("HubSpot daily usage limit has been reached");
                return(EmptyResult);
            }


            var data = new List <object>();

            data.AddRange(new CompanyIterator(client, crawlerJobData, settings).Iterate());
            data.AddRange(new DealIterator(client, crawlerJobData, settings).Iterate());
            data.AddRange(new ContactIterator(client, crawlerJobData, settings).Iterate());
            data.AddRange(new DynamicContactListIterator(client, crawlerJobData).Iterate());
            data.AddRange(new FormsIterator(client, crawlerJobData).Iterate());
            data.AddRange(new OwnersIterator(client, crawlerJobData).Iterate());
            data.AddRange(new PublishingChannelsIterator(client, crawlerJobData).Iterate());
            data.AddRange(new FilesIterator(client, crawlerJobData).Iterate());
            data.AddRange(new SiteMapsIterator(client, crawlerJobData).Iterate());
            data.AddRange(new TemplatesIterator(client, crawlerJobData).Iterate());
            data.AddRange(new UrlMappingsIterator(client, crawlerJobData).Iterate());
            data.AddRange(new EngagementsIterator(client, crawlerJobData).Iterate());
            data.AddRange(new RecentDealsIterator(client, crawlerJobData).Iterate());
            data.AddRange(new RecentlyCreatedDealsIterator(client, crawlerJobData).Iterate());
            data.AddRange(new SmtpTokensIterator(client, crawlerJobData).Iterate());
            data.AddRange(new SocialCalendarEventsIterator(client, crawlerJobData).Iterate());
            data.AddRange(new StaticContactListIterator(client, crawlerJobData).Iterate());
            data.AddRange(new TaskCalendarEventsIterator(client, crawlerJobData).Iterate());
            data.AddRange(new WorkflowsIterator(client, crawlerJobData).Iterate());
            data.AddRange(new BlogPostsIterator(client, crawlerJobData).Iterate());
            data.AddRange(new BlogsIterator(client, crawlerJobData).Iterate());
            data.AddRange(new BlogTopicsIterator(client, crawlerJobData).Iterate());
            data.AddRange(new DomainsIterator(client, crawlerJobData).Iterate());
            data.AddRange(new BroadcastMessagesIterator(client, crawlerJobData).Iterate());
            data.AddRange(new ProductsIterator(client, crawlerJobData, settings).Iterate());
            data.AddRange(new LineItemsIterator(client, crawlerJobData, settings).Iterate());
            data.AddRange(new TicketsIterator(client, crawlerJobData, settings).Iterate());

            return(data);
        }