Exemple #1
0
        public void CreatingModelAllowsItToBeRetrieved()
        {
            var modelCount = 0;

            testObj.Create <DummyModel>();
            foreach (var model in testObj.Get <DummyModel>())
            {
                modelCount++;
            }
            Assert.AreEqual(1, modelCount);
        }
Exemple #2
0
        /// <summary>
        /// creates a new deal in hubspot
        /// </summary>
        /// <typeparam name="T">type of deal to create</typeparam>
        /// <param name="dealdata">data of deal to create</param>
        /// <returns>created deal</returns>
        public async Task <T> Create <T>(T dealdata)
            where T : HubSpotDeal
        {
            EntityModel model = registry.Get(typeof(T));

            JObject request = new JObject {
                ["associations"] = new JObject {
                    ["associatedCompanyIds"] = new JArray(dealdata.Companies ?? new long[0]),
                    ["associatedVids"]       = new JArray(dealdata.Contacts ?? new long[0])
                }
            };

            JArray properties = new JArray();

            foreach (KeyValuePair <string, PropertyInfo> property in model.Properties)
            {
                properties.Add(new JObject {
                    ["name"]  = property.Key,
                    ["value"] = Convert.ToString(property.Value.GetValue(dealdata), CultureInfo.InvariantCulture)
                });
            }

            request["properties"] = properties;

            JObject response = await rest.Post <JObject>("deals/v1/deal", request);

            return(ToDeal <T>(response, model));
        }
        /// <inheritdoc />
        public async Task <T> Create <T>(T ticket)
            where T : HubspotTicket
        {
            EntityModel ticketmodel = models.Get(typeof(T));

            JArray properties = new JArray();

            foreach (KeyValuePair <string, PropertyInfo> property in ticketmodel.Properties)
            {
                properties.Add(new JObject
                {
                    ["name"]  = property.Key,
                    ["value"] = new JValue(property.Value.GetValue(ticket))
                });
            }

            JObject response = await restclient.Post <JObject>("crm-objects/v1/objects/tickets", properties);

            return(response.ToEntity <T>(ticketmodel));
        }
        /// <summary>
        /// creates a new company in hubspot
        /// </summary>
        /// <typeparam name="T">type of company</typeparam>
        /// <param name="company">company data to create</param>
        /// <returns>created entity</returns>
        public async Task <T> Create <T>(T company)
            where T : HubSpotCompany
        {
            EntityModel model = registry.Get(typeof(T));

            JObject request    = new JObject();
            JArray  properties = new JArray();

            foreach (KeyValuePair <string, PropertyInfo> property in model.Properties)
            {
                properties.Add(new JObject {
                    ["name"]  = property.Key,
                    ["value"] = property.Value.GetValue(company)?.ToString()
                });
            }

            request["properties"] = properties;

            JObject response = await rest.Post("companies/v2/companies", request);

            return(ToCompany <T>(response, model));
        }
        public void TestNamedAndIgnoredProerties(Type type)
        {
            var modelRegistry = new ModelRegistry();
            var properties    = modelRegistry.Get(type);

            var name2 = properties.GetMapping("Name1");

            Assert.True(name2 == "name2");

            var nameA = properties.GetMapping("NameA");

            Assert.True(nameA == "namea");

            var ignore = properties.GetMapping("Ignore");

            Assert.Null(ignore);
        }
Exemple #6
0
        /// <summary>
        /// creates or updates a contact
        /// </summary>
        /// <typeparam name="T">type of contact model</typeparam>
        /// <param name="email">e-mail of contact to create or update</param>
        /// <param name="contact">contact data to create or update</param>
        /// <returns></returns>
        public async Task <long> CreateOrUpdate <T>(string email, T contact)
            where T : HubSpotContact
        {
            EntityModel model = models.Get(typeof(T));

            JObject request = new JObject();

            request["properties"] = GetProperties(contact, model);

            JObject response = await rest.Post <JObject>($"contacts/v1/contact/createOrUpdate/email/{email}", request);

            return(response.Value <long>("vid"));
        }