Skip to content

Commit

Permalink
Client methods and any associated models complete
Browse files Browse the repository at this point in the history
  • Loading branch information
Jason Hickey committed Nov 11, 2010
1 parent d8648b8 commit f50a19c
Show file tree
Hide file tree
Showing 8 changed files with 118 additions and 25 deletions.
4 changes: 2 additions & 2 deletions ConsoleRunner/Program.cs
Expand Up @@ -9,10 +9,10 @@ namespace ConsoleRunner
class Program
{
//011ebcadaeb71e9a
//277da11f331fc698ad22a66c0c4b5c33
static void Main(string[] args)
{
foreach (BasicSegment campaign in Client.Segments("011ebcadaeb71e9a"))
Console.WriteLine(campaign.Title);
new Client("34a1fa45cbf30b2024e3df25fa214e54").Delete();
}
}
}
78 changes: 66 additions & 12 deletions createsend-dotnet/Client.cs
Expand Up @@ -7,40 +7,94 @@ namespace createsend_dotnet
{
public class Client
{
public static string Create(ClientDetail newClient)
private string _clientID;

public Client(string clientID)
{
_clientID = clientID;
}

public string Create(string companyName, string contactName, string emailAddress, string country, string timezone)
{
string json = HttpHelper.Post("/clients.json", null, JavaScriptConvert.SerializeObject(newClient));
string json = HttpHelper.Post("/clients.json", null, JavaScriptConvert.SerializeObject(
new ClientDetail() { CompanyName = companyName, ContactName = contactName, EmailAddress = emailAddress, Country = country, TimeZone = timezone })
);
return JavaScriptConvert.DeserializeObject<string>(json);
}

public static ClientWithSettings Details(string clientID)
public ClientWithSettings Details()
{
string json = HttpHelper.Get(string.Format("/clients/{0}.json", clientID), null);
string json = HttpHelper.Get(string.Format("/clients/{0}.json", _clientID), null);
return JavaScriptConvert.DeserializeObject<ClientWithSettings>(json);
}

public static IEnumerable<CampaignDetail> Campaigns(string clientID)
public IEnumerable<CampaignDetail> Campaigns()
{
string json = HttpHelper.Get(string.Format("/clients/{0}/campaigns.json", clientID), null);
string json = HttpHelper.Get(string.Format("/clients/{0}/campaigns.json", _clientID), null);
return JavaScriptConvert.DeserializeObject<CampaignDetail[]>(json);
}

public static IEnumerable<DraftDetail> Drafts(string clientID)
public IEnumerable<DraftDetail> Drafts()
{
string json = HttpHelper.Get(string.Format("/clients/{0}/drafts.json", clientID), null);
string json = HttpHelper.Get(string.Format("/clients/{0}/drafts.json", _clientID), null);
return JavaScriptConvert.DeserializeObject<DraftDetail[]>(json);
}

public static IEnumerable<BasicList> Lists(string clientID)
public IEnumerable<BasicList> Lists()
{
string json = HttpHelper.Get(string.Format("/clients/{0}/lists.json", clientID), null);
string json = HttpHelper.Get(string.Format("/clients/{0}/lists.json", _clientID), null);
return JavaScriptConvert.DeserializeObject<BasicList[]>(json);
}

public static IEnumerable<BasicSegment> Segments(string clientID)
public IEnumerable<BasicSegment> Segments()
{
string json = HttpHelper.Get(string.Format("/clients/{0}/segments.json", clientID), null);
string json = HttpHelper.Get(string.Format("/clients/{0}/segments.json", _clientID), null);
return JavaScriptConvert.DeserializeObject<BasicSegment[]>(json);
}

public PagedCollection<BasicSubscriber> SuppressionList()
{
string json = HttpHelper.Get(string.Format("/clients/{0}/suppressionlist.json", _clientID), null);
return JavaScriptConvert.DeserializeObject<PagedCollection<BasicSubscriber>>(json);
}

public IEnumerable<BasicTemplate> Templates()
{
string json = HttpHelper.Get(string.Format("/clients/{0}/templates.json", _clientID), null);
return JavaScriptConvert.DeserializeObject<BasicTemplate[]>(json);
}

public void SetBasics(string companyName, string contactName, string emailAddress, string country, string timezone)
{
HttpHelper.Put(string.Format("/clients/{0}/setbasics.json", _clientID), null, JavaScriptConvert.SerializeObject(
new ClientDetail() { CompanyName = companyName, ContactName = contactName, EmailAddress = emailAddress, Country = country, TimeZone = timezone })
);
}

public void SetAccess(string userName, string password, int accessLevel)
{
HttpHelper.Put(string.Format("/clients/{0}/setaccess.json", _clientID), null, JavaScriptConvert.SerializeObject(
new ClientAccessSettings() { Username = userName, Password = password, AccessLevel = accessLevel })
);
}

public void SetPAYGBilling(string currency, bool clientPays, bool canPurchaseCredits, int markupPercentage, decimal markupOnDelivery, decimal markupPerRecipient, decimal markupOnDesignSpamTest)
{
HttpHelper.Put(string.Format("/clients/{0}/setpaygbilling.json", _clientID), null, JavaScriptConvert.SerializeObject(
new BillingOptions() { Currency = currency, ClientPays = clientPays, CanPurchaseCredits = canPurchaseCredits, MarkupPercentage = markupPercentage, MarkupOnDelivery = markupOnDelivery, MarkupPerRecipient = markupPerRecipient, MarkupOnDesignSpamTest = markupOnDesignSpamTest })
);
}

public void SetMonthlyBilling(string currency, bool clientPays, bool canPurchaseCredits, int markupPercentage)
{
HttpHelper.Put(string.Format("/clients/{0}/setmonthlybilling.json", _clientID), null, JavaScriptConvert.SerializeObject(
new BillingOptions() { Currency = currency, ClientPays = clientPays, CanPurchaseCredits = canPurchaseCredits, MarkupPercentage = markupPercentage })
);
}

public void Delete()
{
HttpHelper.Delete(string.Format("/clients/{0}.json", _clientID), null);
}
}
}
2 changes: 1 addition & 1 deletion createsend-dotnet/HttpHelper.cs
Expand Up @@ -74,7 +74,7 @@ static string MakeRequest(string method, string uri, string payload)
{
HttpWebRequest req = (HttpWebRequest)WebRequest.Create(uri);
req.Method = method;
req.ContentType = "application/xml";
req.ContentType = "application/json";
req.UserAgent = "createsend-dotnet-#" + CreateSendOptions.VersionNumber;

req.Credentials = authCredentials;
Expand Down
10 changes: 0 additions & 10 deletions createsend-dotnet/Models/Client.cs
Expand Up @@ -23,16 +23,6 @@ public class ClientWithSettings

public class ClientDetail
{
public ClientDetail() { }
public ClientDetail(string companyName, string contactName, string emailAddress, string country, string timezone)
{
CompanyName = companyName;
ContactName = contactName;
EmailAddress = emailAddress;
Country = country;
TimeZone = timezone;
}

public string ClientID { get; set; }
public string CompanyName { get; set; }
public string ContactName { get; set; }
Expand Down
19 changes: 19 additions & 0 deletions createsend-dotnet/Models/PagedCollection.cs
@@ -0,0 +1,19 @@
using System;
using System.Collections.Generic;
using System.Text;

namespace createsend_dotnet
{
public class PagedCollection<T>
{
//deserializer does not allow deserialization from JSON list straight to IEnumerable<T>
public List<T> Results { get; set; }
public string ResultsOrderedBy { get; set; }
public string OrderDirection { get; set; }
public int PageNumber { get; set; }
public int PageSize { get; set; }
public int RecordsOnThisPage { get; set; }
public int TotalNumberOfRecords { get; set; }
public int NumberOfPages { get; set; }
}
}
13 changes: 13 additions & 0 deletions createsend-dotnet/Models/Subscriber.cs
@@ -0,0 +1,13 @@
using System;
using System.Collections.Generic;
using System.Text;

namespace createsend_dotnet
{
public class BasicSubscriber
{
public string EmailAddress { get; set; }
public DateTime Date { get; set; }
public string State { get; set; }
}
}
14 changes: 14 additions & 0 deletions createsend-dotnet/Models/Template.cs
@@ -0,0 +1,14 @@
using System;
using System.Collections.Generic;
using System.Text;

namespace createsend_dotnet
{
public class BasicTemplate
{
public string TemplateID { get; set; }
public string Name { get; set; }
public string PreviewURL { get; set; }
public string ScreenshotURL { get; set; }
}
}
3 changes: 3 additions & 0 deletions createsend-dotnet/createsend-dotnet.csproj
Expand Up @@ -50,7 +50,10 @@
<Compile Include="Models\Client.cs" />
<Compile Include="HttpHelper.cs" />
<Compile Include="Models\List.cs" />
<Compile Include="Models\PagedCollection.cs" />
<Compile Include="Models\Segment.cs" />
<Compile Include="Models\Subscriber.cs" />
<Compile Include="Models\Template.cs" />
<Compile Include="Properties\AssemblyInfo.cs" />
<Compile Include="Models\Result.cs" />
</ItemGroup>
Expand Down

0 comments on commit f50a19c

Please sign in to comment.