C# Class ConstantContactUtility.Utility

Provides utility methods to create a new Contact, update an existing one, etc.
Show file Open project: constantcontact/Constant-Contact-Dot-Net-Wrapper

Public Methods

Method Description
CompareContactListsBySortOrder ( ConstantContactBO.ContactList x, ConstantContactBO.ContactList y ) : int

Defines the compare criteria for two Contact List instances

CreateNewContact ( AuthenticationData authenticationData, ConstantContactBO.Contact contact ) : ConstantContactBO.Contact

Create a New Contact

The POST data presents only values for EmailAddress, FirstName, LastName, OptInSource and ContactLists elements

CreateNewEmailCampaign ( AuthenticationData authenticationData, ConstantContactBO.Entities.EmailCampaign campaign ) : ConstantContactBO.Entities.EmailCampaign

Create a New EmailCampaign

DeleteEmailCampaign ( AuthenticationData authenticationData, string id ) : void

Sends a Http DELETE request at the specified Uri address to delete an Email Campaign

GetContactCollection ( AuthenticationData authenticationData, string &nextChunkId ) : IList

Retrieves the first chunk collection of Contacts that the server provides

Constant Contact server provides paged collections

GetContactCollection ( AuthenticationData authenticationData, string currentChunkId, string &nextChunkId ) : IList

Retrieves the collection of Contacts returned by server at the current chunk Id

Constant Contact server provides paged collections

GetContactDetailsById ( AuthenticationData authenticationData, string id ) : ConstantContactBO.Contact

Retrieve an individual Contact by its Id

GetEmailCampaignById ( AuthenticationData authenticationData, string id ) : ConstantContactBO.Entities.EmailCampaign

Get EmailCampaign By Id

GetEmailCampaignCollection ( AuthenticationData authenticationData ) : List

Gets a list of email campaigns

GetEmailCampaignCollection ( AuthenticationData authenticationData, string status ) : List

Gets a list of email campaigns filtered by status

GetEmailCollection ( AuthenticationData authenticationData, string currentChunkId, string &nextChunkId ) : IList

Retrieves the collection of Emails returned by server

GetUserContactListCollection ( AuthenticationData authenticationData, string &nextChunkId ) : IList

Retrieves the first chunk collection of user Contact Lists that the server provides for current Contact Account Owner. The collection is sorted by the Sort Order and it will not include the system predefined lists ("Active", "Removed", "DoNotEmail")

Constant Contact server provides paged collections

GetUserContactListCollection ( AuthenticationData authenticationData, string currentChunkId, string &nextChunkId ) : IList

Retrieves the collection of user Contact Lists returned by the server at current chunk Id. The collection is sorted by the Sort Order and it will not include the system predefined lists ("Active", "Removed", "DoNotEmail")

IsEmail ( string email ) : bool

Check if e-mail is valid

IsValidUserAuthentication ( AuthenticationData authenticationData ) : void

Verify user authentication

RemoveContactFromAllLists ( AuthenticationData authenticationData, string contactId ) : void

Remove Contact from all Contact Lists

ScheduleEmailCampaign ( AuthenticationData authenticationData, ConstantContactBO.Entities.EmailCampaign campaign ) : ConstantContactBO.Entities.EmailCampaign

Schedule an EmailCampaign

SearchContactByEmail ( AuthenticationData authenticationData, IEnumerable emailAddresses, string &nextChunkId ) : IList

Retrieves the first chunk collection of Contacts that match specified Email Addresses

Constant Contact server provides paged collections

SearchContactByEmail ( AuthenticationData authenticationData, IEnumerable emailAddresses, string currentChunkId, string &nextChunkId ) : List

Retrieves the collection of Contacts that match specified Email Addresses, returned by the server at current chunk Id. Entire collection of Contacts will be returned if no Email Address is specified

Constant Contact server provides paged collections

UnsubscribeContact ( AuthenticationData authenticationData, string contactId ) : void

Opting-out ("Unsubscribe") a Contact

Opted-out Contacts become members of the Do-Not-Mail special list

UpdateContactFullForm ( AuthenticationData authenticationData, ConstantContactBO.Contact contact ) : void

Update a Contact using the full form. All Contact fields will be updated

