Created
September 27, 2012 00:56
-
-
Save robertmclaws/3791549 to your computer and use it in GitHub Desktop.
Simple code to convert SendGrid's ridiculous Event API into usable C# objects.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
public ActionResult Index() | |
{ | |
var json = new StreamReader(Request.InputStream).ReadToEnd(); | |
//RWM: The next line turns the faux-array into an actual one. | |
json = string.Format("[{0}]", json.Replace("}" + Environment.NewLine + "{", "},{")); | |
var models = JsonConvert.DeserializeObject<List<SendGridEventModel>>(json); | |
models.ForEach(c => ProcessEvent(c)); | |
return new HttpStatusCodeResult(HttpStatusCode.OK); | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
public class SendGridEventModel | |
{ | |
/// <summary> | |
/// Applies to all message types. | |
/// </summary> | |
public string Category { get; set; } | |
/// <summary> | |
/// Applies to all message types. | |
/// </summary> | |
public string Event { get; set; } | |
/// <summary> | |
/// Applies to all message types. | |
/// </summary> | |
public string Email { get; set; } | |
/// <summary> | |
/// Applies to Deferred and Delivered events. | |
/// </summary> | |
public string Response { get; set; } | |
/// <summary> | |
/// Applies to the Deferred event. | |
/// </summary> | |
public int Attempt { get; set; } | |
/// <summary> | |
/// Applies to the Bounce and Drop events | |
/// </summary> | |
public string Reason { get; set; } | |
/// <summary> | |
/// Applies to the Click event. | |
/// </summary> | |
public string Url { get; set; } | |
/// <summary> | |
/// 3 digit status code. Applies to the Bounce event. | |
/// </summary> | |
public int Status { get; set; } | |
/// <summary> | |
/// Applies to the Bounce event. | |
/// </summary> | |
public string Type { get; set; } | |
/// <summary> | |
/// | |
/// </summary> | |
public Int64 TimeStamp { get; set; } | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment