예제 #1
0
        public static MessageBuildResult Build(
            string token,
            IEnumerable <ObjectProperty> superProperties,
            decimal amount,
            DateTime time,
            object distinctId,
            MixpanelConfig config)
        {
            MessageBuildResult messageBuildResult = PeopleMessageBuilderBase.CreateMessage(
                token,
                superProperties,
                null,
                distinctId,
                config,
                "$append",
                rawValue => throw new InvalidOperationException());

            if (!messageBuildResult.Success)
            {
                return(messageBuildResult);
            }

            messageBuildResult.Message["$append"] = new Dictionary <string, object>(1)
            {
                {
                    "$transactions", new Dictionary <string, object>(2)
                    {
                        { "$time", TimeParser.ParseMixpanelFormat(time).Value },
                        { "$amount", amount }
                    }
                }
            };

            return(messageBuildResult);
        }
        private static MessageBuildResult Build(
            string operation,
            string token,
            IEnumerable <ObjectProperty> superProperties,
            object rawProperties,
            object distinctId,
            MixpanelConfig config)
        {
            MessageCandidate messageCandidate = PeopleMessageBuilderBase.CreateValidMessageCandidate(
                token,
                superProperties,
                rawProperties,
                distinctId,
                config,
                out string messageCandidateErrorMessage);

            if (messageCandidate == null)
            {
                return(MessageBuildResult.CreateFail(messageCandidateErrorMessage));
            }

            var message = new Dictionary <string, object>();
            var set     = new Dictionary <string, object>();

            message[operation] = set;

            // Special properties
            PeopleMessageBuilderBase.RunForValidSpecialProperties(
                messageCandidate,
                (specialPropertyName, isMessageSpecialProperty, value) =>
            {
                if (isMessageSpecialProperty)
                {
                    message[specialPropertyName] = value;
                }
                else
                {
                    set[specialPropertyName] = value;
                }
            });

            // User properties
            PeopleMessageBuilderBase.RunForValidUserProperties(
                messageCandidate,
                rawValue => GenericPropertyParser.Parse(rawValue, allowCollections: true),
                (formattedPropertyName, value) =>
            {
                set[formattedPropertyName] = value;
            });

            return(MessageBuildResult.CreateSuccess(message));
        }
 public static MessageBuildResult Build(
     string token,
     IEnumerable <ObjectProperty> superProperties,
     object rawProperties,
     object distinctId,
     MixpanelConfig config)
 {
     return(PeopleMessageBuilderBase.CreateMessage(
                token,
                superProperties,
                rawProperties,
                distinctId,
                config,
                "$add",
                NumberParser.Parse));
 }
 public static MessageBuildResult Build(
     string token,
     IEnumerable <ObjectProperty> superProperties,
     object rawProperties,
     object distinctId,
     MixpanelConfig config)
 {
     return(PeopleMessageBuilderBase.CreateMessage(
                token,
                superProperties,
                rawProperties,
                distinctId,
                config,
                "$union",
                rawValue => CollectionParser.Parse(rawValue, _ => GenericPropertyParser.Parse(_, allowCollections: false))));
 }
        // Message example:
        // {
        //     "$token": "36ada5b10da39a1347559321baf13063",
        //     "$distinct_id": "13793",
        //     "$unset": [ "Days Overdue" ]
        // }

        public static MessageBuildResult Build(
            string token,
            IEnumerable <ObjectProperty> superProperties,
            IEnumerable <string> propertyNames,
            object distinctId,
            MixpanelConfig config)
        {
            MessageCandidate messageCandidate = PeopleMessageBuilderBase.CreateValidMessageCandidate(
                token,
                superProperties,
                null,
                distinctId,
                config,
                out string messageCandidateErrorMessage);

            if (messageCandidate == null)
            {
                return(MessageBuildResult.CreateFail(messageCandidateErrorMessage));
            }

            var message = new Dictionary <string, object>();

            // Special properties
            PeopleMessageBuilderBase.RunForValidSpecialProperties(
                messageCandidate,
                (specialPropertyName, isMessageSpecialProperty, value) =>
            {
                // Ignore non-message specific special properties as they are not valid in profile update messages
                if (isMessageSpecialProperty)
                {
                    message[specialPropertyName] = value;
                }
            });

            message["$unset"] = propertyNames ?? new string[0];

            return(MessageBuildResult.CreateSuccess(message));
        }
        public static MessageBuildResult Build(
            string token,
            IEnumerable <ObjectProperty> superProperties,
            object distinctId,
            MixpanelConfig config)
        {
            MessageBuildResult messageBuildResult = PeopleMessageBuilderBase.CreateMessage(
                token,
                superProperties,
                null,
                distinctId,
                config,
                "$delete",
                rawValue => throw new InvalidOperationException());

            if (!messageBuildResult.Success)
            {
                return(messageBuildResult);
            }

            messageBuildResult.Message["$delete"] = Empty;
            return(messageBuildResult);
        }