// --- Helpers

        /// <summary>
        /// Gets a ready request containing a POST
        /// </summary>
        /// <returns>The POST request that is already being sent</returns>
        /// <param name="events">Events to send in the post</param>
        protected HttpContent GetPOSTRequest(List <Dictionary <string, object> > events)
        {
            // Add STM to event
            AddSentTimeToEvents(events);

            // Build the event
            SelfDescribingJson sdj = new SelfDescribingJson(Constants.SCHEMA_PAYLOAD_DATA, events);

            // Build the HTTP Content Body
            HttpContent httpContent = new StringContent(sdj.ToString(), Encoding.UTF8, Constants.POST_CONTENT_TYPE);

            return(httpContent);
        }
        // --- Helpers

        /// <summary>
        /// Gets a ready request containing a POST
        /// </summary>
        /// <returns>The POST request that is already being sent</returns>
        /// <param name="events">Events to send in the post</param>
        /// <param name="ids">The row ids</param>
        /// <param name="oversize">If the event list is oversize</param>
        protected UnityHTTP.Request GetPOSTRequest(List <Dictionary <string, object> > events)
        {
            // Add STM to event
            AddSentTimeToEvents(events);

            // Build the event
            SelfDescribingJson sdj = new SelfDescribingJson(Constants.SCHEMA_PAYLOAD_DATA, events);

            byte[]            data        = Utils.StringToBytes(sdj.ToString());
            UnityHTTP.Request httpRequest = new UnityHTTP.Request(UnityHTTP.Enums.RequestType.POST, this.collectorUri, data);
            httpRequest.AddHeader("Content-Type", Constants.POST_CONTENT_TYPE);
            httpRequest.synchronous = this.synchronous;

            return(httpRequest);
        }
예제 #3
0
        public void testInitSDJWithSelfDescribingJson()
        {
            SelfDescribingJson nullSdj = null;
            var sdj = new SelfDescribingJson("iglu:com.snowplowanalytics.snowplow/payload_data/jsonschema/1-0-4", nullSdj);

            Assert.AreEqual(@"{""schema"":""iglu:com.snowplowanalytics.snowplow/payload_data/jsonschema/1-0-4""}", sdj.ToString());

            object dictObj = new Dictionary <string, object>
            {
                { "hello", "world" }
            };
            var notNullSdj = new SelfDescribingJson("iglu:com.snowplowanalytics.snowplow/test_event/jsonschema/1-0-4", dictObj);

            sdj.SetData(notNullSdj);

            Assert.AreEqual(@"{""schema"":""iglu:com.snowplowanalytics.snowplow/payload_data/jsonschema/1-0-4"",""data"":{""schema"":""iglu:com.snowplowanalytics.snowplow/test_event/jsonschema/1-0-4"",""data"":{""hello"":""world""}}}", sdj.ToString());
        }
        public void TestInitWithSdj()
        {
            Dictionary <string, object> dict = new Dictionary <string, object>();

            dict.Add("demo", 5);
            SelfDescribingJson data = new SelfDescribingJson("iglu:acme.com/demo_app/jsonschema/1-0-0", dict);
            SelfDescribingJson sdj  = new SelfDescribingJson("iglu:acme.com/demo/jsonschema/1-0-0", data);

            Assert.NotNull(sdj);
            Assert.AreEqual(126, sdj.GetByteSize());
            CollectionAssert.AreEquivalent(JSON.Deserialize <Dictionary <string, object> >("{\"data\":{\"data\":{\"demo\":5}, \"schema\":\"iglu:acme.com/demo_app/jsonschema/1-0-0\"}, \"schema\":\"iglu:acme.com/demo/jsonschema/1-0-0\"}"), JSON.Deserialize <Dictionary <string, object> >(sdj.ToString()));

            dict.Add("app", "hello");
            data.SetData(dict);
            sdj.SetData(data);

            CollectionAssert.AreEquivalent(JSON.Deserialize <Dictionary <string, object> >("{\"data\":{\"data\":{\"app\":\"hello\", \"demo\":5}, \"schema\":\"iglu:acme.com/demo_app/jsonschema/1-0-0\"}, \"schema\":\"iglu:acme.com/demo/jsonschema/1-0-0\"}"), JSON.Deserialize <Dictionary <string, object> >(sdj.ToString()));
        }
        public void TestInitWithObject()
        {
            Dictionary <string, object> dict = new Dictionary <string, object> ();

            dict.Add("demo", 5);
            SelfDescribingJson sdj = new SelfDescribingJson("iglu:acme.com/demo_app/jsonschema/1-0-0", dict);

            Assert.NotNull(sdj);
            Assert.AreEqual(71, sdj.GetByteSize());
            Assert.AreEqual("{\"data\":{\"demo\":5}, \"schema\":\"iglu:acme.com/demo_app/jsonschema/1-0-0\"}", sdj.ToString());

            sdj.SetSchema("iglu:acme.com/demo_app/jsonschema/1-0-1");

            Assert.AreEqual("{\"data\":{\"demo\":5}, \"schema\":\"iglu:acme.com/demo_app/jsonschema/1-0-1\"}", sdj.ToString());

            dict.Add("app", "hello");
            sdj.SetData(dict);

            Assert.AreEqual("{\"data\":{\"app\":\"hello\", \"demo\":5}, \"schema\":\"iglu:acme.com/demo_app/jsonschema/1-0-1\"}", sdj.ToString());
        }