private TDto SerialGet <TDto>(SerialHubSpotContact hubSpotContact, SerialSyncResult run) { var response = _http.Get($"contacts/v1/contact/email/{hubSpotContact.Email}/profile?hapikey={_hubSpotApiKey}&property=vid"); run.GetCount++; var dto = default(TDto); switch (response.StatusCode) { case HttpStatusCode.OK: // 200; update only endpoint _logger.LogInformation($"Retrieved: contact {hubSpotContact.Email}.\r\njson: {dto}"); dto = _http.GetResponseContent <TDto>(response); break; case HttpStatusCode.NotFound: // 404; contact with supplied email address does not exist _logger.LogWarning($"Not Found. Contact does not exist\r\njson: {_serializer.Serialize(hubSpotContact)}"); break; default: // could not get contact _logger.LogWarning($"Exception occurred while GETting contact [{hubSpotContact.Email}]"); break; } return(dto); }
private SerialSyncResult SerialDelete(int currentContactIndex, SerialHubSpotContact hubSpotContact, HubSpotVidResult hubSpotVidResult, int contactCount, SerialSyncResult run) { if (hubSpotVidResult == null) { return(run); } var response = _http.Delete($"contacts/v1/contact/vid/{hubSpotVidResult.ContactVid}?hapikey={_hubSpotApiKey}"); run.DeleteCount++; switch (response.StatusCode) { case HttpStatusCode.OK: // 200; when contact is deleted successfully _logger.LogInformation($"Deleted: contact {currentContactIndex + 1} of {contactCount}"); break; case HttpStatusCode.NotFound: // 404; when the contact vid does not exist _logger.LogWarning($"No contact in HubSpot to delete.\r\njson: {_serializer.Serialize(hubSpotContact)}"); break; default: // contact was rejected for update (application exception) SetFailureData(run, response, hubSpotContact, contactCount, currentContactIndex); break; } return(run); }
private SerialSyncResult SerialUpdate(int currentContactIndex, SerialHubSpotContact hubSpotContact, int contactCount, SerialSyncResult run) { var response = _http.Post($"contacts/v1/contact/email/{hubSpotContact.Email}/profile?hapikey={_hubSpotApiKey}", hubSpotContact); switch (response.StatusCode) { case HttpStatusCode.NoContent: // 204; update only endpoint _logger.LogInformation($"Updated: contact {currentContactIndex + 1} of {contactCount}"); run.SuccessCount++; run.UpdateCount++; break; case HttpStatusCode.NotFound: // 404; update only endpoint; contact does not exist run.EmailAddressesDoNotExist.Add(hubSpotContact); run.EmailAddressDoesNotExistCount++; break; case HttpStatusCode.Conflict: // 409; update endpoint; already exists -- when a contact attempts to update their email address to one already claimed run.EmailAddressesAlreadyExist.Add(hubSpotContact); run.EmailAddressAlreadyExistsCount++; break; default: // contact was rejected for update (application exception) SetFailureData(run, response, hubSpotContact, contactCount, currentContactIndex); break; } return(run); }
public void should_append_environment_and_lifecycle_stage() { var result = new SerialHubSpotContact(); MappingExpressionExtensions.AddTangentialAttributesToHubSpotProperties(result, "dev"); result.Properties.First(item => item.Name == "environment").Value.Should().Be("dev"); result.Properties.First(item => item.Name == "lifecyclestage").Value.Should().Be("customer"); }
public void should_append_environment_and_lifecycle_stage_when_they_dont_already_exist() { var result = new SerialHubSpotContact { Properties = new List <HubSpotContactProperty> { new HubSpotContactProperty { Name = "environment", Value = "PRODUCTION" }, new HubSpotContactProperty { Name = "lifecyclestage", Value = "boss!" } } }; MappingExpressionExtensions.AddTangentialAttributesToHubSpotProperties(result, "dev"); result.Properties.First(item => item.Name == "environment").Value.Should().Be("PRODUCTION"); result.Properties.First(item => item.Name == "lifecyclestage").Value.Should().Be("boss!"); }