/// <summary>
        /// Add contact list items to list
        /// </summary>
        /// <param name="request">request object with contacts to add</param>
        /// <exception cref="BadRequestException">          in case HTTP response code is 400 - Bad request, the request was formatted improperly.</exception>
        /// <exception cref="UnauthorizedException">        in case HTTP response code is 401 - Unauthorized, API Key missing or invalid.</exception>
        /// <exception cref="AccessForbiddenException">     in case HTTP response code is 403 - Forbidden, insufficient permissions.</exception>
        /// <exception cref="ResourceNotFoundException">    in case HTTP response code is 404 - NOT FOUND, the resource requested does not exist.</exception>
        /// <exception cref="InternalServerErrorException"> in case HTTP response code is 500 - Internal Server Error.</exception>
        /// <exception cref="CallfireApiException">         in case HTTP response code is something different from codes listed above.</exception>
        /// <exception cref="CallfireClientException">      in case error has occurred in client.</exception>
        public void AddListItems <T>(AddContactListContactsRequest <T> request)
        {
            Validate.NotBlank(request.ContactListId.ToString(), "request.contactListId cannot be null");
            string path = LISTS_ITEMS_PATH.ReplaceFirst(ClientConstants.PLACEHOLDER, request.ContactListId.ToString());

            Client.Post <object>(path, request);
        }
예제 #2
0
        public void TestAddContactsToContactListById()
        {
            string requestJson = GetJsonPayload("/contacts/contactsApi/response/addContactsToContactList.json");
            var    restRequest = MockRestResponse(requestJson);

            Contact c1 = new Contact {
                HomePhone = "123456"
            };
            Contact c2 = new Contact {
                HomePhone = "123457"
            };

            AddContactListContactsRequest <Contact> request = new AddContactListContactsRequest <Contact>
            {
                ContactNumbersField = "homePhone",
                ContactListId       = TEST_LONG,
                Contacts            = new List <Contact> {
                    c1, c2
                },
                UseCustomFields = true
            };

            Client.ContactListsApi.AddListItems(request);

            var requestBodyParam = restRequest.Value.Parameters.FirstOrDefault(p => p.Type == ParameterType.RequestBody);

            Assert.AreEqual(Serializer.Serialize(requestBodyParam.Value), requestJson);
            Assert.AreEqual(Method.POST, restRequest.Value.Method);
            Assert.That(restRequest.Value.Resource, Does.Contain("/" + TEST_LONG));
        }
        public void TestContactListItemsCRUD()
        {
            Contact c1 = new Contact {
                FirstName = "name1", HomePhone = "12345678901"
            };
            Contact c2 = new Contact {
                FirstName = "name2", HomePhone = "12345678902"
            };
            CreateContactListRequest <Contact> request = new CreateContactListRequest <Contact>
            {
                Contacts = new List <Contact> {
                    c1, c2
                },
                Name            = "listFromContacts",
                UseCustomFields = true
            };
            ResourceId id = Client.ContactListsApi.Create(request);

            AddContactListContactsRequest <string> addItemsRequest = new AddContactListContactsRequest <string>
            {
                ContactListId = id.Id,
                Contacts      = new List <string> {
                    "12345543211"
                },
                UseCustomFields = true
            };

            Client.ContactListsApi.AddListItems(addItemsRequest);

            GetByIdRequest getItemsRequest = new GetByIdRequest {
                Id = id.Id
            };
            Page <Contact>  contactListItems = Client.ContactListsApi.GetListItems(getItemsRequest);
            IList <Contact> items            = contactListItems.Items;

            Assert.AreEqual(3, items.Count);

            Client.ContactListsApi.RemoveListItem(id.Id, (long)items[0].Id);
            System.Threading.Thread.Sleep(5000);
            contactListItems = Client.ContactListsApi.GetListItems(getItemsRequest);
            items            = contactListItems.Items;
            Assert.AreEqual(2, items.Count);

            Client.ContactListsApi.RemoveListItems(id.Id, new List <long> {
                (long)items[0].Id, (long)items[1].Id
            });
            System.Threading.Thread.Sleep(5000);
            contactListItems = Client.ContactListsApi.GetListItems(getItemsRequest);
            Assert.True(contactListItems.Items.Count == 0);
            Assert.AreEqual(0, contactListItems.TotalCount);

            Client.ContactListsApi.Delete(id.Id);
        }
