示例#1
0
        public HappyPath()
        {
            var logger       = new Mock <ILogger>();
            var crawlJobData = new HubSpotCrawlJobData(HubSpotConfiguration.Create());


            _sut = new CluedIn.Crawling.HubSpot.Infrastructure.HubSpotClient(logger.Object, crawlJobData,
                                                                             new RestClient());
        }
示例#2
0
        public override List <QueryResponse> RunQueries(IDictionary <string, object> config, string id, IEntity entity)
        {
            var hubSpotCrawlJobData = new HubSpotCrawlJobData(config);
            var quereis             = new List <QueryResponse>();
            var client  = new RestClient("https://api.hubapi.com");
            var request = new RestRequest(string.Format("/automation/v2/workflows/enrollments/contacts/{0}", id), Method.GET);

            request.AddQueryParameter("hapikey", hubSpotCrawlJobData.ApiToken); // adds to POST or URL querystring based on Method
            var result = client.ExecuteTaskAsync <List <Workflow> >(request).Result;

            if (result.Data == null)
            {
                return(new List <QueryResponse>()
                {
                    new QueryResponse()
                    {
                        Content = result.Content, StatusCode = result.StatusCode
                    }
                });
            }

            if (!result.Data.Any())
            {
                return(new List <QueryResponse>()
                {
                    new QueryResponse()
                    {
                        Content = result.Content, StatusCode = result.StatusCode
                    }
                });
            }

            if (entity.Properties[CluedIn.Core.Data.Vocabularies.Vocabularies.CluedInPerson.Email] == null)
            {
                return(new List <QueryResponse>()
                {
                    new QueryResponse()
                    {
                        Content = result.Content, StatusCode = result.StatusCode
                    }
                });
            }

            foreach (var workflow in result.Data)
            {
                var removeRequest = new RestRequest(string.Format("/automation/v2/workflows/{0}/enrollments/contacts/{1}", workflow.id, entity.Properties[CluedIn.Core.Data.Vocabularies.Vocabularies.CluedInPerson.Email]), Method.DELETE);
                removeRequest.AddQueryParameter("hapikey", hubSpotCrawlJobData.ApiToken); // adds to POST or URL querystring based on Method
                var removeResult = client.ExecuteTaskAsync(removeRequest).Result;

                quereis.Add(new QueryResponse()
                {
                    Content = result.Content, StatusCode = result.StatusCode
                });
            }

            return(quereis);
        }
        public override IEnumerable <Clue> DoProcess(ExecutionContext context, WebhookDataCommand command)
        {
            try
            {
                if (ConfigurationManager.AppSettings.GetFlag("Feature.Webhooks.Log.Posts", false))
                {
                    context.Log.Debug(() => command.HttpPostData);
                }

                var configurationDataStore = context.ApplicationContext.Container.Resolve <IConfigurationRepository>();
                if (command.WebhookDefinition.ProviderDefinitionId != null)
                {
                    var providerDefinition = context.Organization.Providers.GetProviderDefinition(context, command.WebhookDefinition.ProviderDefinitionId.Value);
                    var jobDataCheck       = context.ApplicationContext.Container.ResolveAll <IProvider>().FirstOrDefault(providerInstance => providerDefinition != null && providerInstance.Id == providerDefinition.ProviderId);
                    var configStoreData    = configurationDataStore.GetConfigurationById(context, command.WebhookDefinition.ProviderDefinitionId.Value);  // TODO RJ the configStoreData var is never used. Should it be ?

                    // If you have stopped the provider then don't process the webhooks
                    if (providerDefinition?.WebHooks != null)
                    {
                        if (providerDefinition.WebHooks == false || providerDefinition.IsEnabled == false)
                        {
                            return(new List <Clue>());
                        }
                    }

                    if (jobDataCheck != null)
                    {
                        var crawlJobData = new HubSpotCrawlJobData();

                        var clues = new List <Clue>();

                        IAgentJobProcessorArguments jobArgs = new DebugAgentJobProcessorArguments
                        {
                            TaskScheduler = TaskScheduler.Default,
                            Job           = new AgentJob(Guid.NewGuid(), AgentJobPriority.Normal, "CluedIn" + HubSpotConstants.ProviderName, ProcessingRestriction.Any, null, null)
                        };

                        var processorState = new AgentJobProcessorState <HubSpotCrawlJobData>(jobArgs, AppContext)
                        {
                            JobData = crawlJobData,
                            Status  = new AgentJobStatus {
                                Statistics = new AgentJobStatusStatistics()
                            }
                        };

                        throw new NotImplementedException($"TODO: Implement this to populate '{clues.GetType()}' with '{processorState}'");
                    }
                }
            }
            catch (Exception exception)
            {
                context.Log.Error(new { command.HttpHeaders, command.HttpQueryString, command.HttpPostData, command.WebhookDefinitionId }, () => "Could not process web hook message", exception);
            }

            return(new List <Clue>());
        }
示例#4
0
 public BaseIteratorTest()
 {
     Client  = new Mock <IHubSpotClient>();
     JobData = new HubSpotCrawlJobData(new Dictionary <string, object>
     {
         { HubSpotConstants.KeyName.BaseUri, "" },
         { HubSpotConstants.KeyName.ApiToken, Guid.NewGuid() },
         { HubSpotConstants.KeyName.CustomerSubDomain, "" },
         { HubSpotConstants.KeyName.LastCrawlFinishTime, DateTimeOffset.Now }
     });
 }
示例#5
0
        public override List <RawQuery> GetRawQueries(IDictionary <string, object> config, IEntity entity, Core.Mesh.Properties properties)
        {
            var hubSpotCrawlJobData = new HubSpotCrawlJobData(config);

            return(new List <Core.Messages.WebApp.RawQuery>()
            {
                new Core.Messages.WebApp.RawQuery()
                {
                    Query = string.Format("curl -X PUT https://api.hubapi.com/" + EditUrl + "{1}?hapikey={0} " + "--header \"Content-Type: application/json\"" + " --data '{2}'", hubSpotCrawlJobData.ApiToken, this.GetLookupId(entity), JsonUtility.Serialize(properties)),
                    Source = "cUrl"
                }
            });
        }
示例#6
0
        public override List <Core.Messages.WebApp.RawQuery> GetRawQueries(IDictionary <string, object> config, IEntity entity)
        {
            var hubSpotCrawlJobData = new HubSpotCrawlJobData(config);

            return(new List <Core.Messages.WebApp.RawQuery>()
            {
                new Core.Messages.WebApp.RawQuery()
                {
                    Query = string.Format("curl -X DELETE https://api.hubapi.com/" + DeleteUrl + "{0}?hapikey={1} " + "--header \"Content-Type: application/json\"", hubSpotCrawlJobData.ApiToken, this.GetLookupId(entity)),
                    Source = "cUrl"
                }
            });
        }
示例#7
0
        protected HubSpotProviderTest()
        {
            Container          = new Mock <IWindsorContainer>();
            SystemContext      = new Mock <SystemContext>(Container.Object);
            NameClientFactory  = new Mock <IHubSpotClientFactory>();
            ApplicationContext = new ApplicationContext(Container.Object);
            Logger             = new Mock <ILogger>();
            Configuration      = HubSpotConfiguration.Create();
            CrawlJobData       = new HubSpotCrawlJobData(Configuration);
            Client             = new Mock <HubSpotClient>(Logger.Object, CrawlJobData, new RestClient());
            Sut = new CluedIn.Provider.HubSpot.HubSpotProvider(ApplicationContext, NameClientFactory.Object, Logger.Object, null);

            NameClientFactory.Setup(n => n.CreateNew(It.IsAny <HubSpotCrawlJobData>())).Returns(() => Client.Object);
        }
示例#8
0
        /**********************************************************************************************************
        * METHODS
        **********************************************************************************************************/

        public override async Task <CrawlJobData> GetCrawlJobData(
            ProviderUpdateContext context,
            IDictionary <string, object> configuration,
            Guid organizationId,
            Guid userId,
            Guid providerDefinitionId)
        {
            if (configuration == null)
            {
                throw new ArgumentNullException(nameof(configuration));
            }

            var hubspotCrawlJobData = new HubSpotCrawlJobData(configuration);

            return(await Task.FromResult(hubspotCrawlJobData));
        }
