/// <summary>
        /// Create a new Contact Segment
        /// </summary>
        /// <param name="segment"></param>
        /// <returns>The contact segment as returned from the API</returns>
        public ContactSegment CreateSegment(ContactSegment segment)
        {
            RestRequest request = new RestRequest(Method.POST)
                                      {
                                          RequestFormat = DataFormat.Json,
                                          Resource = "/assets/contact/segment"
                                      };
            request.AddBody(segment);

            IRestResponse<ContactSegment> response = _client.Execute<ContactSegment>(request);
            return response.Data;
        }
Esempio n. 2
0
        /// <summary>
        /// Update an existnig Contact Segment
        /// </summary>
        /// <param name="contactSegment"></param>
        /// <returns>The contactSegment as returned from the API</returns>
        public ContactSegment UpdateContactSegment(ContactSegment contactSegment)
        {
            RestRequest request = new RestRequest(Method.PUT)
            {
                Resource      = "/assets/contact/segment" + contactSegment.id,
                RequestFormat = DataFormat.Json
            };

            request.AddBody(contactSegment);

            IRestResponse <ContactSegment> response = _client.Execute <ContactSegment>(request);

            return(response.Data);
        }
Esempio n. 3
0
        /// <summary>
        /// Create a new Contact Segment
        /// </summary>
        /// <param name="segment"></param>
        /// <returns>The contact segment as returned from the API</returns>
        public ContactSegment CreateSegment(ContactSegment segment)
        {
            RestRequest request = new RestRequest(Method.POST)
            {
                RequestFormat = DataFormat.Json,
                Resource      = "/assets/contact/segment"
            };

            request.AddBody(segment);

            IRestResponse <ContactSegment> response = _client.Execute <ContactSegment>(request);

            return(response.Data);
        }
        public void CreateSegmentTest()
        {
            // Activity Restriction (number of emails)
            var activityRestriction = new NumericValueCondition
                                          {
                                              id = -500020,
                                              @operator = "equal",
                                              type = "NumericValueCondition",
                                              value = 1
                                          };

            // Time Restriction (sent within the last)
            var timeRestriction = new DateValueCondition
                                      {
                                          id = -21,
                                          @operator = "withinLast",
                                          type = "DateValueCondition",
                                          value = new RelativeDate
                                                      {
                                                          id = "-500021",
                                                          offset = 1,
                                                          timePeriod = "week",
                                                          type = "RelativeDate"
                                                      }
                                      };

            // Define a Criteria for Contacts that received an Email in the last week
            // includes restrictions defined in the previous step
            EmailSentCriterion emailSentCriterion = new EmailSentCriterion
                                                        {
                                                            id = -500014,
                                                            type = "EmailSentCriterion",
                                                            activityRestriction = activityRestriction,
                                                            timeRestriction = timeRestriction
                                                        };

            // The endpoint expects a list, but we'll only include 1 criteria
            List<ContactSegmentSample.Models.Criteria.Criterion> criteria = new List<ContactSegmentSample.Models.Criteria.Criterion>();
            criteria.Add(emailSentCriterion);

            // Next we'll create a Contact Filter
            ContactFilter filter = new ContactFilter
                                       {
                                           criteria = criteria,
                                           id = -500012,
                                           name = "Filter Sample",
                                           scope = "local",
                                           statement = "-500014",
                                           type = "ContactFilter"
                                       };

            ContactFilterSegmentElement filterElement = new ContactFilterSegmentElement()
                                                            {
                                                                filter = filter,
                                                                id = -500013,
                                                                isIncluded = true,
                                                                type = "ContactFilterSegmentElement"
                                                            };

            // The Segment expects one or more Filters, we'll include 1
            List<SegmentElement> filterElements = new List<SegmentElement>();
            filterElements.Add(filterElement);

            ContactSegment segment = new ContactSegment
                                         {
                                             detph = "complete",
                                             id = -500002,
                                             elements = filterElements,
                                             name = "sample segment",
                                             type = "ContactSegment"
                                         };

            var content = _segmentHelper.CreateSegment(segment);

            Assert.IsNotNull(content);
        }
        public void CreateSegmentTest()
        {
            // Activity Restriction (number of emails)
            var activityRestriction = new NumericValueCondition
            {
                id        = -500020,
                @operator = "equal",
                type      = "NumericValueCondition",
                value     = 1
            };

            // Time Restriction (sent within the last)
            var timeRestriction = new DateValueCondition
            {
                id        = -21,
                @operator = "withinLast",
                type      = "DateValueCondition",
                value     = new RelativeDate
                {
                    id         = "-500021",
                    offset     = 1,
                    timePeriod = "week",
                    type       = "RelativeDate"
                }
            };

            // Define a Criteria for Contacts that received an Email in the last week
            // includes restrictions defined in the previous step
            EmailSentCriterion emailSentCriterion = new EmailSentCriterion
            {
                id   = -500014,
                type = "EmailSentCriterion",
                activityRestriction = activityRestriction,
                timeRestriction     = timeRestriction
            };

            // The endpoint expects a list, but we'll only include 1 criteria
            List <ContactSegmentSample.Models.Criteria.Criterion> criteria = new List <ContactSegmentSample.Models.Criteria.Criterion>();

            criteria.Add(emailSentCriterion);

            // Next we'll create a Contact Filter
            ContactFilter filter = new ContactFilter
            {
                criteria  = criteria,
                id        = -500012,
                name      = "Filter Sample",
                scope     = "local",
                statement = "-500014",
                type      = "ContactFilter"
            };

            ContactFilterSegmentElement filterElement = new ContactFilterSegmentElement()
            {
                filter     = filter,
                id         = -500013,
                isIncluded = true,
                type       = "ContactFilterSegmentElement"
            };

            // The Segment expects one or more Filters, we'll include 1
            List <SegmentElement> filterElements = new List <SegmentElement>();

            filterElements.Add(filterElement);

            ContactSegment segment = new ContactSegment
            {
                detph    = "complete",
                id       = -500002,
                elements = filterElements,
                name     = "sample segment",
                type     = "ContactSegment"
            };

            var content = _segmentHelper.CreateSegment(segment);

            Assert.IsNotNull(content);
        }
        /// <summary>
        /// Update an existnig Contact Segment
        /// </summary>
        /// <param name="contactSegment"></param>
        /// <returns>The contactSegment as returned from the API</returns>
        public ContactSegment UpdateContactSegment(ContactSegment contactSegment)
        {
            RestRequest request = new RestRequest(Method.PUT)
            {
                Resource = "/assets/contact/segment" + contactSegment.id,
                RequestFormat = DataFormat.Json
            };
            request.AddBody(contactSegment);

            IRestResponse<ContactSegment> response = _client.Execute<ContactSegment>(request);

            return response.Data;
        }