static string GetFormSubmissionMode(FormSubmissionMode mode) { return(mode switch { FormSubmissionMode.All => "all", FormSubmissionMode.Newest => "newest", FormSubmissionMode.None => "none", FormSubmissionMode.Oldest => "oldest", _ => throw new ArgumentOutOfRangeException(nameof(mode)), });
public async Task FormSubmissionMode_is_added_to_queryString(FormSubmissionMode formSubmissionMode, string queryStringValue, [Frozen] IHttpRestClient client, IHubSpotContactClient sut, long contactId, Contact contact) { Mock.Get(client) .Setup(p => p.SendAsync <Contact>(HttpMethod.Get, $"/contacts/v1/contact/vid/{contactId}/profile", It.IsAny <IQueryString>())) .ReturnsAsync(contact) .Verifiable(); var response = await sut.GetByIdAsync(contactId, formSubmissionMode : formSubmissionMode); Mock.Get(client) .Verify(p => p.SendAsync <Contact>(HttpMethod.Get, $"/contacts/v1/contact/vid/{contactId}/profile", QueryStringMatcher.That(Does.Contain($"formSubmissionMode={queryStringValue}")))); }
public void AddFormSubmissionMode_adds_value(FormSubmissionMode mode, string value) { var builder = new HttpQueryStringBuilder(); HttpQueryStringBuilderExtensions.AddFormSubmissionMode(builder, mode); Assume.That(builder.HasKey("formSubmissionMode")); var query = builder.BuildQuery(); Assert.That(query.Query, Contains.Substring($"formSubmissionMode={value}")); }
/// <summary> /// Initializes a new instance of the <see cref="GetAllContactsQuery"/> class. /// </summary> /// <param name="count">The number of records to receive default is 20, max is 100.</param> /// <param name="vidOffset">The vid offset of the previous call if any. This will return a new "page" of contacts.</param> /// <param name="property">The names of the properties to return in the response.</param> /// <param name="propertyMode">Determines whether the history of the properties are returned along with the values or just the values.</param> /// <param name="formSubmissionMode">Designates which form submission should be fetched. The default is "newest".</param> /// <param name="showListMemberships">Indicates whether or not the response will contain all list memberships for each contact.</param> public GetAllContactsQuery( int count = 20, int vidOffset = 0, string[] property = null, PropertyMode propertyMode = PropertyMode.value_and_history, FormSubmissionMode formSubmissionMode = ContactsApi.ModelEnums.FormSubmissionMode.all, bool showListMemberships = true) { this.Count = count.ToString(); this.VidOffset = vidOffset; this.Property = property; this.PropertyMode = propertyMode; this.FormSubmissionMode = formSubmissionMode.ToString(); this.ShowListMemberships = showListMemberships; }
/// <summary> /// Initializes a new instance of the <see cref="GetHubSpotContactOp"/> class. /// </summary> /// <param name="email"> /// The email address for the contact you're searching for. /// </param> /// <param name="vid"> /// Unique identifier for a particular contact. In HubSpot's contact system, contact ID's are called "vid", as you can see in the API output below. /// </param> /// <param name="properties"> /// By default, all valued properties will be included. If you include the "property" parameter, then the returned data will only include the property /// or properties that you request. You can include this parameter multiple times to specify multiple properties. The lastmodifieddate and associatedcompanyid will always be /// included, even if not specified. Keep in mind that only properties that have a value will be included in the response, even if specified in the URL. /// </param> /// <param name="propertyMode"> /// One of “value_only” or “value_and_history” to specify if the current value for a property should be fetched, /// or the value and all the historical values for that property. Default is “value_and_history”. /// </param> /// <param name="formSubmissionMode"> /// One of “all”, “none”, “newest”, “oldest” to specify which form submissions should be fetched. Default is “all”. /// </param> /// <param name="showListMembership"> /// Boolean "true" or "false" to indicate whether current list memberships should be fetched for the contact. Default is true. /// </param> public GetHubSpotContactOp( string email, int vid, string[] properties, PropertyMode propertyMode = PropertyMode.value_and_history, FormSubmissionMode formSubmissionMode = FormSubmissionMode.all, bool showListMembership = true) { (string.IsNullOrWhiteSpace(email)).MustForArg( FormattableString.Invariant($"Both {nameof(email)} and {nameof(vid)} cannot be null")); this.Email = email; this.Vid = vid; this.FormSubmissionMode = formSubmissionMode; this.ShowListMembership = showListMembership; this.Properties = properties; this.PropertyMode = propertyMode; //this.Query = new GetContactQuery(new string[]{this.Vid}); }
async Task <IReadOnlyDictionary <long, Contact> > IHubSpotContactClient.GetManyByIdAsync(IReadOnlyList <long> contactIds, IReadOnlyList <IProperty> properties, PropertyMode propertyMode, FormSubmissionMode formSubmissionMode, bool showListMemberships, bool includeDeletes) { if (contactIds == null || contactIds.Count == 0) { return(new Dictionary <long, Contact>()); } if (contactIds.Count >= 100) { throw new ArgumentOutOfRangeException(nameof(contactIds), "Up to 100 contacts can be requested at the same time"); } var builder = new HttpQueryStringBuilder(); foreach (var id in contactIds) { builder.Add("vid", id.ToString()); } builder.AddProperties(properties); builder.AddPropertyMode(propertyMode); builder.AddFormSubmissionMode(formSubmissionMode); builder.AddShowListMemberships(showListMemberships); var contacts = await _client.GetAsync <Dictionary <long, Contact> >("/contacts/v1/contact/vids/batch/", builder.BuildQuery()); return(contacts); }
async Task <Contact> IHubSpotContactClient.GetByUserTokenAsync(string userToken, IReadOnlyList <IProperty> properties, PropertyMode propertyMode, FormSubmissionMode formSubmissionMode, bool showListMemberships) { if (string.IsNullOrEmpty(userToken)) { throw new ArgumentNullException(nameof(userToken)); } var builder = new HttpQueryStringBuilder(); builder.AddProperties(properties); builder.AddPropertyMode(propertyMode); builder.AddFormSubmissionMode(formSubmissionMode); builder.AddShowListMemberships(showListMemberships); try { var contact = await _client.GetAsync <Contact>($"/contacts/v1/contact/utk/{userToken}/profile", builder.BuildQuery()); return(contact); } catch (HttpException ex) when(ex.StatusCode == HttpStatusCode.NotFound) { throw new NotFoundException("Contact not found", ex); } }
async Task <ContactList> IHubSpotContactClient.GetRecentlyCreatedAsync(IReadOnlyList <IProperty> properties, PropertyMode propertyMode, FormSubmissionMode formSubmissionMode, bool showListMemberships, int count, long?contactOffset, DateTimeOffset?timeOffset) { if (count > 100) { throw new ArgumentOutOfRangeException(nameof(count), "Up to 100 contacts can be requested at the same time"); } var builder = new HttpQueryStringBuilder(); builder.AddProperties(properties); builder.AddPropertyMode(propertyMode); builder.AddFormSubmissionMode(formSubmissionMode); builder.AddShowListMemberships(showListMemberships); builder.Add("count", count.ToString()); if (contactOffset.HasValue) { builder.Add("vidOffset", contactOffset.Value.ToString()); } if (timeOffset.HasValue) { builder.Add("timeOffset", timeOffset.Value.ToUnixTimeMilliseconds().ToString()); } var list = await _client.GetAsync <ContactList>("/contacts/v1/lists/all/contacts/recent", builder.BuildQuery()); return(list); }
async Task <Contact> IHubSpotContactClient.GetByIdAsync(long contactId, IReadOnlyList <IProperty> properties, PropertyMode propertyMode, FormSubmissionMode formSubmissionMode, bool showListMemberships) { var builder = new HttpQueryStringBuilder(); builder.AddProperties(properties); builder.AddPropertyMode(propertyMode); builder.AddFormSubmissionMode(formSubmissionMode); builder.AddShowListMemberships(showListMemberships); try { var contact = await _client.GetAsync <Contact>($"/contacts/v1/contact/vid/{contactId}/profile", builder.BuildQuery()); return(contact); } catch (HttpException ex) when(ex.StatusCode == HttpStatusCode.NotFound) { throw new NotFoundException("Contact not found", ex); } }
/// <summary> /// Initializes a new instance of the <see cref="GetContactsByEmailBatchQuery"/> class. /// </summary> /// <param name="props"> /// By default, all valued properties will be included. If you include the "property" parameter, /// then the returned data will only include the property or properties that you request. You can /// include this parameter multiple times to specify multiple properties. The lastmodifieddate and /// associatedcompanyid will always be included, even if not specified. Keep in mind that only /// properties that have a value will be included in the response, even if specified in the URL.</param> /// <param name="propertyMode"> /// One of “value_only” or “value_and_history” to specify if the current value for a property /// should be fetched, or the value and all the historical values for that property. Default /// is “value_and_history”. /// </param> /// <param name="formSubmissionMode"> /// One of “all,” “none,” “newest,” “oldest” to specify which form submissions should be fetched. /// Default is “all.” /// </param> /// <param name="showListMemberships"> /// Boolean "true" or "false" to indicate whether current list memberships should be fetched for the contact. /// Default is true. /// </param> public GetContactsByEmailBatchQuery(string[] props, PropertyMode propertyMode = PropertyMode.value_and_history, FormSubmissionMode formSubmissionMode = ModelEnums.FormSubmissionMode.all, bool showListMemberships = true) { this.Properties = props; this.PropertyMode = propertyMode; this.FormSubmissionMode = formSubmissionMode.ToString(); this.ShowListMemberships = showListMemberships; }
public static void AddFormSubmissionMode(this HttpQueryStringBuilder builder, FormSubmissionMode formSubmissionMode) { if (builder == null) { throw new ArgumentNullException(nameof(builder)); } builder.Add("formSubmissionMode", GetFormSubmissionMode(formSubmissionMode));
public void AddFormSubmissionMode_builder_is_required(FormSubmissionMode testValue) { Assert.Throws <ArgumentNullException>(() => HttpQueryStringBuilderExtensions.AddFormSubmissionMode(null, testValue)); }
async Task <ContactList> IHubSpotListClient.GetContactsInListAsync(long listId, IReadOnlyList <IProperty> properties, PropertyMode propertyMode, FormSubmissionMode formSubmissionMode, bool showListMemberships, int count, long?contactOffset) { if (count > 100) { throw new ArgumentOutOfRangeException(nameof(count), "Up to 100 contacts can be requested at the same time"); } var builder = new HttpQueryStringBuilder(); builder.AddProperties(properties); builder.AddPropertyMode(propertyMode); builder.AddFormSubmissionMode(formSubmissionMode); builder.AddShowListMemberships(showListMemberships); builder.Add("count", count.ToString()); builder.Add("vidOffset", contactOffset); var list = await _client.GetAsync <ContactList>($"/contacts/v1/lists/{listId}/contacts/all", builder.BuildQuery()); return(list); }
/// <summary> /// Initializes a new instance of the <see cref="GetContactQuery"/> class. /// </summary> /// <param name="props"> /// By default, all valued properties will be included. If you include the "property" parameter, /// then the returned data will only include the property or properties that you request. You can /// include this parameter multiple times to specify multiple properties. The lastmodifieddate and /// associatedcompanyid will always be included, even if not specified. Keep in mind that only /// properties that have a value will be included in the response, even if specified in the URL.</param> /// <param name="propertyMode"> /// One of “value_only” or “value_and_history” to specify if the current value for a property /// should be fetched, or the value and all the historical values for that property. Default /// is “value_and_history”. /// </param> /// <param name="formSubmissionMode"> /// One of “all,” “none,” “newest,” “oldest” to specify which form submissions should be fetched. /// Default is “all.” /// </param> /// <param name="showListMemberships"> /// Boolean "true" or "false" to indicate whether current list memberships should be fetched for the contact. /// Default is true. /// </param> public GetContactQuery(string[] props, PropertyMode propertyMode = PropertyMode.value_and_history, FormSubmissionMode formSubmissionMode = FormSubmissionMode.all, bool showListMemberships = true) { this.properties = props; this.propertyMode = propertyMode.ToString(); this.formSubmissionMode = formSubmissionMode.ToString(); this.showListMemberships = showListMemberships; }