Skip to content

Instantly share code, notes, and snippets.

@Corstiaan84
Last active August 29, 2015 14:24
Show Gist options
  • Save Corstiaan84/96336c8be29cdbde7c8f to your computer and use it in GitHub Desktop.
Save Corstiaan84/96336c8be29cdbde7c8f to your computer and use it in GitHub Desktop.
using System;
using System.Collections.Generic;
using System.Linq;
using System.Net;
using System.Text;
using System.Threading.Tasks;
using RestSharp;
namespace Fluxmatix.Authentication
{
public class EmailOctopusUserEmailDataExporter : IUserEmailDataExporter
{
public static string ApiKey { get; set; }
public void Export(IUser user, object listIdentifier)
{
var listId = (string)listIdentifier;
var rest = new RestClient("https://emailoctopus.com/api/1/");
var req = new RestRequest(string.Format("lists/{0}/members", listId));
var data = new EmailOctopusRequestData() {
api_key = ApiKey,
email_address = user.Email,
first_name = user.Username,
last_name = "",
subscribed = true
};
req.AddBody(data);
req.Method = Method.POST;
var response = rest.Execute<EmailOctopusReponseData>(req);
}
}
public class EmailOctopusRequestData
{
public string api_key { get; set; }
public string email_address { get; set; }
public string first_name { get; set; }
public string last_name { get; set; }
public bool subscribed { get; set; }
}
public class EmailOctopusReponseData
{
public Member member { get; set; }
}
public class Member
{
public string id { get; set; }
public string email_address { get; set; }
public string first_name { get; set; }
public string last_name { get; set; }
public bool subscribed { get; set; }
public DateTime created_at { get; set; }
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment