/// <summary> /// Get a contact by email address /// </summary> /// <param name="email"></param> /// <typeparam name="T"></typeparam> /// <returns></returns> public async Task <T> GetByEmailAsync <T>(string email) where T : IHubSpotEntity, new() { Logger.LogDebug("Contact get by email"); var opt = new OwnerListRequestOptions() { EmailAddress = email }; var owner = await ListAsync <OwnerListHubSpotEntity <OwnerHubSpotEntity> >(opt); var value = owner.Owners.FirstOrDefault(); if (value != null) { return((T)Convert.ChangeType(value, typeof(T))); } return(default(T)); }
/// <summary> /// List contacts /// </summary> /// <param name="opts">Request options - use for pagination</param> /// <typeparam name="T"></typeparam> /// <returns></returns> public async Task <T> ListAsync <T>(OwnerListRequestOptions opts = null) where T : IHubSpotEntity, new() { Logger.LogDebug("Owner ListAsync"); if (opts == null) { opts = new OwnerListRequestOptions(); } var path = PathResolver(new OwnerHubSpotEntity(), HubSpotAction.List); if (!string.IsNullOrEmpty(opts.EmailAddress)) { path = path.SetQueryParam("email", opts.EmailAddress); } if (opts.IncludeInactive) { path = path.SetQueryParam("includeInactive", "true"); } var data = await ListAsync <T>(path); return(data); }
/// <summary> /// List Owners /// </summary> /// <param name="opts">Request options - use for filtering</param> /// <typeparam name="T"></typeparam> /// <returns></returns> public async Task <IEnumerable <T> > ListAsync <T>(OwnerListRequestOptions opts = null) where T : IOwnerHubSpotEntity, new() { Logger.LogDebug("Owner ListAsync"); if (opts == null) { opts = new OwnerListRequestOptions(); } var path = PathResolver(new OwnerHubSpotEntity(), HubSpotAction.List); if (opts.IncludeInactive) { path = path.SetQueryParam("includeinactive", "true"); } if (!string.IsNullOrWhiteSpace(opts.Email)) { path = path.SetQueryParam("email", opts.Email); } var data = await GetGenericAsync <IEnumerable <T> >(path); return(data); }