Exemplo n.º 1
0
        public static IList<InterestGroup> GetInterestGroups(string listId, ApiKey apiKey = null)
        {
            apiKey = apiKey ?? new ApiKey(); // load from config

            var data = new Dictionary<string, object>();
            data["output"] = "json";
            data["method"] = "listInterestGroupings";
            data["apikey"] = apiKey.ToString();
            data["id"] = listId;

            DataContractJsonSerializer serializer = new DataContractJsonSerializer(typeof(IList<InterestGroup>));

            using (MemoryStream ms = new MemoryStream(Encoding.Unicode.GetBytes(HttpUtils.Send(apiKey.Url, data)))) {
                return serializer.ReadObject(ms) as IList<InterestGroup>;
            }

            //return JsonConvert.DeserializeObject<IList<InterestGroup>>(HttpUtils.Send(apiKey.Url, data));
        }
Exemplo n.º 2
0
        public static MailingList GetByProperty(string propertyName, object propertyValue, ApiKey apiKey = null)
        {
            apiKey = apiKey ?? new ApiKey(); // load from config

            var data = new Dictionary<string, object>();
            data["output"] = "json";
            data["method"] = "lists";
            data["apikey"] = apiKey.ToString();
            data["filters["+propertyName+"]"] = propertyValue;

            DataContractJsonSerializer serializer = new DataContractJsonSerializer(typeof(MailingListCollection));

            using (MemoryStream ms = new MemoryStream(Encoding.Unicode.GetBytes(HttpUtils.Send(apiKey.Url, data)))) {
                var lists = serializer.ReadObject(ms) as MailingListCollection;
                //var lists = JsonConvert.DeserializeObject<MailingListCollection>(HttpUtils.Send(apiKey.Url, data));
                if (lists != null && lists.MailingLists.Count > 0)
                    return lists.MailingLists[0];
            }

            return null;
        }
Exemplo n.º 3
0
        public static void Subscribe(string listId, Subscriber subscriber, ApiKey apiKey = null)
        {
            apiKey = apiKey ?? new ApiKey(); // load from config

            var data = new Dictionary<string, object>();
            data["output"] = "json";
            data["method"] = "listSubscribe";
            data["apikey"] = apiKey.ToString();
            data["id"] = listId;
            data["email_address"] = subscriber.Email;
            data["double_optin"] = "false";

            if (subscriber.UpdateIfExists)
                data["update_existing"] = "true";

            if (subscriber.AppendInterests)
                data["replace_interests"] = "false";

            if (!string.IsNullOrEmpty(subscriber.FirstName))
                data["merge_vars[FNAME]"] = subscriber.FirstName;

            if (!string.IsNullOrEmpty(subscriber.LastName))
                data["merge_vars[LNAME]"] = subscriber.LastName;

            // merge other fields
            foreach (var key in subscriber.Data.Keys)
                data["merge_vars[" + key + "]"] = subscriber.Data[key];

            if (subscriber.InterestGroups.Count > 0) {
                for (var igroup = 0; igroup < subscriber.InterestGroups.Count; igroup++) {
                    data["merge_vars[GROUPINGS][" + igroup + "][name]"] = subscriber.InterestGroups[igroup].GroupName;
                    data["merge_vars[GROUPINGS][" + igroup + "][groups]"] = string.Join(",", subscriber.InterestGroups[igroup].Interests);
                }
                
            }

            HttpUtils.Send(apiKey.Url, data);
        }
Exemplo n.º 4
0
 public static MailingList GetById(string id, ApiKey apiKey = null)
 {
     return GetByProperty("list_id", id, apiKey);
 }
Exemplo n.º 5
0
 public static MailingList GetByName(string name, ApiKey apiKey = null)
 {
     return GetByProperty("list_name", name, apiKey);
 }