示例#9
0
        public HubSpotClient(ILogger log, HubSpotCrawlJobData hubspotCrawlJobData, IRestClient client)
        {
            if (hubspotCrawlJobData == null)
            {
                throw new ArgumentNullException(nameof(hubspotCrawlJobData));
            }

            _log = log ?? throw new ArgumentNullException(nameof(log));

            _client         = client ?? throw new ArgumentNullException(nameof(client));
            _client.BaseUrl =
                hubspotCrawlJobData.BaseUri != null
                    ? hubspotCrawlJobData.BaseUri
                    : new Uri(HubSpotConstants.ApiBaseUri);

            _client.AddDefaultParameter("hapikey", hubspotCrawlJobData.ApiToken, ParameterType.QueryString);
        }
        public HubSpotClient(ILogger log, HubSpotCrawlJobData hubspotCrawlJobData, IRestClient client) // TODO: pass on any extra dependencies
        {
            if (hubspotCrawlJobData == null)
            {
                throw new ArgumentNullException(nameof(hubspotCrawlJobData));
            }
            if (client == null)
            {
                throw new ArgumentNullException(nameof(client));
            }

            _log = log ?? throw new ArgumentNullException(nameof(log));

            // TODO use info from hubspotCrawlJobData to instantiate the connection
            client.BaseUrl = new Uri(s_baseUri);
            client.AddDefaultParameter("api_key", hubspotCrawlJobData.ApiKey, ParameterType.QueryString);
        }
示例#11
0
        public override List <QueryResponse> Validate(ExecutionContext context, RemoveFromProcessingDataCommand command, IDictionary <string, object> config, string id, MeshQuery query)
        {
            var hubSpotCrawlJobData = new HubSpotCrawlJobData(config);
            var quereis             = new List <QueryResponse>();
            var client  = new RestClient("https://api.hubapi.com");
            var request = new RestRequest(string.Format("/automation/v2/workflows/enrollments/contacts/{0}", id), Method.GET);

            request.AddQueryParameter("hapikey", hubSpotCrawlJobData.ApiToken); // adds to POST or URL querystring based on Method
            var result = client.ExecuteTaskAsync <List <Workflow> >(request).Result;

            return(new List <QueryResponse>()
            {
                new QueryResponse()
                {
                    Content = result.Content, StatusCode = result.StatusCode
                }
            });
        }
示例#12
0
            public GetDataTests()
            {
                var nameClientFactory = new Mock <IHubSpotClientFactory>();

                _clientMock = new Mock <IHubSpotClient>();

                _clientMock
                .Setup(x => x.GetSettingsAsync())
                .Returns(Task.FromResult(new Settings()));

                _logMock = new Mock <ILogger>();

                nameClientFactory.Setup(x => x.CreateNew(It.IsAny <HubSpotCrawlJobData>())).Returns(_clientMock.Object);

                _sut = new CluedIn.Crawling.HubSpot.Crawler(nameClientFactory.Object, _logMock.Object);

                _crawlJobData = new HubSpotCrawlJobData(HubSpotConfiguration.Create());
            }
示例#13
0
        public override List <QueryResponse> RunQueries(IDictionary <string, object> config, string id)
        {
            var hubSpotCrawlJobData = new HubSpotCrawlJobData(config);
            var client  = new RestClient("https://api.hubapi.com");
            var request = new RestRequest(string.Format(DeleteUrl + "{0}", id), Method.DELETE);

            request.AddQueryParameter("hapikey", hubSpotCrawlJobData.ApiToken); // adds to POST or URL querystring based on Method

            var result = client.ExecuteTaskAsync(request).Result;

            return(new List <QueryResponse>()
            {
                new QueryResponse()
                {
                    Content = result.Content, StatusCode = result.StatusCode
                }
            });
        }
示例#14
0
        /**********************************************************************************************************
        * METHODS
        **********************************************************************************************************/

        public override async Task <CrawlJobData> GetCrawlJobData(
            ProviderUpdateContext context,
            IDictionary <string, object> configuration,
            Guid organizationId,
            Guid userId,
            Guid providerDefinitionId)
        {
            if (configuration == null)
            {
                throw new ArgumentNullException(nameof(configuration));
            }

            var hubspotCrawlJobData = new HubSpotCrawlJobData();

            if (configuration.ContainsKey(HubSpotConstants.KeyName.ApiKey))
            {
                hubspotCrawlJobData.ApiKey = configuration[HubSpotConstants.KeyName.ApiKey].ToString();
            }

            return(await Task.FromResult(hubspotCrawlJobData));
        }
