-
Notifications
You must be signed in to change notification settings - Fork 12
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat: add plan versionId support (#22)
- Loading branch information
1 parent
8c46250
commit ae84619
Showing
2 changed files
with
53 additions
and
2 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,7 +1,53 @@ | ||
package com.amplitude.core.events | ||
|
||
import com.amplitude.common.jvm.ConsoleLogger | ||
import org.json.JSONException | ||
import org.json.JSONObject | ||
|
||
data class Plan( | ||
val branch: String? = null, | ||
val source: String? = null, | ||
val version: String? = null | ||
) | ||
val version: String? = null, | ||
val versionId: String? = null, | ||
) { | ||
|
||
/** | ||
* Get JSONObject of current tacking plan | ||
* @return JSONObject including plan information | ||
*/ | ||
fun toJSONObject(): JSONObject? { | ||
val plan = JSONObject() | ||
try { | ||
if (!branch.isNullOrEmpty()) { | ||
plan.put(AMP_PLAN_BRANCH, branch) | ||
} | ||
if (!source.isNullOrEmpty()) { | ||
plan.put(AMP_PLAN_SOURCE, source) | ||
} | ||
if (!version.isNullOrEmpty()) { | ||
plan.put(AMP_PLAN_VERSION, version) | ||
} | ||
if (!versionId.isNullOrEmpty()) { | ||
plan.put(AMP_PLAN_VERSION_ID, versionId) | ||
} | ||
} catch (e: JSONException) { | ||
ConsoleLogger.logger.error("JSON Serialization of tacking plan object failed") | ||
} | ||
return plan | ||
} | ||
|
||
companion object { | ||
const val AMP_PLAN_BRANCH = "branch" | ||
const val AMP_PLAN_SOURCE = "source" | ||
const val AMP_PLAN_VERSION = "version" | ||
const val AMP_PLAN_VERSION_ID = "versionId" | ||
|
||
fun fromJSONObject(jsonObject: JSONObject): Plan { | ||
val branch = jsonObject.optString(AMP_PLAN_BRANCH, null) | ||
val source = jsonObject.optString(AMP_PLAN_SOURCE, null) | ||
val version = jsonObject.optString(AMP_PLAN_VERSION, null) | ||
val versionId = jsonObject.optString(AMP_PLAN_VERSION_ID, null) | ||
return Plan(branch, source, version, versionId) | ||
} | ||
} | ||
} |
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