Skip to content

Commit

Permalink
Rest of Segment methods
Browse files Browse the repository at this point in the history
  • Loading branch information
Jason Hickey committed Nov 18, 2010
1 parent 4bccd14 commit 3155366
Show file tree
Hide file tree
Showing 3 changed files with 45 additions and 8 deletions.
5 changes: 3 additions & 2 deletions ConsoleRunner/Program.cs
Expand Up @@ -15,12 +15,13 @@ class Program
static void Main(string[] args)
{
foreach (BasicSegment segment in new Client("011ebcadaeb71e9a").Segments())
Console.WriteLine(new Segment(segment.SegmentID).Details());
Console.WriteLine(new Segment(segment.SegmentID).Details().SegmentID + ":" + new Segment(segment.SegmentID).Details().Title);
SegmentRules rules = new SegmentRules();
rules.Add(new Rule() { Subject = "Email", Clauses = new List<string>() { "EQUALS jasonh" } });
rules.Add(new Rule() { Subject = "EmailAddress", Clauses = new List<string>() { "EQUALS jasonh" } });
var segmentID = Segment.Create("aa76d29949e7f10ab28712617634fd0b", "fucker", rules);
Console.WriteLine(segmentID);

new Segment("894f2b9a6e0ebfcd23076c707a2186a7").AddRule("EmailAddress", new List<string>() { "CONTAINS suckit" });
}
}
}
5 changes: 0 additions & 5 deletions createsend-dotnet.sln
Expand Up @@ -4,11 +4,6 @@ Microsoft Visual Studio Solution File, Format Version 11.00
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "createsend-dotnet", "createsend-dotnet\createsend-dotnet.csproj", "{A498EB72-A24F-4CF3-85DE-3E4EE62DF56F}"
EndProject
Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "Solution Items", "Solution Items", "{23495137-57D3-41AB-AB55-01FD382D9964}"
ProjectSection(SolutionItems) = preProject
createsend-dotnet.vsmdi = createsend-dotnet.vsmdi
Local.testsettings = Local.testsettings
TraceAndTestImpact.testsettings = TraceAndTestImpact.testsettings
EndProjectSection
EndProject
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "ConsoleRunner", "ConsoleRunner\ConsoleRunner.csproj", "{C052F6B7-0146-47A7-AD35-B33FEC526548}"
EndProject
Expand Down
43 changes: 42 additions & 1 deletion createsend-dotnet/Segment.cs
Expand Up @@ -2,6 +2,7 @@
using System.Collections.Generic;
using System.Text;
using Newtonsoft.Json;
using System.Collections.Specialized;

namespace createsend_dotnet
{
Expand All @@ -25,7 +26,10 @@ public static string Create(string listID, string title, SegmentRules rules)
}
catch (CreatesendException ex)
{
ErrorResult<RuleErrorResults> result = JavaScriptConvert.DeserializeObject<ErrorResult<RuleErrorResults>>(ex.ResponseData);
if (!string.IsNullOrEmpty(ex.ResponseData))
{
ErrorResult<RuleErrorResults> result = JavaScriptConvert.DeserializeObject<ErrorResult<RuleErrorResults>>(ex.ResponseData);
}

//TODO : return this result instead of newly created segment id - example code gonna need to show how to handle this
}
Expand All @@ -34,10 +38,47 @@ public static string Create(string listID, string title, SegmentRules rules)
return JavaScriptConvert.DeserializeObject<string>(json);
}

public void Update(string title, SegmentRules rules)
{
HttpHelper.Put(string.Format("/segments/{0}.json", _segmentID), null, JavaScriptConvert.SerializeObject(
new Dictionary<string, object>() { { "Title", title }, { "Rules", rules } })
);
}

public void AddRule(string subject, List<string> clauses)
{
HttpHelper.Post(string.Format("/segments/{0}/rules.json", _segmentID), null, JavaScriptConvert.SerializeObject(
new Dictionary<string, object>() { { "Subject", subject }, { "Clauses", clauses } })
);
}

public PagedCollection<SubscriberDetail> Subscribers(DateTime fromDate, int page, int pageSize, string orderField, string orderDirection)
{
NameValueCollection queryArguments = new NameValueCollection();
queryArguments.Add("date", fromDate.ToString("yyyy-MM-dd HH:mm:ss"));
queryArguments.Add("page", page.ToString());
queryArguments.Add("pagesize", pageSize.ToString());
queryArguments.Add("orderfield", orderField);
queryArguments.Add("orderdirection", orderDirection);

string json = HttpHelper.Get(string.Format("/segments/{0}/active.json", _segmentID), queryArguments);
return JavaScriptConvert.DeserializeObject<PagedCollection<SubscriberDetail>>(json);
}

public SegmentDetail Details()
{
string json = HttpHelper.Get(string.Format("/segments/{0}.json", _segmentID), null);
return JavaScriptConvert.DeserializeObject<SegmentDetail>(json);
}

public void ClearRules()
{
HttpHelper.Delete(string.Format("/segments/{0}/rules.json", _segmentID), null);
}

public void Delete()
{
HttpHelper.Delete(string.Format("/segments/{0}.json", _segmentID), null);
}
}
}

0 comments on commit 3155366

Please sign in to comment.