コード例 #1
0
ファイル: DealsApi.cs プロジェクト: microknights/hubspot-api
        /// <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));
        }
コード例 #2
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"));
        }
コード例 #3
0
        public async Task <T> CreateEngagement <T>(HubSpotEngagementResult data)
            where T : HubSpotEngagementResult
        {
            var     requestData = JToken.FromObject(data);
            JObject response    = await rest.Post <JObject>($"/engagements/v1/engagements", requestData);

            return(ToEngagementResult <T>(response));
        }
コード例 #4
0
        /// <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));
        }
コード例 #5
0
        /// <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));
        }