diff --git a/project/BuildSettings.scala b/project/BuildSettings.scala index d180c40..05a369e 100644 --- a/project/BuildSettings.scala +++ b/project/BuildSettings.scala @@ -33,7 +33,8 @@ object BuildSettings { "-Ywarn-nullary-override", "-Ywarn-nullary-unit", "-Ywarn-numeric-widen", - "-Ywarn-value-discard" + "-Ywarn-value-discard", + "-Ypartial-unification" ) ) diff --git a/src/main/scala/com.snowplowanalytics.snowplow.analytics.scalasdk/Event.scala b/src/main/scala/com.snowplowanalytics.snowplow.analytics.scalasdk/Event.scala index ae98525..b43b567 100644 --- a/src/main/scala/com.snowplowanalytics.snowplow.analytics.scalasdk/Event.scala +++ b/src/main/scala/com.snowplowanalytics.snowplow.analytics.scalasdk/Event.scala @@ -17,7 +17,7 @@ import java.time.Instant import java.util.UUID // circe -import io.circe.{Encoder, Json, JsonObject, ObjectEncoder} +import io.circe.{Encoder, Json, JsonObject, ObjectEncoder, Decoder} import io.circe.Json.JString import io.circe.generic.semiauto._ import io.circe.syntax._ @@ -241,6 +241,8 @@ object Event { */ implicit val jsonEncoder: ObjectEncoder[Event] = deriveEncoder[Event] + implicit def eventDecoder: Decoder[Event] = deriveDecoder[Event] + /** * Derived TSV parser for the Event class */ diff --git a/src/main/scala/com.snowplowanalytics.snowplow.analytics.scalasdk/SnowplowEvent.scala b/src/main/scala/com.snowplowanalytics.snowplow.analytics.scalasdk/SnowplowEvent.scala index 65766a4..5184dbd 100644 --- a/src/main/scala/com.snowplowanalytics.snowplow.analytics.scalasdk/SnowplowEvent.scala +++ b/src/main/scala/com.snowplowanalytics.snowplow.analytics.scalasdk/SnowplowEvent.scala @@ -14,7 +14,12 @@ package com.snowplowanalytics.snowplow.analytics.scalasdk // circe import io.circe.syntax._ -import io.circe.{Encoder, Json, JsonObject} +import io.circe.generic.semiauto._ +import io.circe.{Encoder, Json, JsonObject, Decoder, DecodingFailure} +import io.circe.CursorOp.DownField + +//cats +import cats.implicits._ // iglu import com.snowplowanalytics.iglu.core.circe.CirceIgluCodecs._ @@ -61,6 +66,10 @@ object SnowplowEvent { ).asJson } + implicit val contextsDecoder: Decoder[Contexts] = deriveDecoder[Contexts].recover { + case DecodingFailure(_, List(DownField("data"), DownField(_))) => Contexts(List()) + } + implicit final val unstructCirceEncoder: Encoder[UnstructEvent] = Encoder.instance { unstructEvent: UnstructEvent => if (unstructEvent.data.isEmpty) Json.Null @@ -70,6 +79,10 @@ object SnowplowEvent { ).asJson } + implicit val unstructEventDecoder: Decoder[UnstructEvent] = deriveDecoder[UnstructEvent].recover { + case DecodingFailure(_, List(DownField("data"), DownField(_))) => UnstructEvent(None) + } + /** * @param shredProperty Type of self-describing entity * @param vendor Iglu schema vendor diff --git a/src/test/scala/com.snowplowanalytics.snowplow.analytics.scalasdk/EventSpec.scala b/src/test/scala/com.snowplowanalytics.snowplow.analytics.scalasdk/EventSpec.scala index e024a0d..9fc4b0a 100644 --- a/src/test/scala/com.snowplowanalytics.snowplow.analytics.scalasdk/EventSpec.scala +++ b/src/test/scala/com.snowplowanalytics.snowplow.analytics.scalasdk/EventSpec.scala @@ -33,7 +33,7 @@ import org.specs2.mutable.Specification import com.snowplowanalytics.iglu.core.{SchemaKey, SchemaVer, SelfDescribingData} // This library -import com.snowplowanalytics.snowplow.analytics.scalasdk.SnowplowEvent.{Contexts, UnstructEvent} +import com.snowplowanalytics.snowplow.analytics.scalasdk.SnowplowEvent._ /** * Tests Event case class @@ -2004,6 +2004,739 @@ class EventSpec extends Specification { "Cannot parse key 'true_tstamp with value VALUE IS MISSING into datetime" )) } + + "successfully decode encoded event which has no contexts or unstruct_event" in { + val event = Event( + app_id = Some("angry-birds"), + platform = Some("web"), + etl_tstamp = Some(Instant.parse("2017-01-26T00:01:25.292Z")), + collector_tstamp = Instant.parse("2013-11-26T00:02:05Z"), + dvce_created_tstamp = Some(Instant.parse("2013-11-26T00:03:57.885Z")), + event = Some("page_view"), + event_id = UUID.fromString("c6ef3124-b53a-4b13-a233-0088f79dcbcb"), + txn_id = Some(41828), + name_tracker = Some("cloudfront-1"), + v_tracker = Some("js-2.1.0"), + v_collector = "clj-tomcat-0.1.0", + v_etl = "serde-0.5.2", + user_id = Some("jon.doe@email.com"), + user_ipaddress = Some("92.231.54.234"), + user_fingerprint = Some("2161814971"), + domain_userid = Some("bc2e92ec6c204a14"), + domain_sessionidx = Some(3), + network_userid = Some("ecdff4d0-9175-40ac-a8bb-325c49733607"), + geo_country = Some("US"), + geo_region = Some("TX"), + geo_city = Some("New York"), + geo_zipcode = Some("94109"), + geo_latitude = Some(37.443604), + geo_longitude = Some(-122.4124), + geo_region_name = Some("Florida"), + ip_isp = Some("FDN Communications"), + ip_organization = Some("Bouygues Telecom"), + ip_domain = Some("nuvox.net"), + ip_netspeed = Some("Cable/DSL"), + page_url = Some("http://www.snowplowanalytics.com"), + page_title = Some("On Analytics"), + page_referrer = None, + page_urlscheme = Some("http"), + page_urlhost = Some("www.snowplowanalytics.com"), + page_urlport = Some(80), + page_urlpath = Some("/product/index.html"), + page_urlquery = Some("id=GTM-DLRG"), + page_urlfragment = Some("4-conclusion"), + refr_urlscheme = None, + refr_urlhost = None, + refr_urlport = None, + refr_urlpath = None, + refr_urlquery = None, + refr_urlfragment = None, + refr_medium = None, + refr_source = None, + refr_term = None, + mkt_medium = None, + mkt_source = None, + mkt_term = None, + mkt_content = None, + mkt_campaign = None, + contexts = Contexts(List()), + se_category = None, + se_action = None, + se_label = None, + se_property = None, + se_value = None, + unstruct_event = UnstructEvent(None), + tr_orderid = None, + tr_affiliation = None, + tr_total = None, + tr_tax = None, + tr_shipping = None, + tr_city = None, + tr_state = None, + tr_country = None, + ti_orderid = None, + ti_sku = None, + ti_name = None, + ti_category = None, + ti_price = None, + ti_quantity = None, + pp_xoffset_min = None, + pp_xoffset_max = None, + pp_yoffset_min = None, + pp_yoffset_max = None, + useragent = None, + br_name = None, + br_family = None, + br_version = None, + br_type = None, + br_renderengine = None, + br_lang = None, + br_features_pdf = Some(true), + br_features_flash = Some(false), + br_features_java = None, + br_features_director = None, + br_features_quicktime = None, + br_features_realplayer = None, + br_features_windowsmedia = None, + br_features_gears = None, + br_features_silverlight = None, + br_cookies = None, + br_colordepth = None, + br_viewwidth = None, + br_viewheight = None, + os_name = None, + os_family = None, + os_manufacturer = None, + os_timezone = None, + dvce_type = None, + dvce_ismobile = None, + dvce_screenwidth = None, + dvce_screenheight = None, + doc_charset = None, + doc_width = None, + doc_height = None, + tr_currency = None, + tr_total_base = None, + tr_tax_base = None, + tr_shipping_base = None, + ti_currency = None, + ti_price_base = None, + base_currency = None, + geo_timezone = None, + mkt_clickid = None, + mkt_network = None, + etl_tags = None, + dvce_sent_tstamp = None, + refr_domain_userid = None, + refr_dvce_tstamp = None, + derived_contexts = Contexts(List()), + domain_sessionid = Some("2b15e5c8-d3b1-11e4-b9d6-1681e6b88ec1"), + derived_tstamp = Some(Instant.parse("2013-11-26T00:03:57.886Z")), + event_vendor = Some("com.snowplowanalytics.snowplow"), + event_name = Some("link_click"), + event_format = Some("jsonschema"), + event_version = Some("1-0-0"), + event_fingerprint = Some("e3dbfa9cca0412c3d4052863cefb547f"), + true_tstamp = Some(Instant.parse("2013-11-26T00:03:57.886Z")) + ) + val eventJson = event.toJson(false) + eventJson.as[Event] must beRight(event) + } + + + "successfully decode encoded event which has contexts but has no unstruct_event" in { + val event = Event( + app_id = Some("angry-birds"), + platform = Some("web"), + etl_tstamp = Some(Instant.parse("2017-01-26T00:01:25.292Z")), + collector_tstamp = Instant.parse("2013-11-26T00:02:05Z"), + dvce_created_tstamp = Some(Instant.parse("2013-11-26T00:03:57.885Z")), + event = Some("page_view"), + event_id = UUID.fromString("c6ef3124-b53a-4b13-a233-0088f79dcbcb"), + txn_id = Some(41828), + name_tracker = Some("cloudfront-1"), + v_tracker = Some("js-2.1.0"), + v_collector = "clj-tomcat-0.1.0", + v_etl = "serde-0.5.2", + user_id = Some("jon.doe@email.com"), + user_ipaddress = Some("92.231.54.234"), + user_fingerprint = Some("2161814971"), + domain_userid = Some("bc2e92ec6c204a14"), + domain_sessionidx = Some(3), + network_userid = Some("ecdff4d0-9175-40ac-a8bb-325c49733607"), + geo_country = Some("US"), + geo_region = Some("TX"), + geo_city = Some("New York"), + geo_zipcode = Some("94109"), + geo_latitude = Some(37.443604), + geo_longitude = Some(-122.4124), + geo_region_name = Some("Florida"), + ip_isp = Some("FDN Communications"), + ip_organization = Some("Bouygues Telecom"), + ip_domain = Some("nuvox.net"), + ip_netspeed = Some("Cable/DSL"), + page_url = Some("http://www.snowplowanalytics.com"), + page_title = Some("On Analytics"), + page_referrer = None, + page_urlscheme = Some("http"), + page_urlhost = Some("www.snowplowanalytics.com"), + page_urlport = Some(80), + page_urlpath = Some("/product/index.html"), + page_urlquery = Some("id=GTM-DLRG"), + page_urlfragment = Some("4-conclusion"), + refr_urlscheme = None, + refr_urlhost = None, + refr_urlport = None, + refr_urlpath = None, + refr_urlquery = None, + refr_urlfragment = None, + refr_medium = None, + refr_source = None, + refr_term = None, + mkt_medium = None, + mkt_source = None, + mkt_term = None, + mkt_content = None, + mkt_campaign = None, + contexts = Contexts( + List( + SelfDescribingData( + SchemaKey( + "org.schema", + "WebPage", + "jsonschema", + SchemaVer.Full(1, 0, 0) + ), + JsonObject( + ("genre", "blog".asJson), + ("inLanguage", "en-US".asJson), + ("datePublished", "2014-11-06T00:00:00Z".asJson), + ("author", "Fred Blundun".asJson), + ("breadcrumb", List("blog", "releases").asJson), + ("keywords", List("snowplow", "javascript", "tracker", "event").asJson) + ).asJson + ), + SelfDescribingData( + SchemaKey( + "org.w3", + "PerformanceTiming", + "jsonschema", + SchemaVer.Full(1, 0, 0) + ), + JsonObject( + ("navigationStart", 1415358089861L.asJson), + ("unloadEventStart", 1415358090270L.asJson), + ("unloadEventEnd", 1415358090287L.asJson), + ("redirectStart", 0.asJson), + ("redirectEnd", 0.asJson), + ("fetchStart", 1415358089870L.asJson), + ("domainLookupStart", 1415358090102L.asJson), + ("domainLookupEnd", 1415358090102L.asJson), + ("connectStart", 1415358090103L.asJson), + ("connectEnd", 1415358090183L.asJson), + ("requestStart", 1415358090183L.asJson), + ("responseStart", 1415358090265L.asJson), + ("responseEnd", 1415358090265L.asJson), + ("domLoading", 1415358090270L.asJson), + ("domInteractive", 1415358090886L.asJson), + ("domContentLoadedEventStart", 1415358090968L.asJson), + ("domContentLoadedEventEnd", 1415358091309L.asJson), + ("domComplete", 0.asJson), + ("loadEventStart", 0.asJson), + ("loadEventEnd", 0.asJson) + ).asJson + ) + ) + ), + se_category = None, + se_action = None, + se_label = None, + se_property = None, + se_value = None, + unstruct_event = UnstructEvent(None), + tr_orderid = None, + tr_affiliation = None, + tr_total = None, + tr_tax = None, + tr_shipping = None, + tr_city = None, + tr_state = None, + tr_country = None, + ti_orderid = None, + ti_sku = None, + ti_name = None, + ti_category = None, + ti_price = None, + ti_quantity = None, + pp_xoffset_min = None, + pp_xoffset_max = None, + pp_yoffset_min = None, + pp_yoffset_max = None, + useragent = None, + br_name = None, + br_family = None, + br_version = None, + br_type = None, + br_renderengine = None, + br_lang = None, + br_features_pdf = Some(true), + br_features_flash = Some(false), + br_features_java = None, + br_features_director = None, + br_features_quicktime = None, + br_features_realplayer = None, + br_features_windowsmedia = None, + br_features_gears = None, + br_features_silverlight = None, + br_cookies = None, + br_colordepth = None, + br_viewwidth = None, + br_viewheight = None, + os_name = None, + os_family = None, + os_manufacturer = None, + os_timezone = None, + dvce_type = None, + dvce_ismobile = None, + dvce_screenwidth = None, + dvce_screenheight = None, + doc_charset = None, + doc_width = None, + doc_height = None, + tr_currency = None, + tr_total_base = None, + tr_tax_base = None, + tr_shipping_base = None, + ti_currency = None, + ti_price_base = None, + base_currency = None, + geo_timezone = None, + mkt_clickid = None, + mkt_network = None, + etl_tags = None, + dvce_sent_tstamp = None, + refr_domain_userid = None, + refr_dvce_tstamp = None, + derived_contexts = Contexts( + List( + SelfDescribingData( + SchemaKey( + "com.snowplowanalytics.snowplow", + "ua_parser_context", + "jsonschema", + SchemaVer.Full(1, 0, 0) + ), + JsonObject( + ("useragentFamily", "IE".asJson), + ("useragentMajor", "7".asJson), + ("useragentMinor", "0".asJson), + ("useragentPatch", Json.Null), + ("useragentVersion", "IE 7.0".asJson), + ("osFamily", "Windows XP".asJson), + ("osMajor", Json.Null), + ("osMinor", Json.Null), + ("osPatch", Json.Null), + ("osPatchMinor", Json.Null), + ("osVersion", "Windows XP".asJson), + ("deviceFamily", "Other".asJson) + ).asJson + ) + ) + ), + domain_sessionid = Some("2b15e5c8-d3b1-11e4-b9d6-1681e6b88ec1"), + derived_tstamp = Some(Instant.parse("2013-11-26T00:03:57.886Z")), + event_vendor = Some("com.snowplowanalytics.snowplow"), + event_name = Some("link_click"), + event_format = Some("jsonschema"), + event_version = Some("1-0-0"), + event_fingerprint = Some("e3dbfa9cca0412c3d4052863cefb547f"), + true_tstamp = Some(Instant.parse("2013-11-26T00:03:57.886Z")) + ) + val eventJson = event.toJson(false) + eventJson.as[Event] must beRight(event) + } + + "successfully decode encoded event which has unstruct_event but has no contexts" in { + val event = Event( + app_id = Some("angry-birds"), + platform = Some("web"), + etl_tstamp = Some(Instant.parse("2017-01-26T00:01:25.292Z")), + collector_tstamp = Instant.parse("2013-11-26T00:02:05Z"), + dvce_created_tstamp = Some(Instant.parse("2013-11-26T00:03:57.885Z")), + event = Some("page_view"), + event_id = UUID.fromString("c6ef3124-b53a-4b13-a233-0088f79dcbcb"), + txn_id = Some(41828), + name_tracker = Some("cloudfront-1"), + v_tracker = Some("js-2.1.0"), + v_collector = "clj-tomcat-0.1.0", + v_etl = "serde-0.5.2", + user_id = Some("jon.doe@email.com"), + user_ipaddress = Some("92.231.54.234"), + user_fingerprint = Some("2161814971"), + domain_userid = Some("bc2e92ec6c204a14"), + domain_sessionidx = Some(3), + network_userid = Some("ecdff4d0-9175-40ac-a8bb-325c49733607"), + geo_country = Some("US"), + geo_region = Some("TX"), + geo_city = Some("New York"), + geo_zipcode = Some("94109"), + geo_latitude = Some(37.443604), + geo_longitude = Some(-122.4124), + geo_region_name = Some("Florida"), + ip_isp = Some("FDN Communications"), + ip_organization = Some("Bouygues Telecom"), + ip_domain = Some("nuvox.net"), + ip_netspeed = Some("Cable/DSL"), + page_url = Some("http://www.snowplowanalytics.com"), + page_title = Some("On Analytics"), + page_referrer = None, + page_urlscheme = Some("http"), + page_urlhost = Some("www.snowplowanalytics.com"), + page_urlport = Some(80), + page_urlpath = Some("/product/index.html"), + page_urlquery = Some("id=GTM-DLRG"), + page_urlfragment = Some("4-conclusion"), + refr_urlscheme = None, + refr_urlhost = None, + refr_urlport = None, + refr_urlpath = None, + refr_urlquery = None, + refr_urlfragment = None, + refr_medium = None, + refr_source = None, + refr_term = None, + mkt_medium = None, + mkt_source = None, + mkt_term = None, + mkt_content = None, + mkt_campaign = None, + contexts = Contexts(List()), + se_category = None, + se_action = None, + se_label = None, + se_property = None, + se_value = None, + unstruct_event = UnstructEvent( + Some( + SelfDescribingData( + SchemaKey( + "com.snowplowanalytics.snowplow", + "link_click", + "jsonschema", + SchemaVer.Full(1, 0, 1) + ), + JsonObject( + ("targetUrl", "http://www.example.com".asJson), + ("elementClasses", List("foreground").asJson), + ("elementId", "exampleLink".asJson) + ).asJson + ) + ) + ), + tr_orderid = None, + tr_affiliation = None, + tr_total = None, + tr_tax = None, + tr_shipping = None, + tr_city = None, + tr_state = None, + tr_country = None, + ti_orderid = None, + ti_sku = None, + ti_name = None, + ti_category = None, + ti_price = None, + ti_quantity = None, + pp_xoffset_min = None, + pp_xoffset_max = None, + pp_yoffset_min = None, + pp_yoffset_max = None, + useragent = None, + br_name = None, + br_family = None, + br_version = None, + br_type = None, + br_renderengine = None, + br_lang = None, + br_features_pdf = Some(true), + br_features_flash = Some(false), + br_features_java = None, + br_features_director = None, + br_features_quicktime = None, + br_features_realplayer = None, + br_features_windowsmedia = None, + br_features_gears = None, + br_features_silverlight = None, + br_cookies = None, + br_colordepth = None, + br_viewwidth = None, + br_viewheight = None, + os_name = None, + os_family = None, + os_manufacturer = None, + os_timezone = None, + dvce_type = None, + dvce_ismobile = None, + dvce_screenwidth = None, + dvce_screenheight = None, + doc_charset = None, + doc_width = None, + doc_height = None, + tr_currency = None, + tr_total_base = None, + tr_tax_base = None, + tr_shipping_base = None, + ti_currency = None, + ti_price_base = None, + base_currency = None, + geo_timezone = None, + mkt_clickid = None, + mkt_network = None, + etl_tags = None, + dvce_sent_tstamp = None, + refr_domain_userid = None, + refr_dvce_tstamp = None, + derived_contexts = Contexts(List()), + domain_sessionid = Some("2b15e5c8-d3b1-11e4-b9d6-1681e6b88ec1"), + derived_tstamp = Some(Instant.parse("2013-11-26T00:03:57.886Z")), + event_vendor = Some("com.snowplowanalytics.snowplow"), + event_name = Some("link_click"), + event_format = Some("jsonschema"), + event_version = Some("1-0-0"), + event_fingerprint = Some("e3dbfa9cca0412c3d4052863cefb547f"), + true_tstamp = Some(Instant.parse("2013-11-26T00:03:57.886Z")) + ) + val eventJson = event.toJson(false) + eventJson.as[Event] must beRight(event) + } + + "successfully decode encoded event which has both contexts and unstruct_event" in { + val event = Event( + app_id = Some("angry-birds"), + platform = Some("web"), + etl_tstamp = Some(Instant.parse("2017-01-26T00:01:25.292Z")), + collector_tstamp = Instant.parse("2013-11-26T00:02:05Z"), + dvce_created_tstamp = Some(Instant.parse("2013-11-26T00:03:57.885Z")), + event = Some("page_view"), + event_id = UUID.fromString("c6ef3124-b53a-4b13-a233-0088f79dcbcb"), + txn_id = Some(41828), + name_tracker = Some("cloudfront-1"), + v_tracker = Some("js-2.1.0"), + v_collector = "clj-tomcat-0.1.0", + v_etl = "serde-0.5.2", + user_id = Some("jon.doe@email.com"), + user_ipaddress = Some("92.231.54.234"), + user_fingerprint = Some("2161814971"), + domain_userid = Some("bc2e92ec6c204a14"), + domain_sessionidx = Some(3), + network_userid = Some("ecdff4d0-9175-40ac-a8bb-325c49733607"), + geo_country = Some("US"), + geo_region = Some("TX"), + geo_city = Some("New York"), + geo_zipcode = Some("94109"), + geo_latitude = Some(37.443604), + geo_longitude = Some(-122.4124), + geo_region_name = Some("Florida"), + ip_isp = Some("FDN Communications"), + ip_organization = Some("Bouygues Telecom"), + ip_domain = Some("nuvox.net"), + ip_netspeed = Some("Cable/DSL"), + page_url = Some("http://www.snowplowanalytics.com"), + page_title = Some("On Analytics"), + page_referrer = None, + page_urlscheme = Some("http"), + page_urlhost = Some("www.snowplowanalytics.com"), + page_urlport = Some(80), + page_urlpath = Some("/product/index.html"), + page_urlquery = Some("id=GTM-DLRG"), + page_urlfragment = Some("4-conclusion"), + refr_urlscheme = None, + refr_urlhost = None, + refr_urlport = None, + refr_urlpath = None, + refr_urlquery = None, + refr_urlfragment = None, + refr_medium = None, + refr_source = None, + refr_term = None, + mkt_medium = None, + mkt_source = None, + mkt_term = None, + mkt_content = None, + mkt_campaign = None, + contexts = Contexts( + List( + SelfDescribingData( + SchemaKey( + "org.schema", + "WebPage", + "jsonschema", + SchemaVer.Full(1, 0, 0) + ), + JsonObject( + ("genre", "blog".asJson), + ("inLanguage", "en-US".asJson), + ("datePublished", "2014-11-06T00:00:00Z".asJson), + ("author", "Fred Blundun".asJson), + ("breadcrumb", List("blog", "releases").asJson), + ("keywords", List("snowplow", "javascript", "tracker", "event").asJson) + ).asJson + ), + SelfDescribingData( + SchemaKey( + "org.w3", + "PerformanceTiming", + "jsonschema", + SchemaVer.Full(1, 0, 0) + ), + JsonObject( + ("navigationStart", 1415358089861L.asJson), + ("unloadEventStart", 1415358090270L.asJson), + ("unloadEventEnd", 1415358090287L.asJson), + ("redirectStart", 0.asJson), + ("redirectEnd", 0.asJson), + ("fetchStart", 1415358089870L.asJson), + ("domainLookupStart", 1415358090102L.asJson), + ("domainLookupEnd", 1415358090102L.asJson), + ("connectStart", 1415358090103L.asJson), + ("connectEnd", 1415358090183L.asJson), + ("requestStart", 1415358090183L.asJson), + ("responseStart", 1415358090265L.asJson), + ("responseEnd", 1415358090265L.asJson), + ("domLoading", 1415358090270L.asJson), + ("domInteractive", 1415358090886L.asJson), + ("domContentLoadedEventStart", 1415358090968L.asJson), + ("domContentLoadedEventEnd", 1415358091309L.asJson), + ("domComplete", 0.asJson), + ("loadEventStart", 0.asJson), + ("loadEventEnd", 0.asJson) + ).asJson + ) + ) + ), + se_category = None, + se_action = None, + se_label = None, + se_property = None, + se_value = None, + unstruct_event = UnstructEvent( + Some( + SelfDescribingData( + SchemaKey( + "com.snowplowanalytics.snowplow", + "link_click", + "jsonschema", + SchemaVer.Full(1, 0, 1) + ), + JsonObject( + ("targetUrl", "http://www.example.com".asJson), + ("elementClasses", List("foreground").asJson), + ("elementId", "exampleLink".asJson) + ).asJson + ) + ) + ), + tr_orderid = None, + tr_affiliation = None, + tr_total = None, + tr_tax = None, + tr_shipping = None, + tr_city = None, + tr_state = None, + tr_country = None, + ti_orderid = None, + ti_sku = None, + ti_name = None, + ti_category = None, + ti_price = None, + ti_quantity = None, + pp_xoffset_min = None, + pp_xoffset_max = None, + pp_yoffset_min = None, + pp_yoffset_max = None, + useragent = None, + br_name = None, + br_family = None, + br_version = None, + br_type = None, + br_renderengine = None, + br_lang = None, + br_features_pdf = Some(true), + br_features_flash = Some(false), + br_features_java = None, + br_features_director = None, + br_features_quicktime = None, + br_features_realplayer = None, + br_features_windowsmedia = None, + br_features_gears = None, + br_features_silverlight = None, + br_cookies = None, + br_colordepth = None, + br_viewwidth = None, + br_viewheight = None, + os_name = None, + os_family = None, + os_manufacturer = None, + os_timezone = None, + dvce_type = None, + dvce_ismobile = None, + dvce_screenwidth = None, + dvce_screenheight = None, + doc_charset = None, + doc_width = None, + doc_height = None, + tr_currency = None, + tr_total_base = None, + tr_tax_base = None, + tr_shipping_base = None, + ti_currency = None, + ti_price_base = None, + base_currency = None, + geo_timezone = None, + mkt_clickid = None, + mkt_network = None, + etl_tags = None, + dvce_sent_tstamp = None, + refr_domain_userid = None, + refr_dvce_tstamp = None, + derived_contexts = Contexts( + List( + SelfDescribingData( + SchemaKey( + "com.snowplowanalytics.snowplow", + "ua_parser_context", + "jsonschema", + SchemaVer.Full(1, 0, 0) + ), + JsonObject( + ("useragentFamily", "IE".asJson), + ("useragentMajor", "7".asJson), + ("useragentMinor", "0".asJson), + ("useragentPatch", Json.Null), + ("useragentVersion", "IE 7.0".asJson), + ("osFamily", "Windows XP".asJson), + ("osMajor", Json.Null), + ("osMinor", Json.Null), + ("osPatch", Json.Null), + ("osPatchMinor", Json.Null), + ("osVersion", "Windows XP".asJson), + ("deviceFamily", "Other".asJson) + ).asJson + ) + ) + ), + domain_sessionid = Some("2b15e5c8-d3b1-11e4-b9d6-1681e6b88ec1"), + derived_tstamp = Some(Instant.parse("2013-11-26T00:03:57.886Z")), + event_vendor = Some("com.snowplowanalytics.snowplow"), + event_name = Some("link_click"), + event_format = Some("jsonschema"), + event_version = Some("1-0-0"), + event_fingerprint = Some("e3dbfa9cca0412c3d4052863cefb547f"), + true_tstamp = Some(Instant.parse("2013-11-26T00:03:57.886Z")) + ) + val eventJson = event.toJson(false) + eventJson.as[Event] must beRight(event) + } } "The transformSchema method" should {