Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feature(bank-sdk): Amplitude. Changed API url to Gini proxy #638

Open
wants to merge 1 commit into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -62,8 +62,10 @@ class BankApiDocumentRepository(
}

suspend fun sendEvents(amplitudeRoot: AmplitudeRoot): Resource<Unit> =
wrapInResource {
trackingAnalysisRemoteSource.sendEvents(amplitudeRoot)
withAccessToken { accessToken ->
wrapInResource {
trackingAnalysisRemoteSource.sendEvents(accessToken, amplitudeRoot)
}
}


Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand All @@ -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()
)
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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<ResponseBody>
@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<ResponseBody>
}
Original file line number Diff line number Diff line change
Expand Up @@ -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<AmplitudeEventBody>,
)

Expand Down Expand Up @@ -35,7 +34,6 @@ data class AmplitudeEventBody(


internal fun AmplitudeRoot.toAmplitudeRequestBody() = AmplitudeRequestBody(
apiKey = apiKey,
events = events.map { it.toAmplitudeEventBody() }
)

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -315,7 +315,7 @@ abstract class GiniCoreAPIBuilder<DM : DocumentManager<DR, E>, G : GiniCoreAPI<D
@Synchronized
protected fun getTrackingAnalyticsApiRetrofit(): Retrofit {
val retrofit = Retrofit.Builder()
.baseUrl("https://api.eu.amplitude.com")
.baseUrl(getApiBaseUrl()!!)
.addConverterFactory(MoshiConverterFactory.create(getMoshi()))
.client(createOkHttpClient())
.build()
Expand Down
Loading