예제 #4
0
    public static void Main(string[] args)
    {
        var client = new CallfireClient("api_login", "api_password");

        var request1 = new AddContactListContactsRequest <Contact>
        {
            Contacts = new List <Contact>
            {
                new Contact
                {
                    FirstName = "Alice",
                    LastName  = "Moore",
                    HomePhone = "12135551126"
                },
                new Contact
                {
                    FirstName  = "Bob",
                    LastName   = "Smith",
                    HomePhone  = "12135551127",
                    Properties = new Dictionary <string, string>
                    {
                        { "age", "30" }
                    }
                }
            },
            ContactListId = 45006708003
        };

        client.ContactListsApi.AddListItems(request1);

        var request2 = new AddContactListContactsRequest <string>
        {
            Contacts = new List <string> {
                "12132212384", "12136612355", "12133312300"
            },
            ContactNumbersField = "workPhone",
            ContactListId       = 45006708003
        };

        client.ContactListsApi.AddListItems(request2);

        var request3 = new AddContactListContactsRequest <long>
        {
            Contacts = new List <long> {
                800634185003, 800734186003, 800834187003, 800984185003
            },
            ContactListId = 45006708003
        };

        client.ContactListsApi.AddListItems(request3);
    }
예제 #5
0
        public void TestDynamicPropertiesSerializationWithOtherProps()
        {
            AddContactListContactsRequest <long> requestObjects = new AddContactListContactsRequest <long>
            {
                ContactNumbersField = "field",
                ContactListId       = 5,
                Contacts            = new List <long> {
                    1, 2
                }
            };

            String serialized = Serializer.Serialize(requestObjects);

            Assert.That(serialized, Does.Contain("\"contactIds\":"));
            Assert.That(serialized, Does.Contain("\"contactNumbersField\":\"field\""));
        }
        public void TestDynamicPropertiesSerializationWithOtherProps()
        {
            AddContactListContactsRequest<long> requestObjects = new AddContactListContactsRequest<long>
            {
                ContactNumbersField = "field",
                ContactListId = 5,
                Contacts = new List<long> { 1, 2 }
            };

            String serialized = Serializer.Serialize(requestObjects);
            Assert.That(serialized, Is.StringContaining("\"contactIds\":"));
            Assert.That(serialized, Is.StringContaining("\"contactNumbersField\":\"field\""));
        }
        public void TestAddContactsToContactListById()
        {
            string expectedJson = GetJsonPayload("/contacts/contactsApi/response/addContactsToContactList.json");
            var restRequest = MockRestResponse(expectedJson);

            Contact c1 = new Contact { HomePhone = "123456" };
            Contact c2 = new Contact { HomePhone = "123457" };

            AddContactListContactsRequest<Contact> request = new AddContactListContactsRequest<Contact>
            {
                ContactNumbersField = "homePhone",
                ContactListId = TEST_LONG,
                Contacts = new List<Contact> { c1, c2 }
            };

            Client.ContactListsApi.AddListItems(request);

            var requestBodyParam = restRequest.Value.Parameters.FirstOrDefault(p => p.Type == ParameterType.RequestBody);
            Assert.AreEqual(requestBodyParam.Value, expectedJson);
            Assert.AreEqual(Method.POST, restRequest.Value.Method);
            Assert.That(restRequest.Value.Resource, Is.StringContaining("/" + TEST_LONG));
        }
        public void TestContactListItemsCRUD()
        {
            Contact c1 = new Contact { FirstName = "name1", HomePhone = "12345678901" };
            Contact c2 = new Contact { FirstName = "name2", HomePhone = "12345678902" };
            CreateContactListRequest<Contact> request = new CreateContactListRequest<Contact>
            {
                Contacts = new List<Contact> { c1, c2 },
                Name = "listFromContacts"
            };
            ResourceId id = Client.ContactListsApi.Create(request);

            AddContactListContactsRequest<string> addItemsRequest = new AddContactListContactsRequest<string>
            {
                ContactListId = id.Id,
                Contacts = new List<string> { "12345543211" }
            };
            Client.ContactListsApi.AddListItems(addItemsRequest);

            GetByIdRequest getItemsRequest = new GetByIdRequest { Id = id.Id };
            Page<Contact> contactListItems = Client.ContactListsApi.GetListItems(getItemsRequest);
            IList<Contact> items = contactListItems.Items;
            Assert.AreEqual(3, items.Count);

            Client.ContactListsApi.RemoveListItem(id.Id, (long)items[0].Id);
            contactListItems = Client.ContactListsApi.GetListItems(getItemsRequest);
            items = contactListItems.Items;
            Assert.AreEqual(2, items.Count);

            Client.ContactListsApi.RemoveListItems(id.Id, new List<long> { (long)items[0].Id, (long)items[1].Id });
            contactListItems = Client.ContactListsApi.GetListItems(getItemsRequest);
            Assert.True(contactListItems.Items.Count == 0);
            Assert.AreEqual(0, contactListItems.TotalCount);

            Client.ContactListsApi.Delete(id.Id);
        }