diff --git a/bank-api-library/library/src/main/java/net/gini/android/bank/api/BankApiDocumentRepository.kt b/bank-api-library/library/src/main/java/net/gini/android/bank/api/BankApiDocumentRepository.kt index c1372df64..fb1cb302c 100644 --- a/bank-api-library/library/src/main/java/net/gini/android/bank/api/BankApiDocumentRepository.kt +++ b/bank-api-library/library/src/main/java/net/gini/android/bank/api/BankApiDocumentRepository.kt @@ -62,8 +62,10 @@ class BankApiDocumentRepository( } suspend fun sendEvents(amplitudeRoot: AmplitudeRoot): Resource = - wrapInResource { - trackingAnalysisRemoteSource.sendEvents(amplitudeRoot) + withAccessToken { accessToken -> + wrapInResource { + trackingAnalysisRemoteSource.sendEvents(accessToken, amplitudeRoot) + } } diff --git a/bank-api-library/library/src/main/java/net/gini/android/bank/api/TrackingAnalysisRemoteSource.kt b/bank-api-library/library/src/main/java/net/gini/android/bank/api/TrackingAnalysisRemoteSource.kt index 0a84df872..d8ced4204 100644 --- a/bank-api-library/library/src/main/java/net/gini/android/bank/api/TrackingAnalysisRemoteSource.kt +++ b/bank-api-library/library/src/main/java/net/gini/android/bank/api/TrackingAnalysisRemoteSource.kt @@ -3,6 +3,7 @@ package net.gini.android.bank.api import kotlinx.coroutines.withContext import net.gini.android.bank.api.models.AmplitudeRoot import net.gini.android.bank.api.requests.toAmplitudeRequestBody +import net.gini.android.core.api.requests.BearerAuthorizatonHeader import net.gini.android.core.api.requests.SafeApiRequest import kotlin.coroutines.CoroutineContext @@ -14,10 +15,13 @@ class TrackingAnalysisRemoteSource internal constructor( private val trackingAnalysisService: TrackingAnalysisService ) { - suspend fun sendEvents(amplitudeRoot: AmplitudeRoot): Unit = + suspend fun sendEvents(accessToken: String, amplitudeRoot: AmplitudeRoot): Unit = withContext(coroutineContext) { SafeApiRequest.apiRequest { - trackingAnalysisService.sendEvents(amplitudeRoot.toAmplitudeRequestBody()) + trackingAnalysisService.sendEvents( + BearerAuthorizatonHeader(accessToken).value, + amplitudeRoot.toAmplitudeRequestBody() + ) } } diff --git a/bank-api-library/library/src/main/java/net/gini/android/bank/api/TrackingAnalysisService.kt b/bank-api-library/library/src/main/java/net/gini/android/bank/api/TrackingAnalysisService.kt index 1be0fcc41..c51267a94 100644 --- a/bank-api-library/library/src/main/java/net/gini/android/bank/api/TrackingAnalysisService.kt +++ b/bank-api-library/library/src/main/java/net/gini/android/bank/api/TrackingAnalysisService.kt @@ -5,10 +5,19 @@ import net.gini.android.core.api.DocumentService import okhttp3.ResponseBody import retrofit2.Response import retrofit2.http.Body +import retrofit2.http.Header +import retrofit2.http.Headers import retrofit2.http.POST -internal interface TrackingAnalysisService: DocumentService { +internal interface TrackingAnalysisService : DocumentService { - @POST("/batch") - suspend fun sendEvents(@Body amplitudeBody: AmplitudeRequestBody): Response + @POST("/events/batch") + @Headers( + "Content-Type: application/vnd.gini.v1.events.amplitude", + "Accept: application/json" + ) + suspend fun sendEvents( + @Header("Authorization") token: String, + @Body amplitudeBody: AmplitudeRequestBody + ): Response } diff --git a/bank-api-library/library/src/main/java/net/gini/android/bank/api/requests/AmplitudeBody.kt b/bank-api-library/library/src/main/java/net/gini/android/bank/api/requests/AmplitudeBody.kt index 87b696fcf..725246229 100644 --- a/bank-api-library/library/src/main/java/net/gini/android/bank/api/requests/AmplitudeBody.kt +++ b/bank-api-library/library/src/main/java/net/gini/android/bank/api/requests/AmplitudeBody.kt @@ -7,7 +7,6 @@ import net.gini.android.bank.api.models.AmplitudeRoot @JsonClass(generateAdapter = true) data class AmplitudeRequestBody( - @Json(name = "api_key") val apiKey: String, @Json(name = "events") val events: List, ) @@ -35,7 +34,6 @@ data class AmplitudeEventBody( internal fun AmplitudeRoot.toAmplitudeRequestBody() = AmplitudeRequestBody( - apiKey = apiKey, events = events.map { it.toAmplitudeEventBody() } ) diff --git a/core-api-library/library/src/main/java/net/gini/android/core/api/internal/GiniCoreAPIBuilder.kt b/core-api-library/library/src/main/java/net/gini/android/core/api/internal/GiniCoreAPIBuilder.kt index 06a207451..5c43bc856 100644 --- a/core-api-library/library/src/main/java/net/gini/android/core/api/internal/GiniCoreAPIBuilder.kt +++ b/core-api-library/library/src/main/java/net/gini/android/core/api/internal/GiniCoreAPIBuilder.kt @@ -315,7 +315,7 @@ abstract class GiniCoreAPIBuilder, G : GiniCoreAPI