UpdateEmailCampaign ( AuthenticationData authenticationData, ConstantContactBO.Entities.EmailCampaign campaign ) : ConstantContactBO.Entities.EmailCampaign

Update a New EmailCampaign

UpdateList ( ConstantContactBO.ContactList list, AuthenticationData authdata ) : void

Update an existing ContactList

addFolder ( AuthenticationData authdata, string folderName ) : string

Creates a new folder

addList ( string name, bool optindefault, AuthenticationData authdata ) : void

Create a new Contact List

addList ( string name, bool optindefault, int sortOrder, AuthenticationData authdata ) : void

Create a new Contact List

bulkUrlEncoded ( AuthenticationData authdata, string data, IList listIds ) : string

Uploads text/csv file dumped to string to specified lists

clearContacts ( AuthenticationData authdata, IList listIds ) : string

Removes all contacts from selected lists

clearFolder ( AuthenticationData authdata, int folderId ) : void

Deletes all images in target folder

deleteImage ( AuthenticationData authdata, string link ) : void

Deletes target image

deleteList ( AuthenticationData authdata, string listID ) : void

Delete a Contact List specified by list ID

exportContacts ( AuthenticationData authdata, int listId, string fileType, bool exportOptDate, bool exportOptSource, bool exportListName, string sortBy, IList columns ) : string

Creates export all contacts activity for targeded list.

getActivities ( AuthenticationData Authdata, string &nextChunk ) : IList

Gets first chunk of all activities

getActivities ( AuthenticationData Authdata, string link, string &nextChunk ) : IList

Gets chunk of activites at specified link

getActivityDetails ( AuthenticationData Authdata, string id ) : ConstantContactBO.Activity

Get details of activity with specified ID

getImageDetails ( string link, AuthenticationData Authdata ) : ConstantContactBO.Image

Gets Details of a single image

getListMembers ( string link, AuthenticationData Authdata, string &nextChunk ) : IList

Retrieves all list members of selected node.

Constant Contact server provides paged collections

httpDelete ( AuthenticationData Authdata, string URI ) : string

Sends HTTP Delete to specified URI

httpGet ( AuthenticationData Authdata, string URI ) : string

Performs HTTP GET to specified URI

httpPost ( AuthenticationData Authdata, string URI, string data, string contentType ) : string

Posts XML data to specified URI

httpPut ( AuthenticationData Authdata, string URI, string data, string contentType ) : string

Posts XML data to specified URI

listFolders ( AuthenticationData Authdata, string &nextChunk ) : IList

Retrieves list of first 50 folders

listFolders ( AuthenticationData Authdata, string link, string &nextChunk ) : IList

Retrieves list of all folders in chunks of 50

listImages ( AuthenticationData Authdata, string link, string &nextChunk ) : IList

Get chunk of 50 images at specified link

listImages ( string folderId, AuthenticationData Authdata, string &nextChunk ) : IList

Get chunk of first 50 images in specified folder

urlEncodedPost ( AuthenticationData Authdata, string URI, string content ) : string

HTTP POST using URLEncoded Content Type

Private Methods

Method Description
CreateCredentialCache ( Uri address, AuthenticationData authenticationData ) : ICredentials

Create credentials for network transport

DeleteInformation ( AuthenticationData authenticationData, Uri address ) : void

Sends a Http DELETE request at the specified Uri address

GetContactListCollection ( AuthenticationData authenticationData, string currentChunkId, string &nextChunkId ) : IList

Retrieves the collection of Contact Lists returned by the server at current chunk Id. The collection is sorted by the Sort Order and it will include the system predefined lists ("Active", "Removed", "DoNotEmail")

Constant Contact server provides paged collections

ScheduleEmailCampaign ( AuthenticationData authenticationData, Uri address, string data ) : void
SetCredentials ( AuthenticationData Authdata, HttpWebRequest &request ) : void
UpdateContact ( AuthenticationData authenticationData, ConstantContactBO.Contact contact ) : void

Update a Contact

ValidateAuthenticationData ( AuthenticationData authenticationData ) : void

Check if API Key, Username and Password are not null or empty

Method Details

CompareContactListsBySortOrder() public static method

Defines the compare criteria for two Contact List instances
public static CompareContactListsBySortOrder ( ConstantContactBO.ContactList x, ConstantContactBO.ContactList y ) : int
x ConstantContactBO.ContactList Contact List to be compared
y ConstantContactBO.ContactList Contact List to be compared
return int

