Skip to content

Commit

Permalink
fix: bring back java.util.Calendar to metadata constructors
Browse files Browse the repository at this point in the history
  • Loading branch information
wzieba committed Dec 13, 2023
1 parent 810dec9 commit 67a755b
Show file tree
Hide file tree
Showing 5 changed files with 17 additions and 15 deletions.
2 changes: 1 addition & 1 deletion example/src/main/java/com/example/MainActivity.java
Original file line number Diff line number Diff line change
Expand Up @@ -116,7 +116,7 @@ public void trackPlay(View view) {
new ArrayList<String>(),
"http://example.com/thumbs/video-1234",
"Awesome Video #1234",
System.currentTimeMillis(),
Calendar.getInstance(),
90
);
// NOTE: For videos embedded in an article, "url" should be the URL for that article.
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
package com.parsely.parselyandroid

import java.util.Calendar

/**
* Represents post metadata to be passed to Parsely tracking.
*
Expand All @@ -19,15 +21,15 @@ open class ParselyMetadata
* @param tags User-defined tags for the content. Up to 20 are allowed.
* @param thumbUrl URL at which the main image for this content is located.
* @param title The title of the content.
* @param publicationDateMilliseconds The date this piece of content was published.
* @param pubDate The date this piece of content was published.
*/(
private val authors: List<String>? = null,
@JvmField internal val link: String? = null,
private val section: String? = null,
private val tags: List<String>? = null,
private val thumbUrl: String? = null,
private val title: String? = null,
private val publicationDateMilliseconds: Long? = null
private val pubDate: Calendar? = null
) {
/**
* Turn this object into a Map
Expand All @@ -54,8 +56,8 @@ open class ParselyMetadata
if (title != null) {
output["title"] = title
}
if (publicationDateMilliseconds != null) {
output["pub_date_tmsp"] = publicationDateMilliseconds / 1000
if (pubDate != null) {
output["pub_date_tmsp"] = pubDate.timeInMillis / 1000
}
return output
}
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
package com.parsely.parselyandroid

import java.util.Calendar

/**
* ParselyMetadata for video content.
*/
Expand All @@ -13,7 +15,7 @@ class ParselyVideoMetadata
* @param tags User-defined tags for the video. Up to 20 are allowed.
* @param thumbUrl URL at which the main image for this video is located.
* @param title The title of the video.
* @param publicationDateMilliseconds The timestamp in milliseconds this video was published.
* @param pubDate The timestamp in milliseconds this video was published.
* @param durationSeconds Duration of the video in seconds. Required.
*/(
authors: List<String>? = null,
Expand All @@ -22,9 +24,9 @@ class ParselyVideoMetadata
tags: List<String>? = null,
thumbUrl: String? = null,
title: String? = null,
publicationDateMilliseconds: Long? = null,
pubDate: Calendar? = null,
@JvmField internal val durationSeconds: Int
) : ParselyMetadata(authors, videoId, section, tags, thumbUrl, title, publicationDateMilliseconds) {
) : ParselyMetadata(authors, videoId, section, tags, thumbUrl, title, pubDate) {
/**
* Turn this object into a Map
*
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,6 @@ import org.assertj.core.api.Assertions.assertThat
import org.assertj.core.api.MapAssert
import org.junit.Before
import org.junit.Test
import org.junit.runner.RunWith
import org.robolectric.RobolectricTestRunner

internal class EventsBuilderTest {
private lateinit var sut: EventsBuilder
Expand Down Expand Up @@ -161,7 +159,7 @@ internal class EventsBuilderTest {
fun `given metadata is not null, when creating a pixel, include metadata`() {
// given
val metadata = ParselyMetadata(
ArrayList<String>(), "link", "section", null, null, null, 0
ArrayList<String>(), "link", "section", null, null, null, null
)

// when
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ class ParselyMetadataTest {
tags,
thumbUrl,
title,
publicationDate.inWholeMilliseconds
pubDate
)

// when
Expand All @@ -38,7 +38,7 @@ class ParselyMetadataTest {
tags,
thumbUrl,
title,
publicationDate.inWholeMilliseconds,
pubDate,
duration
)

Expand All @@ -56,7 +56,7 @@ class ParselyMetadataTest {
val tags = arrayListOf("first tag", "second tag")
val thumbUrl = "sample thumb url"
val title = "sample title"
val publicationDate = 100.seconds
val pubDate = Calendar.getInstance().apply { set(2023, 0, 1) }

val expectedParselyMetadataMap = mapOf(
"authors" to authors,
Expand All @@ -65,7 +65,7 @@ class ParselyMetadataTest {
"tags" to tags,
"thumb_url" to thumbUrl,
"title" to title,
"pub_date_tmsp" to publicationDate.inWholeSeconds
"pub_date_tmsp" to pubDate.timeInMillis / 1000
)
}
}

0 comments on commit 67a755b

Please sign in to comment.