-
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.
Merge pull request #100 from Parsely/issue/migrate_events_builder_to_…
…kotlin Migrate `EventsBuilder` to Kotlin
- Loading branch information
Showing
8 changed files
with
85 additions
and
94 deletions.
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/EventsBuilder.java
This file was deleted.
Oops, something went wrong.
63 changes: 63 additions & 0 deletions
63
parsely/src/main/java/com/parsely/parselyandroid/EventsBuilder.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,63 @@ | ||
package com.parsely.parselyandroid | ||
|
||
import com.parsely.parselyandroid.Logging.log | ||
import java.util.Calendar | ||
import java.util.TimeZone | ||
|
||
internal class EventsBuilder( | ||
private val deviceInfoRepository: DeviceInfoRepository, | ||
private val siteId: String, | ||
private val clock: Clock, | ||
) { | ||
/** | ||
* Create an event Map | ||
* | ||
* @param url The URL identifying the pageview/heartbeat | ||
* @param action Action to use (e.g. pageview, heartbeat, videostart, vheartbeat) | ||
* @param metadata Metadata to attach to the event. | ||
* @param extraData A Map of additional information to send with the event. | ||
* @return A Map object representing the event to be sent to Parse.ly. | ||
*/ | ||
fun buildEvent( | ||
url: String, | ||
urlRef: String, | ||
action: String, | ||
metadata: ParselyMetadata?, | ||
extraData: Map<String, Any>?, | ||
uuid: String | ||
): Map<String, Any> { | ||
log("buildEvent called for %s/%s", action, url) | ||
|
||
// Main event info | ||
val event: MutableMap<String, Any> = HashMap() | ||
event["url"] = url | ||
event["urlref"] = urlRef | ||
event["idsite"] = siteId | ||
event["action"] = action | ||
|
||
// Make a copy of extraData and add some things. | ||
val data: MutableMap<String, Any> = HashMap() | ||
if (extraData != null) { | ||
data.putAll(extraData) | ||
} | ||
val deviceInfo = deviceInfoRepository.collectDeviceInfo() | ||
data["ts"] = clock.now.inWholeMilliseconds | ||
data.putAll(deviceInfo) | ||
event["data"] = data | ||
metadata?.let { | ||
event["metadata"] = it.toMap() | ||
} | ||
if (action == "videostart" || action == "vheartbeat") { | ||
event[VIDEO_START_ID_KEY] = uuid | ||
} | ||
if (action == "pageview" || action == "heartbeat") { | ||
event[PAGE_VIEW_ID_KEY] = uuid | ||
} | ||
return event | ||
} | ||
|
||
companion object { | ||
private const val VIDEO_START_ID_KEY = "vsid" | ||
private const val PAGE_VIEW_ID_KEY = "pvid" | ||
} | ||
} |
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
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
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
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
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