CreateNewContact() public static method

Create a New Contact
The POST data presents only values for EmailAddress, FirstName, LastName, OptInSource and ContactLists elements
Thrown if specified Contact is null Thrown if E-mail Address of specified Contact is null or empty Thrown if communication error with Constant server occur /// or other related with the response from server or if specified Contact does not belongs to any list /// or if ApiKey, Username or Password are null or empty
public static CreateNewContact ( AuthenticationData authenticationData, ConstantContactBO.Contact contact ) : ConstantContactBO.Contact
authenticationData AuthenticationData Authentication data (username, password and API Key)
contact ConstantContactBO.Contact Contact to be created
return ConstantContactBO.Contact

CreateNewEmailCampaign() public static method

Create a New EmailCampaign
Thrown if specified EmailCampaign is null Thrown if communication error with Constant server occur /// or other related with the response from server or if ApiKey, Username or Password are null or empty
public static CreateNewEmailCampaign ( AuthenticationData authenticationData, ConstantContactBO.Entities.EmailCampaign campaign ) : ConstantContactBO.Entities.EmailCampaign
authenticationData AuthenticationData Authentication data (username, password and API Key)
campaign ConstantContactBO.Entities.EmailCampaign Email Campaign to be created
return ConstantContactBO.Entities.EmailCampaign

DeleteEmailCampaign() public static method

Sends a Http DELETE request at the specified Uri address to delete an Email Campaign
public static DeleteEmailCampaign ( AuthenticationData authenticationData, string id ) : void
authenticationData AuthenticationData Authentication data (username, password and API Key)
id string campaign id
return void

GetContactCollection() public static method

Retrieves the first chunk collection of Contacts that the server provides
Constant Contact server provides paged collections
Thrown if communication error with Constant server occur /// or other related with the response from server /// or if ApiKey, Username or Password are null or empty
public static GetContactCollection ( AuthenticationData authenticationData, string &nextChunkId ) : IList
authenticationData AuthenticationData Authentication data (username, password and API Key)
nextChunkId string Link to the next chunk of data
return IList

GetContactCollection() public static method

Retrieves the collection of Contacts returned by server at the current chunk Id
Constant Contact server provides paged collections
Thrown if communication error with Constant server occur /// or other related with the response from server /// or if ApiKey, Username or Password are null or empty
public static GetContactCollection ( AuthenticationData authenticationData, string currentChunkId, string &nextChunkId ) : IList
authenticationData AuthenticationData Authentication data (username, password and API Key)
currentChunkId string Link to the current chunk data
nextChunkId string Link to the next chunk of data
return IList

GetContactDetailsById() public static method

Retrieve an individual Contact by its Id
Thrown if communication error with Constant server occur /// or other related with the response from server or if no Contact with specified Id exists /// or if ApiKey, Username or Password are null or empty
public static GetContactDetailsById ( AuthenticationData authenticationData, string id ) : ConstantContactBO.Contact
authenticationData AuthenticationData Authentication data (username, password and API Key)
id string Contact Id
return ConstantContactBO.Contact

GetEmailCampaignById() public static method

Get EmailCampaign By Id
public static GetEmailCampaignById ( AuthenticationData authenticationData, string id ) : ConstantContactBO.Entities.EmailCampaign
authenticationData AuthenticationData Authentication data (username, password and API Key)
id string campaign id
return ConstantContactBO.Entities.EmailCampaign

GetEmailCampaignCollection() public static method

Gets a list of email campaigns
public static GetEmailCampaignCollection ( AuthenticationData authenticationData ) : List
authenticationData AuthenticationData Authentication data (username, password and API Key)
return List

GetEmailCampaignCollection() public static method

Gets a list of email campaigns filtered by status
public static GetEmailCampaignCollection ( AuthenticationData authenticationData, string status ) : List
authenticationData AuthenticationData Authentication data (username, password and API Key)
status string campaign status
return List

GetEmailCollection() public static method

Retrieves the collection of Emails returned by server
Thrown if communication error with Constant server occur /// or other related with the response from server /// or if ApiKey, Username or Password are null or empty
public static GetEmailCollection ( AuthenticationData authenticationData, string currentChunkId, string &nextChunkId ) : IList
authenticationData AuthenticationData Authentication data (username, password and API Key)
currentChunkId string
nextChunkId string
return IList

