Skip to content

Commit

Permalink
add comments and pending classes, features
Browse files Browse the repository at this point in the history
  • Loading branch information
marandaneto committed Sep 15, 2023
1 parent a4ee842 commit cf0791b
Show file tree
Hide file tree
Showing 10 changed files with 58 additions and 20 deletions.
5 changes: 4 additions & 1 deletion .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -152,4 +152,7 @@ build/
gradle-app.setting

# Jacoco
/posthog/jacoco.exec
/posthog/jacoco.exec

# eclipse
.project/
17 changes: 0 additions & 17 deletions .project

This file was deleted.

Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
package com.posthog.android.internal

// ActivityLifecycleCallbacks, IntegrationOperation, PostHogActivityLifecycleCallbacks
internal class PostHogActivityLifecycleCallback {
// TODO: lifecycle events, deeplinks, record screen views
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
package com.posthog.android.internal

// GetAdvertisingIdTask
class PostHogAdvertisingIdReader {
}
4 changes: 4 additions & 0 deletions posthog-v3/posthog/src/main/java/com/posthog/PostHog.kt
Original file line number Diff line number Diff line change
Expand Up @@ -79,6 +79,7 @@ public class PostHog {
properties?.let {
props.putAll(it)
}
// TODO: message_id=messageId

// distinctId is always present but it has to be nullable because the SDK may be disabled
// TODO: missing static, dynamic context
Expand Down Expand Up @@ -136,6 +137,7 @@ public class PostHog {

// TODO: reset feature flags, set anonymousId and distinctId
// val oldDistinctId = this.distinctId
// TODO: userProperties

val props = mutableMapOf<String, Any>()
props["distinct_id"] = distinctId
Expand All @@ -156,6 +158,7 @@ public class PostHog {
if (!isEnabled()) {
return
}
// TODO: groupProperties, event $groupidentify
}

public fun reloadFeatureFlagsRequest() {
Expand Down Expand Up @@ -265,5 +268,6 @@ public class PostHog {
}

// TODO: add other methods
// TODO: is Stats a feature or just used by tests in posthog-android
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@ public class PostHogConfig(
public var flushIntervalSeconds: Int = 30,

public var dataMode: PostHogDataMode = PostHogDataMode.ANY,
public var encryption: PostHogEncryption = PostHogEncryption.PostHogEncryptionNone()
) {
internal var logger: PostHogLogger? = null

Expand Down
21 changes: 21 additions & 0 deletions posthog-v3/posthog/src/main/java/com/posthog/PostHogEncryption.kt
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
package com.posthog

import java.io.InputStream
import java.io.OutputStream

public abstract class PostHogEncryption {
public abstract fun decrypt(inputStream: InputStream): InputStream

public abstract fun encrypt(outputStream: OutputStream): OutputStream

internal class PostHogEncryptionNone : PostHogEncryption() {
override fun decrypt(inputStream: InputStream): InputStream {
return inputStream
}

override fun encrypt(outputStream: OutputStream): OutputStream {
return outputStream
}

}
}
Original file line number Diff line number Diff line change
Expand Up @@ -21,10 +21,13 @@ internal class PostHogApi(private val config: PostHogConfig) {
private val mediaType = "application/json; charset=utf-8".toMediaType()
private val gson = GsonBuilder().apply {
registerTypeAdapter(Date::class.java, GsonDateTypeAdapter(config))
.setLenient()
}.create()
private val gsonBatchBodyType = object : TypeToken<PostHogBatchEvent>() {}.type
private val gsonDecideBodyType = object : TypeToken<Map<String, Any>>() {}.type

// TODO: do we care about max queue size? apparently theres a 500kb hardlimit on the server

fun batch(events: List<PostHogEvent>) {
val batch = PostHogBatchEvent(config.apiKey, events)
// """
Expand All @@ -39,11 +42,15 @@ internal class PostHogApi(private val config: PostHogConfig) {
// "timestamp": "2023-09-13T12:05:30.326Z"
// }
// ],
// "timestamp": "2023-09-13T12:05:30.326Z"
// "timestamp": "2023-09-13T12:05:30.326Z",
// "sent_at": "2023-09-13T12:05:30.326Z",
// }
// """.trimIndent()
val request = makeRequest("${config.host}/batch") {
gson.toJson(batch, gsonBatchBodyType, it.bufferedWriter())
val writer = it.bufferedWriter()
batch.sentAt = Date()
gson.toJson(batch, gsonBatchBodyType, writer)
writer.flush()
}

client.newCall(request).execute().use {
Expand Down Expand Up @@ -89,6 +96,7 @@ internal class PostHogApi(private val config: PostHogConfig) {
}

client.newCall(request).execute().use {
// TODO: do we handle 429 differently?
if (!it.isSuccessful) throw PostHogApiError(it.code, it.message, body = it.body)

it.body?.let { body ->
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,4 +9,6 @@ internal data class PostHogBatchEvent(
val apiKey: String,
val batch: List<PostHogEvent>,
val timestamp: Date = Date(),
@SerializedName("sent_at")
var sentAt: Date? = null,
)
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,11 @@ import com.posthog.PostHogConfig

internal class PostHogStorage(private val config: PostHogConfig) {
// TODO: move to disk cache instead of memory cache
// File folder = context.getDir("posthog-disk-queue"/tag(apiKey), Context.MODE_PRIVATE);
// /data/user/0/com.posthog.myapplication/app_posthog-disk-queue/_6SG-F7I1vCuZ-HdJL3VZQqjBlaSb1_20hDPwqMNnGI.tmp
// application.getSharedPreferences("posthog-android", Context.MODE_PRIVATE) - legacy
// context.getSharedPreferences("posthog-android-" + tag, MODE_PRIVATE)
// eg posthog-android-_6SG-F7I1vCuZ-HdJL3VZQqjBlaSb1_20hDPwqMNnGI
private val keyValues = mutableMapOf<String, Any>()
private val lock = Any()

Expand Down

0 comments on commit cf0791b

Please sign in to comment.