<commit_before>﻿using System.Reflection;
using Microsoft.Extensions.Logging;
using Skarp.HubSpotClient.Interfaces;

namespace Skarp.HubSpotClient.Requests
{
    public class RequestDataConverter
    {
        private readonly ILogger<RequestDataConverter> _logger;

        public RequestDataConverter(
            ILogger<RequestDataConverter> logger)
        {
            _logger = logger;
        }

        /// <summary>
        /// Converts the given <paramref name="entity"/> to a hubspot data entity.
        /// </summary>
        /// <param name="entity">The entity.</param>
        /// <returns></returns>
        public HubspotDataEntity ToHubspotDataEntity(IHubSpotEntity entity)
        {
            _logger.LogDebug("Convert ToHubspotDataEntity");
            var mapped = new HubspotDataEntity();
            bool isv2Route = entity.RouteBasePath.Contains("/v2");
            _logger.LogDebug("isv2route: {0}", isv2Route);

            var allProps = entity.GetType().GetProperties();
            _logger.LogDebug("Have {0} props to map", allProps.Length);

            foreach (var prop in allProps)
            {
                _logger.LogDebug("Mapping prop: '{0}'", prop.Name);
                if (prop.Name.Equals("RouteBasePath")) continue;

                var propValue = prop.GetValue(entity);
                var item = new HubspotDataEntityProp
                {
                    Property = prop.Name,
                    Value = propValue?.ToString()
                };

                if (isv2Route)
                {
                    item.Property = null;
                    item.Name = prop.Name;
                }

                mapped.Properties.Add(item);
            }

            _logger.LogDebug("Mapping complete, returning data");
            return mapped;
        }
    }
}
<commit_msg>Don't add props as mapped if their value is null<commit_after>﻿using System.Reflection;
using Microsoft.Extensions.Logging;
using Skarp.HubSpotClient.Interfaces;

namespace Skarp.HubSpotClient.Requests
{
    public class RequestDataConverter
    {
        private readonly ILogger<RequestDataConverter> _logger;

        public RequestDataConverter(
            ILogger<RequestDataConverter> logger)
        {
            _logger = logger;
        }

        /// <summary>
        /// Converts the given <paramref name="entity"/> to a hubspot data entity.
        /// </summary>
        /// <param name="entity">The entity.</param>
        /// <returns></returns>
        public HubspotDataEntity ToHubspotDataEntity(IHubSpotEntity entity)
        {
            _logger.LogDebug("Convert ToHubspotDataEntity");
            var mapped = new HubspotDataEntity();
            bool isv2Route = entity.RouteBasePath.Contains("/v2");
            _logger.LogDebug("isv2route: {0}", isv2Route);

            var allProps = entity.GetType().GetProperties();
            _logger.LogDebug("Have {0} props to map", allProps.Length);

            foreach (var prop in allProps)
            {
                _logger.LogDebug("Mapping prop: '{0}'", prop.Name);
                if (prop.Name.Equals("RouteBasePath")) continue;

                var propValue = prop.GetValue(entity);
                var item = new HubspotDataEntityProp
                {
                    Property = prop.Name,
                    Value = propValue?.ToString()
                };

                if (isv2Route)
                {
                    item.Property = null;
                    item.Name = prop.Name;
                }
                if(item.Value == null) continue;

                mapped.Properties.Add(item);
            }

            _logger.LogDebug("Mapping complete, returning data");
            return mapped;
        }
    }
}

{'fraction_non_alphanumeric': 0.10175345377258235, 'fraction_numerical': 0.004250797024442083, 'mean_word_length': 1.6683203401842666, 'pattern_counts': {'":': 0, '<': 21, '<?xml version=': 0, '>': 21, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '7303454', 'n_tokens_mistral': 975, 'n_tokens_neox': 930, 'n_words': 208}