-
Notifications
You must be signed in to change notification settings - Fork 3
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 #6 from apphud/development
Development
- Loading branch information
Showing
10 changed files
with
316 additions
and
24 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,10 +1,7 @@ | ||
package com.apphud.sdk | ||
|
||
import android.util.Log | ||
import com.apphud.sdk.body.AttributionBody | ||
import com.apphud.sdk.body.PurchaseBody | ||
import com.apphud.sdk.body.PurchaseItemBody | ||
import com.apphud.sdk.body.PushBody | ||
import com.apphud.sdk.body.* | ||
import com.apphud.sdk.client.ApiClient | ||
import com.apphud.sdk.client.ApphudService | ||
import com.apphud.sdk.client.HttpUrlConnectionExecutor | ||
|
@@ -108,4 +105,45 @@ class ApphudServiceTest { | |
val response = service.purchase(body) | ||
Log.e("WOW", "send push result: ${response.data.results}") | ||
} | ||
|
||
@Test | ||
fun userPropertiesTest() { | ||
val body = UserPropertiesBody( | ||
device_id = deviceId, | ||
properties = listOf( | ||
mapOf( | ||
"set_once" to true, | ||
"kind" to "string", | ||
"value" to "[email protected]", | ||
"name" to "\$email" | ||
), | ||
mapOf( | ||
"kind" to "integer", | ||
"set_once" to false, | ||
"name" to "\$age", | ||
"value" to 31 | ||
), | ||
mapOf( | ||
"set_once" to false, | ||
"value" to true, | ||
"name" to "custom_test_property_1", | ||
"kind" to "boolean" | ||
), | ||
mapOf( | ||
"set_once" to false, | ||
"value" to "gay", | ||
"name" to "\$gender", | ||
"kind" to "string" | ||
), | ||
mapOf( | ||
"name" to "custom_email", | ||
"value" to "[email protected]", | ||
"kind" to "string", | ||
"set_once" to true | ||
) | ||
) | ||
) | ||
val response = service.sendUserProperties(body) | ||
Log.e("WOW", "send user properties result: ${response.data.results}") | ||
} | ||
} |
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
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -153,30 +153,73 @@ object Apphud { | |
* Will return **null** if product is not yet fetched from Google Play Billing. | ||
*/ | ||
@kotlin.jvm.JvmStatic | ||
fun products(productIdentifier: String): SkuDetails? { | ||
fun product(productIdentifier: String): SkuDetails? { | ||
return ApphudInternal.getSkuDetailsByProductId(productIdentifier) | ||
} | ||
|
||
/** | ||
* Purchases product and automatically submit | ||
* @activity: current Activity for use | ||
* @productId: The identifier of the product you wish to purchase | ||
* @block: The closure that will be called when purchase completes. | ||
* @param activity: current Activity for use | ||
* @param productId: The identifier of the product you wish to purchase | ||
* @param block: The closure that will be called when purchase completes. | ||
*/ | ||
@kotlin.jvm.JvmStatic | ||
fun purchase(activity: Activity, productId: String, block: (List<Purchase>) -> Unit) = | ||
ApphudInternal.purchase(activity, productId, block) | ||
|
||
/** | ||
* Purchases product and automatically submit | ||
* @activity: current Activity for use | ||
* @details: The skuDetails of the product you wish to purchase | ||
* @block: The closure that will be called when purchase completes. | ||
* @param activity current Activity for use | ||
* @param details The skuDetails of the product you wish to purchase | ||
* @param block The closure that will be called when purchase completes. | ||
*/ | ||
@kotlin.jvm.JvmStatic | ||
fun purchase(activity: Activity, details: SkuDetails, block: (List<Purchase>) -> Unit) = | ||
ApphudInternal.purchase(activity, details, block) | ||
|
||
|
||
/** | ||
* Set custom user property. | ||
* Value must be one of: "Int", "Float", "Double", "Boolean", "String" or "null". | ||
* | ||
* Example: | ||
* // use built-in property key | ||
* Apphud.setUserProperty(key: ApphudUserPropertyKey.Email, value: "[email protected]", setOnce: true) | ||
* // use custom property key | ||
* Apphud.setUserProperty(key: ApphudUserPropertyKey.CustomProperty("custom_test_property_1"), value: 0.5) | ||
* | ||
* __Note__: You can use several built-in keys with their value types: | ||
* "ApphudUserPropertyKey.Email": User email. Value must be String. | ||
* "ApphudUserPropertyKey.Name": User name. Value must be String. | ||
* "ApphudUserPropertyKey.Phone": User phone number. Value must be String. | ||
* "ApphudUserPropertyKey.Age": User age. Value must be Int. | ||
* "ApphudUserPropertyKey.Gender": User gender. Value must be one of: "male", "female", "other". | ||
* "ApphudUserPropertyKey.Cohort": User install cohort. Value must be String. | ||
* | ||
* @param key Required. Initialize class with custom string or using built-in keys. See example above. | ||
* @param value Required/Optional. Pass "null" to remove given property from Apphud. | ||
* @param setOnce Optional. Pass "true" to make this property non-updatable. | ||
*/ | ||
@kotlin.jvm.JvmStatic | ||
fun setUserProperty(key: ApphudUserPropertyKey, value: Any?, setOnce: Boolean = false) { | ||
ApphudInternal.setUserProperty(key = key, value = value, setOnce = setOnce, increment = false) | ||
} | ||
|
||
/** | ||
* Increment custom user property. | ||
* Value must be one of: "Int", "Float", "Double". | ||
* | ||
* Example: | ||
* Apphud.incrementUserProperty(key: ApphudUserPropertyKey.CustomProperty("progress"), by: 0.5) | ||
* | ||
* @param key Required. Use your custom string key or some of built-in keys. | ||
* @param by Required/Optional. You can pass negative value to decrement. | ||
*/ | ||
@kotlin.jvm.JvmStatic | ||
fun incrementUserProperty(key: ApphudUserPropertyKey, by: Any) { | ||
ApphudInternal.setUserProperty(key = key, value = by, setOnce = false, increment = true) | ||
} | ||
|
||
/** | ||
* Enables debug logs. Better to call this method before SDK initialization. | ||
*/ | ||
|
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,36 @@ | ||
package com.apphud.sdk | ||
|
||
internal const val JSON_NAME_NAME = "name" | ||
internal const val JSON_NAME_VALUE = "value" | ||
internal const val JSON_NAME_SET_ONCE = "set_once" | ||
internal const val JSON_NAME_KIND = "kind" | ||
internal const val JSON_NAME_INCREMENT = "increment" | ||
|
||
internal data class ApphudUserProperty( | ||
val key: String, | ||
val value: Any?, | ||
val increment: Boolean = false, | ||
val setOnce: Boolean = false, | ||
val type: String = "" | ||
) { | ||
|
||
fun toJSON(): MutableMap<String, Any?>? { | ||
if (increment && value == null) { | ||
return null | ||
} | ||
|
||
val jsonParamsString: MutableMap<String, Any?> = mutableMapOf( | ||
JSON_NAME_NAME to key, | ||
JSON_NAME_VALUE to if (value !is Float || value !is Double) value else value as Double, | ||
JSON_NAME_SET_ONCE to setOnce | ||
) | ||
if (value != null) { | ||
jsonParamsString[JSON_NAME_KIND] = type | ||
} | ||
if (increment) { | ||
jsonParamsString[JSON_NAME_INCREMENT] = increment | ||
} | ||
return jsonParamsString | ||
} | ||
|
||
} |
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,43 @@ | ||
package com.apphud.sdk | ||
|
||
/** | ||
Built-in property keys. | ||
*/ | ||
/** User email. Value must be String. */ | ||
internal const val ApphudUserPropertyKeyEmail = "\$email" | ||
|
||
/** User name. Value must be String. */ | ||
internal const val ApphudUserPropertyKeyName = "\$name" | ||
|
||
/** User phone number. Value must be String. */ | ||
internal const val ApphudUserPropertyKeyPhone = "\$phone" | ||
|
||
/** User install cohort. Value must be String. */ | ||
internal const val ApphudUserPropertyKeyCohort = "\$cohort" | ||
|
||
/** User email. Value must be Int. */ | ||
internal const val ApphudUserPropertyKeyAge = "\$age" | ||
|
||
/** User email. Value must be one of: "male", "female", "other". */ | ||
internal const val ApphudUserPropertyKeyGender = "\$gender" | ||
|
||
sealed class ApphudUserPropertyKey(val key: String){ | ||
/** User email. Value must be String*/ | ||
object Email:ApphudUserPropertyKey(ApphudUserPropertyKeyEmail) | ||
/** User name. Value must be String*/ | ||
object Name:ApphudUserPropertyKey(ApphudUserPropertyKeyName) | ||
/** User phone number. Value must be String.*/ | ||
object Phone:ApphudUserPropertyKey(ApphudUserPropertyKeyPhone) | ||
/** User age. Value must be Int.*/ | ||
object Cohort:ApphudUserPropertyKey(ApphudUserPropertyKeyCohort) | ||
/** User install cohort. Value must be String.*/ | ||
object Age:ApphudUserPropertyKey(ApphudUserPropertyKeyAge) | ||
/** User gender. Value must be one of: "male", "female", "other".*/ | ||
object Gender:ApphudUserPropertyKey(ApphudUserPropertyKeyGender) | ||
/** | ||
Initialize with custom property key string. | ||
Example: | ||
Apphud.setUserProperty(key = ApphudUserPropertyKey.CustomProperty("custom_prop_1"), value = 0.5) | ||
*/ | ||
class CustomProperty(value: String):ApphudUserPropertyKey(value) | ||
} |
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,6 @@ | ||
package com.apphud.sdk.body | ||
|
||
data class UserPropertiesBody( | ||
val device_id: String, | ||
val properties: List<Map<String, Any?>> | ||
) |
Oops, something went wrong.