-
Notifications
You must be signed in to change notification settings - Fork 6
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
refactor: migrate
ParselyMetadata
and ParselyVideoMetadata
to kotlin
- Loading branch information
Showing
2 changed files
with
66 additions
and
101 deletions.
There are no files selected for viewing
98 changes: 39 additions & 59 deletions
98
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 |
---|---|---|
@@ -1,80 +1,60 @@ | ||
package com.parsely.parselyandroid; | ||
|
||
import androidx.annotation.Nullable; | ||
|
||
import java.util.ArrayList; | ||
import java.util.HashMap; | ||
import java.util.Map; | ||
package com.parsely.parselyandroid | ||
|
||
/** | ||
* Represents post metadata to be passed to Parsely tracking. | ||
* <p> | ||
* | ||
* | ||
* 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. | ||
*/ | ||
public class ParselyMetadata { | ||
ArrayList<String> authors, tags; | ||
String link, section, thumbUrl, title; | ||
long publicationDateMilliseconds; | ||
|
||
/** | ||
* 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. | ||
*/ | ||
public ParselyMetadata( | ||
@Nullable ArrayList<String> authors, | ||
@Nullable String link, | ||
@Nullable String section, | ||
@Nullable ArrayList<String> tags, | ||
@Nullable String thumbUrl, | ||
@Nullable String title, | ||
long publicationDateMilliseconds | ||
) { | ||
this.authors = authors; | ||
this.link = link; | ||
this.section = section; | ||
this.tags = tags; | ||
this.thumbUrl = thumbUrl; | ||
this.title = title; | ||
this.publicationDateMilliseconds = publicationDateMilliseconds; | ||
} | ||
|
||
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: ArrayList<String>?, | ||
@JvmField internal val link: String?, | ||
private val section: String?, | ||
private val tags: ArrayList<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. | ||
*/ | ||
Map<String, Object> toMap() { | ||
Map<String, Object> output = new HashMap<>(); | ||
if (this.authors != null) { | ||
output.put("authors", this.authors); | ||
open fun toMap(): Map<String, Any?>? { | ||
val output: MutableMap<String, Any?> = HashMap() | ||
if (authors != null) { | ||
output["authors"] = authors | ||
} | ||
if (this.link != null) { | ||
output.put("link", this.link); | ||
if (link != null) { | ||
output["link"] = link | ||
} | ||
if (this.section != null) { | ||
output.put("section", this.section); | ||
if (section != null) { | ||
output["section"] = section | ||
} | ||
if (this.tags != null) { | ||
output.put("tags", this.tags); | ||
if (tags != null) { | ||
output["tags"] = tags | ||
} | ||
if (this.thumbUrl != null) { | ||
output.put("thumb_url", this.thumbUrl); | ||
if (thumbUrl != null) { | ||
output["thumb_url"] = thumbUrl | ||
} | ||
if (this.title != null) { | ||
output.put("title", this.title); | ||
if (title != null) { | ||
output["title"] = title | ||
} | ||
output.put("pub_date_tmsp", publicationDateMilliseconds / 1000); | ||
return output; | ||
output["pub_date_tmsp"] = publicationDateMilliseconds / 1000 | ||
return output | ||
} | ||
} | ||
|
69 changes: 27 additions & 42 deletions
69
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 |
---|---|---|
@@ -1,53 +1,38 @@ | ||
package com.parsely.parselyandroid; | ||
|
||
import androidx.annotation.NonNull; | ||
import androidx.annotation.Nullable; | ||
|
||
import java.util.ArrayList; | ||
import java.util.Calendar; | ||
import java.util.Map; | ||
package com.parsely.parselyandroid | ||
|
||
/** | ||
* ParselyMetadata for video content. | ||
*/ | ||
public class ParselyVideoMetadata extends ParselyMetadata { | ||
|
||
int durationSeconds; | ||
|
||
/** | ||
* 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. | ||
*/ | ||
public ParselyVideoMetadata( | ||
@Nullable ArrayList<String> authors, | ||
@NonNull String videoId, | ||
@Nullable String section, | ||
@Nullable ArrayList<String> tags, | ||
@Nullable String thumbUrl, | ||
@Nullable String title, | ||
long publicationDateMilliseconds, | ||
int durationSeconds | ||
) { | ||
super(authors, videoId, section, tags, thumbUrl, title, publicationDateMilliseconds); | ||
this.durationSeconds = durationSeconds; | ||
} | ||
|
||
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: ArrayList<String>?, | ||
videoId: String, | ||
section: String?, | ||
tags: ArrayList<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. | ||
*/ | ||
Map<String, Object> toMap() { | ||
Map<String, Object> output = super.toMap(); | ||
output.put("duration", this.durationSeconds); | ||
return output; | ||
override fun toMap(): Map<String, Any?>? { | ||
val output = super.toMap()?.toMutableMap() | ||
output?.put("duration", durationSeconds) | ||
return output | ||
} | ||
} |