Skip to content

Instantly share code, notes, and snippets.

@jamesmanning
Created June 5, 2012 15:42
Show Gist options
  • Save jamesmanning/2875820 to your computer and use it in GitHub Desktop.
Save jamesmanning/2875820 to your computer and use it in GitHub Desktop.
linqpad script (needs reference to Newtonsoft.Json) for calling premailer API - see http://premailer.dialect.ca/api
void Main()
{
var webClient = new WebClient();
var requestParameters = new NameValueCollection()
{
{ "url", "http://www.hondaelcerritonews.com/news/2012/MayNewsletter/?view=Email" },
{ "preserve_styles", "false" },
{ "remove_ids", "true" },
{ "remove_classes", "true" },
{ "remove_comments", "true" },
};
var resultBytes = webClient.UploadValues("http://premailer.dialect.ca/api/0.1/documents",
requestParameters);
var resultString = Encoding.UTF8.GetString(resultBytes);
var result = Newtonsoft.Json.JsonConvert.DeserializeObject<RootObject>(resultString);
result.Dump();
webClient.DownloadFile(result.documents.html, @"C:\temp\premailer\apiresults\lastcall.html");
webClient.DownloadFile(result.documents.txt, @"C:\temp\premailer\apiresults\lastcall.txt");
}
// Define other methods and classes here
public class Options
{
public string adapter { get; set; }
public bool preserve_styles { get; set; }
public bool remove_ids { get; set; }
public bool remove_classes { get; set; }
public bool remove_comments { get; set; }
}
public class Documents
{
public string html { get; set; }
public string txt { get; set; }
}
public class RootObject
{
public string version { get; set; }
public int status { get; set; }
public string message { get; set; }
public Options options { get; set; }
public Documents documents { get; set; }
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment