-
Notifications
You must be signed in to change notification settings - Fork 6
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Migrate ParselyMetadata
and ParselyVideoMetadata
to Kotlin. Improve API.
#96
Merged
Merged
Changes from 9 commits
Commits
Show all changes
12 commits
Select commit
Hold shift + click to select a range
5563177
tests: add unit test for `ParselyMetaData#toMap` method
wzieba 597ff4c
tests: add unit test for `ParselyVideoMetaData#toMap` method
wzieba 105a822
fix: set `toMap` methods visibility to package-private
wzieba b7a9ba0
style: address lint warnings
wzieba 341e73b
refactor: change type of publication date from `Calendar` to long
wzieba e1dbd50
Rename .java to .kt
wzieba 8119a56
refactor: migrate `ParselyMetadata` and `ParselyVideoMetadata` to kotlin
wzieba baa1400
Merge branch 'main' into issue/migrate_metadata_to_kotlin
wzieba fa379a9
refactor: accept `List` in metadata's constructors
wzieba 93c79ef
fix: make `publicationDateMilliseconds` nullable
wzieba 810dec9
feat: add `null` default arguments for nullable fields
wzieba 67a755b
fix: bring back `java.util.Calendar` to metadata constructors
wzieba File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
83 changes: 0 additions & 83 deletions
83
parsely/src/main/java/com/parsely/parselyandroid/ParselyMetadata.java
This file was deleted.
Oops, something went wrong.
60 changes: 60 additions & 0 deletions
60
parsely/src/main/java/com/parsely/parselyandroid/ParselyMetadata.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,60 @@ | ||
package com.parsely.parselyandroid | ||
|
||
/** | ||
* Represents post metadata to be passed to Parsely tracking. | ||
* | ||
* | ||
* This class is used to attach a metadata block to a Parse.ly pageview | ||
* request. Pageview metadata is only required for URLs not accessible over the | ||
* internet (i.e. app-only content) or if the customer is using an "in-pixel" integration. | ||
* Otherwise, metadata will be gathered by Parse.ly's crawling infrastructure. | ||
*/ | ||
open class ParselyMetadata | ||
/** | ||
* Create a new ParselyMetadata object. | ||
* | ||
* @param authors The names of the authors of the content. Up to 10 authors are accepted. | ||
* @param link A post's canonical url. | ||
* @param section The category or vertical to which this content belongs. | ||
* @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. | ||
*/( | ||
private val authors: List<String>?, | ||
@JvmField internal val link: String?, | ||
private val section: String?, | ||
private val tags: List<String>?, | ||
private val thumbUrl: String?, | ||
private val title: String?, | ||
private val publicationDateMilliseconds: Long | ||
) { | ||
/** | ||
* Turn this object into a Map | ||
* | ||
* @return a Map object representing the metadata. | ||
*/ | ||
open fun toMap(): Map<String, Any?>? { | ||
val output: MutableMap<String, Any?> = HashMap() | ||
if (authors != null) { | ||
output["authors"] = authors | ||
} | ||
if (link != null) { | ||
output["link"] = link | ||
} | ||
if (section != null) { | ||
output["section"] = section | ||
} | ||
if (tags != null) { | ||
output["tags"] = tags | ||
} | ||
if (thumbUrl != null) { | ||
output["thumb_url"] = thumbUrl | ||
} | ||
if (title != null) { | ||
output["title"] = title | ||
} | ||
output["pub_date_tmsp"] = publicationDateMilliseconds / 1000 | ||
return output | ||
} | ||
} |
56 changes: 0 additions & 56 deletions
56
parsely/src/main/java/com/parsely/parselyandroid/ParselyVideoMetadata.java
This file was deleted.
Oops, something went wrong.
38 changes: 38 additions & 0 deletions
38
parsely/src/main/java/com/parsely/parselyandroid/ParselyVideoMetadata.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,38 @@ | ||
package com.parsely.parselyandroid | ||
|
||
/** | ||
* ParselyMetadata for video content. | ||
*/ | ||
class ParselyVideoMetadata | ||
/** | ||
* Create a new ParselyVideoMetadata object. | ||
* | ||
* @param authors The names of the authors of the video. Up to 10 authors are accepted. | ||
* @param videoId Unique identifier for the video. Required. | ||
* @param section The category or vertical to which this video belongs. | ||
* @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 durationSeconds Duration of the video in seconds. Required. | ||
*/( | ||
authors: List<String>?, | ||
videoId: String, | ||
section: String?, | ||
tags: List<String>?, | ||
thumbUrl: String?, | ||
title: String?, | ||
publicationDateMilliseconds: Long, | ||
@JvmField internal val durationSeconds: Int | ||
) : ParselyMetadata(authors, videoId, section, tags, thumbUrl, title, publicationDateMilliseconds) { | ||
/** | ||
* Turn this object into a Map | ||
* | ||
* @return a Map object representing the metadata. | ||
*/ | ||
override fun toMap(): Map<String, Any?>? { | ||
val output = super.toMap()?.toMutableMap() | ||
output?.put("duration", durationSeconds) | ||
return output | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
71 changes: 71 additions & 0 deletions
71
parsely/src/test/java/com/parsely/parselyandroid/ParselyMetadataTest.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,71 @@ | ||
package com.parsely.parselyandroid | ||
|
||
import java.util.Calendar | ||
import kotlin.time.Duration.Companion.seconds | ||
import org.assertj.core.api.Assertions.assertThat | ||
import org.junit.Test | ||
|
||
class ParselyMetadataTest { | ||
|
||
@Test | ||
fun `given metadata with complete set of data, when converting to map, then the map is as expected`() { | ||
// given | ||
val sut = ParselyMetadata( | ||
authors, | ||
link, | ||
section, | ||
tags, | ||
thumbUrl, | ||
title, | ||
publicationDate.inWholeMilliseconds | ||
) | ||
|
||
// when | ||
val map = sut.toMap() | ||
|
||
// then | ||
assertThat(map).isEqualTo(expectedParselyMetadataMap) | ||
} | ||
|
||
@Test | ||
fun `given video metadata with complete set of data, when converting to map, then the map is as expected`() { | ||
// given | ||
val duration = 12 | ||
val sut = ParselyVideoMetadata( | ||
authors, | ||
link, | ||
section, | ||
tags, | ||
thumbUrl, | ||
title, | ||
publicationDate.inWholeMilliseconds, | ||
duration | ||
) | ||
|
||
// when | ||
val map = sut.toMap() | ||
|
||
// then | ||
assertThat(map).isEqualTo(expectedParselyMetadataMap + ("duration" to duration)) | ||
} | ||
|
||
companion object { | ||
val authors = arrayListOf("first author", "second author") | ||
val link = "sample link" | ||
val section = "sample section" | ||
val tags = arrayListOf("first tag", "second tag") | ||
val thumbUrl = "sample thumb url" | ||
val title = "sample title" | ||
val publicationDate = 100.seconds | ||
|
||
val expectedParselyMetadataMap = mapOf( | ||
"authors" to authors, | ||
"link" to link, | ||
"section" to section, | ||
"tags" to tags, | ||
"thumb_url" to thumbUrl, | ||
"title" to title, | ||
"pub_date_tmsp" to publicationDate.inWholeSeconds | ||
) | ||
} | ||
} |
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I always get a little worried when I see
open
keyword, but I guess this is keeping the current design - so it's all good 😅There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
True 😃 but yes, that's intentional.