Exemplo n.º 1
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);
        }
Exemplo n.º 2
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);
        }