GetUserContactListCollection() public static method

Retrieves the first chunk collection of user Contact Lists that the server provides for current Contact Account Owner. The collection is sorted by the Sort Order and it will not include the system predefined lists ("Active", "Removed", "DoNotEmail")
Constant Contact server provides paged collections
Thrown if communication error with Constant server occur /// or other related with the response from server /// or if ApiKey, Username or Password are null or empty
public static GetUserContactListCollection ( AuthenticationData authenticationData, string &nextChunkId ) : IList
authenticationData AuthenticationData Authentication data (username, password and API Key)
nextChunkId string Link to the next chunk data
return IList

GetUserContactListCollection() public static method

Retrieves the collection of user Contact Lists returned by the server at current chunk Id. The collection is sorted by the Sort Order and it will not include the system predefined lists ("Active", "Removed", "DoNotEmail")
Thrown if communication error with Constant server occur /// or other related with the response from server /// or if ApiKey, Username or Password are null or empty
public static GetUserContactListCollection ( AuthenticationData authenticationData, string currentChunkId, string &nextChunkId ) : IList
authenticationData AuthenticationData Authentication data (username, password and API Key)
currentChunkId string Link to the current chunk data
nextChunkId string Link to the next chunk of data
return IList

IsEmail() public static method

Check if e-mail is valid
public static IsEmail ( string email ) : bool
email string
return bool

IsValidUserAuthentication() public static method

Verify user authentication
Thrown if communication error with Constant server occur /// or other related with the response from server /// or if ApiKey, Username or Password are null or empty
public static IsValidUserAuthentication ( AuthenticationData authenticationData ) : void
authenticationData AuthenticationData Authentication data (username, password and API Key)
return void

RemoveContactFromAllLists() public static method

Remove Contact from all Contact Lists
Thrown if Id of specified Contact is null or empty Thrown if communication error with Constant server occur /// or other related with the response from server or if no Contact with specified Id exists /// or if ApiKey, Username or Password are null or empty
public static RemoveContactFromAllLists ( AuthenticationData authenticationData, string contactId ) : void
authenticationData AuthenticationData Authentication data (username, password and API Key)
contactId string Contact Id
return void

ScheduleEmailCampaign() public static method

Schedule an EmailCampaign
Thrown if specified EmailCampaign is null Thrown if communication error with Constant server occur /// or other related with the response from server or if ApiKey, Username or Password are null or empty
public static ScheduleEmailCampaign ( AuthenticationData authenticationData, ConstantContactBO.Entities.EmailCampaign campaign ) : ConstantContactBO.Entities.EmailCampaign
authenticationData AuthenticationData Authentication data (username, password and API Key)
campaign ConstantContactBO.Entities.EmailCampaign Email Campaign to be updated
return ConstantContactBO.Entities.EmailCampaign

SearchContactByEmail() public static method

Retrieves the first chunk collection of Contacts that match specified Email Addresses
Constant Contact server provides paged collections
Thrown if communication error with Constant server occur /// or other related with the response from server /// or if ApiKey, Username or Password are null or empty
public static SearchContactByEmail ( AuthenticationData authenticationData, IEnumerable emailAddresses, string &nextChunkId ) : IList
authenticationData AuthenticationData Authentication data (username, password and API Key)
emailAddresses IEnumerable One or more Email Addresses
nextChunkId string Link to the next chunk of data
return IList

SearchContactByEmail() public static method

Retrieves the collection of Contacts that match specified Email Addresses, returned by the server at current chunk Id. Entire collection of Contacts will be returned if no Email Address is specified
Constant Contact server provides paged collections
Thrown if communication error with Constant server occur /// or other related with the response from server /// or if ApiKey, Username or Password are null or empty
public static SearchContactByEmail ( AuthenticationData authenticationData, IEnumerable emailAddresses, string currentChunkId, string &nextChunkId ) : List
authenticationData AuthenticationData Authentication data (username, password and API Key)
emailAddresses IEnumerable One or more Email Addresses
currentChunkId string Link to the current chunk data
nextChunkId string Link to the next chunk of data
return List

UnsubscribeContact() public static method