示例#15
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);
            }
        }
示例#16
0
        public override List <Core.Messages.WebApp.RawQuery> GetRawQueries(IDictionary <string, object> config, IEntity entity)
        {
            var queries             = new List <Core.Messages.WebApp.RawQuery>();
            var hubSpotCrawlJobData = new HubSpotCrawlJobData(config);

            var client  = new RestClient("https://api.hubapi.com");
            var request = new RestRequest(string.Format("/automation/v2/workflows/enrollments/contacts/{0}", GetLookupId(entity)), Method.GET);

            request.AddQueryParameter("hapikey", hubSpotCrawlJobData.ApiToken); // adds to POST or URL querystring based on Method
            var result = client.ExecuteTaskAsync <List <Workflow> >(request).Result;

            if (result.Data == null)
            {
                return(new List <Core.Messages.WebApp.RawQuery>());
            }

            if (!result.Data.Any())
            {
                return(new List <Core.Messages.WebApp.RawQuery>());
            }

            if (entity.Properties[CluedIn.Core.Data.Vocabularies.Vocabularies.CluedInPerson.Email] == null)
            {
                return(new List <Core.Messages.WebApp.RawQuery>());
            }

            foreach (var workflow in result.Data)
            {
                queries.Add(new Core.Messages.WebApp.RawQuery()
                {
                    Query  = string.Format("curl -X DELETE https://api.hubapi.com/" + "/automation/v2/workflows/{1}/enrollments/contacts/{2}" + "?hapikey={0} " + "--header \"Content-Type: application/json\"", hubSpotCrawlJobData.ApiToken, workflow.id, entity.Properties[CluedIn.Core.Data.Vocabularies.Vocabularies.CluedInPerson.Email]),
                    Source = "cUrl"
                });
            }

            return(queries);
        }
示例#17
0
 public TicketsIterator(IHubSpotClient client, HubSpotCrawlJobData jobData, Settings properties) : base(client, jobData)
 {
     _settings = properties ?? throw new ArgumentNullException(nameof(properties));
 }
示例#18
0
 public RecentDealsIterator(IHubSpotClient client, HubSpotCrawlJobData jobData) : base(client, jobData)
 {
 }
示例#19
0
 protected HubSpotIteratorBase(IHubSpotClient client, HubSpotCrawlJobData jobData)
 {
     Client  = client ?? throw new ArgumentNullException(nameof(client));
     JobData = jobData ?? throw new ArgumentNullException(nameof(jobData));
 }
示例#20
0
 public DealIterator(IHubSpotClient client, HubSpotCrawlJobData jobData, Settings settings) : base(client, jobData)
 {
     _settings = settings ?? throw new ArgumentNullException(nameof(settings));
 }
示例#21
0
 public TemplatesIterator(IHubSpotClient client, HubSpotCrawlJobData jobData) : base(client, jobData)
 {
 }
示例#22
0
 public OwnersIterator(IHubSpotClient client, HubSpotCrawlJobData jobData) : base(client, jobData)
 {
 }
示例#23
0
 public UrlMappingsIterator(IHubSpotClient client, HubSpotCrawlJobData jobData) : base(client, jobData)
 {
 }
示例#24
0
 public PublishingChannelsIterator(IHubSpotClient client, HubSpotCrawlJobData jobData) : base(client, jobData)
 {
 }
示例#25
0
 public EngagementsIterator(IHubSpotClient client, HubSpotCrawlJobData jobData) : base(client, jobData)
 {
 }
示例#26
0
 public SiteMapsIterator(IHubSpotClient client, HubSpotCrawlJobData jobData) : base(client, jobData)
 {
 }
示例#27
0
 public StaticContactListIterator(IHubSpotClient client, HubSpotCrawlJobData jobData) : base(client, jobData)
 {
 }
示例#28
0
 public WorkflowsIterator(IHubSpotClient client, HubSpotCrawlJobData jobData) : base(client, jobData)
 {
 }
示例#29
0
 public BlogPostsIterator(IHubSpotClient client, HubSpotCrawlJobData jobData) : base(client, jobData)
 {
 }
示例#30
0
 public TaskCalendarEventsIterator(IHubSpotClient client, HubSpotCrawlJobData jobData) : base(client, jobData)
 {
 }