-
Notifications
You must be signed in to change notification settings - Fork 119
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Configure AWSPinpointAnalyticsPlugin with AmplifyOutputs
- Loading branch information
1 parent
5d83536
commit 8cfdc0a
Showing
7 changed files
with
229 additions
and
35 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
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
64 changes: 64 additions & 0 deletions
64
...rc/main/java/com/amplifyframework/analytics/pinpoint/AWSPinpointAnalyticsPluginOptions.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,64 @@ | ||
/* | ||
* Copyright 2024 Amazon.com, Inc. or its affiliates. All Rights Reserved. | ||
* | ||
* Licensed under the Apache License, Version 2.0 (the "License"). | ||
* You may not use this file except in compliance with the License. | ||
* A copy of the License is located at | ||
* | ||
* http://aws.amazon.com/apache2.0 | ||
* | ||
* or in the "license" file accompanying this file. This file is distributed | ||
* on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either | ||
* express or implied. See the License for the specific language governing | ||
* permissions and limitations under the License. | ||
*/ | ||
|
||
package com.amplifyframework.analytics.pinpoint | ||
|
||
import com.amplifyframework.analytics.pinpoint.AWSPinpointAnalyticsPluginConfiguration.DEFAULT_AUTO_FLUSH_INTERVAL | ||
|
||
/** | ||
* Options that can be specified to fine-tune the behavior of the Pinpoint Analytics Plugin. | ||
*/ | ||
data class AWSPinpointAnalyticsPluginOptions internal constructor( | ||
/** | ||
* The interval between sends of queued analytics events, in milliseconds | ||
*/ | ||
val autoFlushEventsInterval: Long | ||
) { | ||
companion object { | ||
/** | ||
* Create a new [Builder] instance | ||
*/ | ||
@JvmStatic | ||
fun builder() = Builder() | ||
|
||
/** | ||
* Create an [AWSPinpointAnalyticsPluginOptions] instance | ||
*/ | ||
@JvmSynthetic | ||
operator fun invoke(func: Builder.() -> Unit) = Builder().apply(func).build() | ||
|
||
internal fun defaults() = builder().build() | ||
} | ||
|
||
/** | ||
* Builder API for constructing [AWSPinpointAnalyticsPluginOptions] instances | ||
*/ | ||
class Builder internal constructor() { | ||
/** | ||
* Set the interval between sends of queed analytics events, in milliseconds | ||
*/ | ||
var autoFlushEventsInterval: Long = DEFAULT_AUTO_FLUSH_INTERVAL | ||
@JvmSynthetic set | ||
|
||
/** | ||
* Set the interval between sends of queed analytics events, in milliseconds | ||
*/ | ||
fun autoFlushEventsInterval(value: Long) = apply { autoFlushEventsInterval = value } | ||
|
||
internal fun build() = AWSPinpointAnalyticsPluginOptions( | ||
autoFlushEventsInterval = autoFlushEventsInterval | ||
) | ||
} | ||
} |
42 changes: 42 additions & 0 deletions
42
...va/com/amplifyframework/analytics/pinpoint/AWSPinpointAnalyticsPluginConfigurationTest.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,42 @@ | ||
/* | ||
* Copyright 2024 Amazon.com, Inc. or its affiliates. All Rights Reserved. | ||
* | ||
* Licensed under the Apache License, Version 2.0 (the "License"). | ||
* You may not use this file except in compliance with the License. | ||
* A copy of the License is located at | ||
* | ||
* http://aws.amazon.com/apache2.0 | ||
* | ||
* or in the "license" file accompanying this file. This file is distributed | ||
* on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either | ||
* express or implied. See the License for the specific language governing | ||
* permissions and limitations under the License. | ||
*/ | ||
|
||
package com.amplifyframework.analytics.pinpoint | ||
|
||
import com.amplifyframework.testutils.configuration.amplifyOutputsData | ||
import io.kotest.matchers.shouldBe | ||
import org.junit.Test | ||
|
||
class AWSPinpointAnalyticsPluginConfigurationTest { | ||
|
||
@Test | ||
fun `reads values from AmplifyOutputsData and Options`() { | ||
val outputs = amplifyOutputsData { | ||
analytics { | ||
awsRegion = "test-region" | ||
appId = "test-app" | ||
} | ||
} | ||
val options = AWSPinpointAnalyticsPluginOptions { | ||
autoFlushEventsInterval = 42 | ||
} | ||
|
||
val configuration = AWSPinpointAnalyticsPluginConfiguration.from(outputs, options) | ||
|
||
configuration.appId shouldBe "test-app" | ||
configuration.region shouldBe "test-region" | ||
configuration.autoFlushEventsInterval shouldBe 42 | ||
} | ||
} |
42 changes: 42 additions & 0 deletions
42
...s/src/main/java/com/amplifyframework/testutils/configuration/AmplifyOutputsDataBuilder.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,42 @@ | ||
/* | ||
* Copyright 2024 Amazon.com, Inc. or its affiliates. All Rights Reserved. | ||
* | ||
* Licensed under the Apache License, Version 2.0 (the "License"). | ||
* You may not use this file except in compliance with the License. | ||
* A copy of the License is located at | ||
* | ||
* http://aws.amazon.com/apache2.0 | ||
* | ||
* or in the "license" file accompanying this file. This file is distributed | ||
* on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either | ||
* express or implied. See the License for the specific language governing | ||
* permissions and limitations under the License. | ||
*/ | ||
|
||
package com.amplifyframework.testutils.configuration | ||
|
||
import com.amplifyframework.core.configuration.AmplifyOutputsData | ||
import kotlinx.serialization.json.JsonObject | ||
|
||
fun amplifyOutputsData(func: AmplifyOutputsDataBuilder.() -> Unit): AmplifyOutputsData = | ||
AmplifyOutputsDataBuilder().apply(func) | ||
|
||
class AmplifyOutputsDataBuilder : AmplifyOutputsData { | ||
override var version = "1" | ||
override var analytics: AmplifyOutputsData.Analytics? = null | ||
override var auth: AmplifyOutputsData.Auth? = null | ||
override val data: AmplifyOutputsData.Data? = null | ||
override val geo: AmplifyOutputsData.Geo? = null | ||
override val notifications: AmplifyOutputsData.Notifications? = null | ||
override val storage: AmplifyOutputsData.Storage? = null | ||
override val custom: JsonObject? = null | ||
|
||
fun analytics(func: AnalyticsBuilder.() -> Unit) { | ||
analytics = AnalyticsBuilder().apply(func) | ||
} | ||
} | ||
|
||
class AnalyticsBuilder : AmplifyOutputsData.Analytics { | ||
override var awsRegion: String = "us-east-1" | ||
override var appId: String = "analytics-app-id" | ||
} |