Opting-out ("Unsubscribe") a Contact
Opted-out Contacts become members of the Do-Not-Mail special list
Thrown if Id of specified Contact is null or empty Thrown if communication error with Constant server occur /// or other related with the response from server or if no Contact with specified Id exists /// or if ApiKey, Username or Password are null or empty
public static UnsubscribeContact ( AuthenticationData authenticationData, string contactId ) : void
authenticationData AuthenticationData Authentication data (username, password and API Key)
contactId string Contact Id
return void

UpdateContactFullForm() public static method

Update a Contact using the full form. All Contact fields will be updated
Thrown if specified Contact is null Thrown if Id or Email Address of specified Contact is null or empty Thrown if communication error with Constant server occur /// or other related with the response from server, if no Contact with specified Id exists /// or if Contact cannot be updated (it belongs to the Do-Not-Mail list) /// or if ApiKey, Username or Password are null or empty
public static UpdateContactFullForm ( AuthenticationData authenticationData, ConstantContactBO.Contact contact ) : void
authenticationData AuthenticationData Authentication data (username, password and API Key)
contact ConstantContactBO.Contact Contact to be updated
return void

UpdateEmailCampaign() public static method

Update a New EmailCampaign
Thrown if specified EmailCampaign is null Thrown if communication error with Constant server occur /// or other related with the response from server or if ApiKey, Username or Password are null or empty
public static UpdateEmailCampaign ( AuthenticationData authenticationData, ConstantContactBO.Entities.EmailCampaign campaign ) : ConstantContactBO.Entities.EmailCampaign
authenticationData AuthenticationData Authentication data (username, password and API Key)
campaign ConstantContactBO.Entities.EmailCampaign Email Campaign to be updated
return ConstantContactBO.Entities.EmailCampaign

UpdateList() public static method

Update an existing ContactList
public static UpdateList ( ConstantContactBO.ContactList list, AuthenticationData authdata ) : void
list ConstantContactBO.ContactList ContactList object to be updated
authdata AuthenticationData Authentication Data for the Constant Contact account
return void

addFolder() public static method

Creates a new folder
public static addFolder ( AuthenticationData authdata, string folderName ) : string
authdata AuthenticationData Authentication Data
folderName string Name of folder to be created
return string

addList() public static method

Create a new Contact List
public static addList ( string name, bool optindefault, AuthenticationData authdata ) : void
name string Name of list to be created
optindefault bool determines if list is the default opt in list
authdata AuthenticationData Authentication data (username, password and API Key)
return void

addList() public static method

Create a new Contact List
public static addList ( string name, bool optindefault, int sortOrder, AuthenticationData authdata ) : void
name string Name of list to be created
optindefault bool determines if list is the default opt in list
sortOrder int Order that the list will show in the Constant Contact UI
authdata AuthenticationData Authentication data (username, password and API Key)
return void

bulkUrlEncoded() public static method

Uploads text/csv file dumped to string to specified lists
public static bulkUrlEncoded ( AuthenticationData authdata, string data, IList listIds ) : string
authdata AuthenticationData Authentication Data
data string CSV or text, dumped to string
listIds IList ID(s) of target lists to upload to
return string

clearContacts() public static method

Removes all contacts from selected lists
public static clearContacts ( AuthenticationData authdata, IList listIds ) : string
authdata AuthenticationData Authentication Data
listIds IList ID(s) of target lists to upload to
return string

clearFolder() public static method

Deletes all images in target folder
public static clearFolder ( AuthenticationData authdata, int folderId ) : void
authdata AuthenticationData Authentication Data
folderId int ID of desired folder to empty
return void

deleteImage() public static method

Deletes target image
public static deleteImage ( AuthenticationData authdata, string link ) : void
authdata AuthenticationData Authentication Data
link string Link to desired image to delete (EX: /ws/customers/{username}/library/folders/{folderID}/images/{imageID})
return void

deleteList() public static method

Delete a Contact List specified by list ID
public static deleteList ( AuthenticationData authdata, string listID ) : void
authdata AuthenticationData Authentication data (username, password and API Key)
listID string ID of target list to delete
return void

exportContacts() public static method

