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()); }
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>()); }
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 } }); }
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" } }); }
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" } }); }
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); }
/********************************************************************************************************** * 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)); }
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); }
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 } }); }
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()); }
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 } }); }
/********************************************************************************************************** * 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)); }
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); } }
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); }
public TicketsIterator(IHubSpotClient client, HubSpotCrawlJobData jobData, Settings properties) : base(client, jobData) { _settings = properties ?? throw new ArgumentNullException(nameof(properties)); }
public RecentDealsIterator(IHubSpotClient client, HubSpotCrawlJobData jobData) : base(client, jobData) { }
protected HubSpotIteratorBase(IHubSpotClient client, HubSpotCrawlJobData jobData) { Client = client ?? throw new ArgumentNullException(nameof(client)); JobData = jobData ?? throw new ArgumentNullException(nameof(jobData)); }
public DealIterator(IHubSpotClient client, HubSpotCrawlJobData jobData, Settings settings) : base(client, jobData) { _settings = settings ?? throw new ArgumentNullException(nameof(settings)); }
public TemplatesIterator(IHubSpotClient client, HubSpotCrawlJobData jobData) : base(client, jobData) { }
public OwnersIterator(IHubSpotClient client, HubSpotCrawlJobData jobData) : base(client, jobData) { }
public UrlMappingsIterator(IHubSpotClient client, HubSpotCrawlJobData jobData) : base(client, jobData) { }
public PublishingChannelsIterator(IHubSpotClient client, HubSpotCrawlJobData jobData) : base(client, jobData) { }
public EngagementsIterator(IHubSpotClient client, HubSpotCrawlJobData jobData) : base(client, jobData) { }
public SiteMapsIterator(IHubSpotClient client, HubSpotCrawlJobData jobData) : base(client, jobData) { }
public StaticContactListIterator(IHubSpotClient client, HubSpotCrawlJobData jobData) : base(client, jobData) { }
public WorkflowsIterator(IHubSpotClient client, HubSpotCrawlJobData jobData) : base(client, jobData) { }
public BlogPostsIterator(IHubSpotClient client, HubSpotCrawlJobData jobData) : base(client, jobData) { }
public TaskCalendarEventsIterator(IHubSpotClient client, HubSpotCrawlJobData jobData) : base(client, jobData) { }