Ejemplo n.º 1
0
        public void UpdateLastLoginDate(Guid referenceID)
        {
            string url = "/database/contacts/" + referenceID;

            var collection = new WebHeaderCollection();

            collection.Add("Authorization", string.Format("Engage {0}", APIToken));

            var obj = new {
                ReferenceID = referenceID,
                Data        = new object[] {
                    new {
                        FieldID = GetFieldID("Tradesmart Last Logged In Date"),
                        Name    = "Tradesmart Last Logged In Date",
                        Value   = DateTime.Now.FmtDate()
                    }
                },
                ItemXml    = (string)null,
                Source     = (string)null,
                FormAction = (string)null
            };

            try {
                var result = Http.Request(Http.PUT, "https://api.ubiquity.co.nz" + url, new JsonSerializer().Serialize(obj), collection);
            } catch (Exception ex) {  }
        }
Ejemplo n.º 2
0
        public bool ReferenceIDIsValid(string refID)
        {
            const string apiBaseUrl = "https://api.ubiquity.co.nz";
            var          url        = string.Format("{0}/database/contacts/{1}?format=json&apiToken={2}", apiBaseUrl, refID, APIToken);

            try {
                Http.Get(url);
                return(true);
            } catch {
                // Will throw an exception when the refID couldn't be found
            }

            return(false);
        }
Ejemplo n.º 3
0
        public dynamic GetPersonByEmail(string email)
        {
            //Build a new Base Rest Client
            APIToken = Util.GetNamedSetting("EngageAPIToken");
            var collection = new WebHeaderCollection();

            collection.Add("Authorization", string.Format("Engage {0}", APIToken));
            string filterString = "{\"filterString\": \"[" + GetFieldID("Email") + "] eq '" + email + "'\"}";
            var    content      = Http.Post("https://api.ubiquity.co.nz/database/contacts/query/", filterString, "Authorization", string.Format("Engage {0}", APIToken));

            var     json = content;
            dynamic obj  = JsonHelper.Parse(json);

            return(obj.totalReturned > 0 ? obj.selectedContacts[0] : null);
        }
Ejemplo n.º 4
0
        public void Unsubscribe(string refID)
        {
            //get member ref
            string url = "/database/contacts/" + refID;

            var collection = new WebHeaderCollection();

            collection.Add("Authorization", string.Format("Engage {0}", APIToken));
            var obj = new {
                ReferenceID = refID,
                Data        = new object[] {
                    new {
                        FieldID = GetFieldID("Opted Out"),
                        Name    = "Opted Out",
                        Value   = "true"
                    },
                    new {
                        FieldID = GetFieldID("Email Permission"),
                        Name    = "Email Permission",
                        Value   = "false"
                    }
                },
                ItemXml    = (string)null,
                Source     = (string)null,
                FormAction = (string)null
            };

            try {
                var response = Http.Request(Http.PUT, "https://api.ubiquity.co.nz" + url, new JsonSerializer().Serialize(obj), collection);
            } catch (Exception e) {
                var email = new ElectronicMail();
                email.Subject = "Engage Error - Unsubscribing member " + refID;
                string body = "";
                body             += @"
	ReferenceID: "     + refID + @"
	Action Taken: Unsubscribing"     + @"
	Errors as follows: "     + e.Message + @"
	Data:
	"     + new JsonSerializer().Serialize(obj);
                email.BodyPlain   = body;
                email.ToAddress   = "*****@*****.**";
                email.FromAddress = SendEMail.EmailFromAddress;
                email.FromName    = SendEMail.EmailFromName;
                email.Send(false);
            }
        }
Ejemplo n.º 5
0
        public List <dynamic> GetEngageContacts()
        {
            var engageContacts = new List <dynamic>();

            const string apiBaseUrl = "https://api.ubiquity.co.nz";
            var          url        = string.Format("{0}/database/contacts?format=json&apiToken={1}", apiBaseUrl, APIToken);
            var          json       = Http.Get(url);

            dynamic obj = JsonHelper.Parse(json);

            // Load all contacts from Engage
            while (obj.totalReturned > 0)
            {
                foreach (var selectedContact in obj.selectedContacts)
                {
                    engageContacts.Add(selectedContact);
                }
                json = Http.Get(url + "&skip=" + obj.next);
                obj  = JsonHelper.Parse(json);
            }

            return(engageContacts);
        }
Ejemplo n.º 6
0
        public dynamic GetEngageModifiedContacts(DateTime since, int limit)
        {
            var engageContacts = new List <dynamic>();

            //Build a new Base Rest Client
            var collection = new WebHeaderCollection();

            collection.Add("Authorization", string.Format("Engage {0}", APIToken));
            const string url = "https://api.ubiquity.co.nz/database/contacts/query/";

            var    numberOfRecords = Math.Min(limit, 150);
            string filterString    = "{{\"filterString\": \"[" + GetFieldID("Last Modified") + "] ge '" + Fmt.DateTime(since, Fmt.DateTimePrecision.Second) + "'\", \"sortFields\": [{{ \"column\": \"" + GetFieldID("Last Modified") + "\", \"direction\": \"Ascending\"}}], \"numberOfRecords\": " + numberOfRecords + ", \"startRecord\": {0}}}";
            var    obj             = JsonHelper.Parse("{\"next\": 0}");

            do
            {
                var content = Http.Post(url, string.Format(filterString, obj.next), "Authorization", string.Format("Engage {0}", APIToken));
                obj = JsonHelper.Parse(content);

                if (obj.selectedContacts.Length == 0)
                {
                    break;
                }

                foreach (var selectedContact in obj.selectedContacts)
                {
                    engageContacts.Add(selectedContact);
                    if (engageContacts.Count >= limit)
                    {
                        break;
                    }
                }
            } while (obj.next < obj.totalContacts && engageContacts.Count < limit);

            return(engageContacts);
        }