Creates export all contacts activity for targeded list.
public static exportContacts ( AuthenticationData authdata, int listId, string fileType, bool exportOptDate, bool exportOptSource, bool exportListName, string sortBy, IList columns ) : string
authdata AuthenticationData Authenticatoin Data
listId int ID of target list
fileType string Export File Type (TXT or CSV)
exportOptDate bool if add/remove date is included in file
exportOptSource bool if add/removed by (contact or site owner) is included
exportListName bool if name of list is included in file
sortBy string sort by Email Address in Ascending Order (EMAIL_ADDRESS) or Date in Descending Order (DATE_DESC)
columns IList List of what columns to include in exported file
return string

getActivities() public static method

Gets first chunk of all activities
public static getActivities ( AuthenticationData Authdata, string &nextChunk ) : IList
Authdata AuthenticationData Authentication Data
nextChunk string Out Link to next chunk of data if
return IList

getActivities() public static method

Gets chunk of activites at specified link
public static getActivities ( AuthenticationData Authdata, string link, string &nextChunk ) : IList
Authdata AuthenticationData Authentication Data
link string Link to target chunk of data
nextChunk string out link to next chunk of data
return IList

getActivityDetails() public static method

Get details of activity with specified ID
public static getActivityDetails ( AuthenticationData Authdata, string id ) : ConstantContactBO.Activity
Authdata AuthenticationData Authentication Data
id string ID of target activity
return ConstantContactBO.Activity

getImageDetails() public static method

Gets Details of a single image
public static getImageDetails ( string link, AuthenticationData Authdata ) : ConstantContactBO.Image
link string link to target image
Authdata AuthenticationData Authentication Data
return ConstantContactBO.Image

getListMembers() public static method

Retrieves all list members of selected node.
Constant Contact server provides paged collections
public static getListMembers ( string link, AuthenticationData Authdata, string &nextChunk ) : IList
link string Link to target list
Authdata AuthenticationData Authentication data (username, password and API Key)
nextChunk string Link to the next chunk data
return IList

httpDelete() public static method

Sends HTTP Delete to specified URI
public static httpDelete ( AuthenticationData Authdata, string URI ) : string
Authdata AuthenticationData Authentication Data
URI string Target URI to send DELETE to
return string

httpGet() public static method

Performs HTTP GET to specified URI
public static httpGet ( AuthenticationData Authdata, string URI ) : string
Authdata AuthenticationData Authentication Data
URI string Target URI to send request to
return string

httpPost() public static method

Posts XML data to specified URI
public static httpPost ( AuthenticationData Authdata, string URI, string data, string contentType ) : string
Authdata AuthenticationData Authentication Data
URI string Target URI to POST XML data to
data string XML Data
contentType string
return string

httpPut() public static method

Posts XML data to specified URI
public static httpPut ( AuthenticationData Authdata, string URI, string data, string contentType ) : string
Authdata AuthenticationData Authentication Data
URI string Target URI to POST XML data to
data string XML Data
contentType string Type of content for the POST data
return string

listFolders() public static method

Retrieves list of first 50 folders
public static listFolders ( AuthenticationData Authdata, string &nextChunk ) : IList
Authdata AuthenticationData Authentication Data
nextChunk string Out; if more than 50 folders, will out link to next chunk of data
return IList

listFolders() public static method

Retrieves list of all folders in chunks of 50
public static listFolders ( AuthenticationData Authdata, string link, string &nextChunk ) : IList
Authdata AuthenticationData Authentication Data
link string link to chunk of data desired
nextChunk string link to next chunk of 50 if needed, otherwise returns blank string
return IList

listImages() public static method

Get chunk of 50 images at specified link
public static listImages ( AuthenticationData Authdata, string link, string &nextChunk ) : IList
Authdata AuthenticationData Authentication Data
link string Link to desired chunk of data
nextChunk string out link to next chunk of data
return IList

listImages() public static method

Get chunk of first 50 images in specified folder
public static listImages ( string folderId, AuthenticationData Authdata, string &nextChunk ) : IList
folderId string ID of target folder
Authdata AuthenticationData Authentication Data
nextChunk string out link to next chunk of data
return IList

urlEncodedPost() public static method

HTTP POST using URLEncoded Content Type
public static urlEncodedPost ( AuthenticationData Authdata, string URI, string content ) : string
Authdata AuthenticationData Authentication Data
URI string URI to POST URLEncoded data to
content string URLencoded data to POST
return string