本文整理汇总了C#中ApiClient.CreateContact方法的典型用法代码示例。如果您正苦于以下问题:C# ApiClient.CreateContact方法的具体用法?C# ApiClient.CreateContact怎么用?C# ApiClient.CreateContact使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类ApiClient
的用法示例。
在下文中一共展示了ApiClient.CreateContact方法的1个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: Create_And_Delete_Survey_And_Campaign_Json
public void Create_And_Delete_Survey_And_Campaign_Json()
{
var testStartedAt = DateTime.Now;
var creds = File.ReadAllLines(@"C:\tmp\sg_creds.txt");
var apiClient = new ApiClient() { ApiToken = creds[0], ApiTokenSecret = creds[1] };
// create survey
var title = "Test Survey " + testStartedAt;
var surveyId = apiClient.CreateSurvey(title);
Assert.IsTrue(surveyId > 0);
// verify that the survey is returned in the list of all surveys
var allSurveys = apiClient.GetAllSurveys();
Assert.IsTrue(allSurveys.Any(s => s.title == title));
// get survey
var survey = apiClient.GetSurvey(surveyId);
Assert.IsNotNull(survey);
Assert.AreEqual(surveyId, survey.id);
Assert.AreEqual(title, survey.title);
Assert.AreEqual("Launched", survey.status);
// create "master" campaign
var masterCampaignName = "Master";
var masterCampaignId = apiClient.CreateCampaign(surveyId, masterCampaignName);
Assert.IsTrue(masterCampaignId > 0);
// create campaign that is a copy of the "master" campaign
var campaignName = "Campaign " + testStartedAt;
var campaignId = apiClient.CreateCampaign(surveyId, campaignName, masterCampaignId);
Assert.IsTrue(campaignId > 0);
// check if the campaign is returned in the list of all campaigns
var campaigns = apiClient.GetCampaigns(surveyId);
Assert.IsNotNull(campaigns);
campaigns = campaigns.Where(c => c._subtype == "email").ToList();
// 2 email campaigns expected
Assert.AreEqual(2, campaigns.Count);
Assert.IsTrue(campaigns.Any(c => c.status == "Active" && c.name == campaignName && c.id == campaignId));
// get the campaign
var campaign = apiClient.GetCampaign(surveyId, campaignId);
Assert.IsNotNull(campaign);
Assert.AreEqual(campaignName, campaign.name);
Assert.AreEqual("Active", campaign.status);
Assert.AreEqual(campaignId, campaign.id);
// get the email messages for the campaign
var emailMessages = apiClient.GetEmailMessageList(surveyId, campaignId);
Assert.IsNotNull(emailMessages);
Assert.AreEqual(1, emailMessages.Count);
Assert.IsNotNull(emailMessages[0]);
Assert.IsNotNull(emailMessages[0].from);
Assert.IsNotNull(emailMessages[0].from.name);
// Survey Research is the default value for the "From" name
Assert.AreEqual("Survey Research", emailMessages[0].from.name);
// update the "From" name on the email message
var updatedFromName = "Updated " + testStartedAt;
emailMessages[0].from.name = updatedFromName;
var nameWasUpdated = apiClient.UpdateEmailMessage(surveyId, campaignId, emailMessages[0]);
Assert.IsTrue(nameWasUpdated);
// get the campaign again to verify that the name was actually updated
emailMessages = apiClient.GetEmailMessageList(surveyId, campaignId);
Assert.IsNotNull(emailMessages);
Assert.AreEqual(1, emailMessages.Count);
Assert.IsNotNull(emailMessages[0]);
Assert.IsNotNull(emailMessages[0].from);
Assert.IsNotNull(emailMessages[0].from.name);
Assert.AreEqual(updatedFromName, emailMessages[0].from.name);
// update the campaign name
var updatedCampaignName = campaignName + " Updated";
campaign.name = updatedCampaignName;
var campaignNameUpdatedSuccess = apiClient.UpdateCampaign(surveyId, campaign);
Assert.IsTrue(campaignNameUpdatedSuccess);
// get the campaign again to verify that the name was updated
campaign = apiClient.GetCampaign(surveyId, campaignId);
Assert.AreEqual(updatedCampaignName, campaign.name);
// create contact
var datetime = testStartedAt.ToString("yyyyMMddHHmmss");
var contactId = apiClient.CreateContact(surveyId, campaignId, "test_" + datetime + "@tntp.org", "John", "Doe", "Test Organization");
Assert.IsTrue(contactId > 0);
// verify that the contact is in the list of contacts
var campaignContactList = apiClient.GetCampaignContactList(surveyId, campaignId);
Assert.AreEqual(1, campaignContactList.Count);
Assert.IsTrue(campaignContactList.Any(c => c.id == contactId));
// update contact
var updated = apiClient.UpdateContact(surveyId, campaignId, contactId, null, null, "Smith");
Assert.IsTrue(updated);
// delete contact
var deleted = apiClient.DeleteContact(surveyId, campaignId, contactId);
Assert.IsTrue(deleted);
//.........这里部分代码省略.........