-
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.
- Loading branch information
1 parent
b4410d1
commit a59e01f
Showing
5 changed files
with
169 additions
and
34 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
69 changes: 69 additions & 0 deletions
69
sample-app/app/src/main/java/com/socure/docv/sdk/sample/Api.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,69 @@ | ||
package com.socure.docv.sdk.sample | ||
|
||
import java.util.concurrent.TimeUnit | ||
import okhttp3.OkHttpClient | ||
import okhttp3.logging.HttpLoggingInterceptor | ||
import retrofit2.Retrofit | ||
import retrofit2.converter.gson.GsonConverterFactory | ||
import retrofit2.http.Body | ||
import retrofit2.http.HeaderMap | ||
import retrofit2.http.POST | ||
|
||
private const val BASE_URL = "https://service.socure.com/" | ||
|
||
fun transaction(): TransactionService { | ||
return Retrofit.Builder() | ||
.baseUrl(BASE_URL) | ||
.addConverterFactory(GsonConverterFactory.create()) | ||
.client(OkHttpBuilder().getBuilder()) | ||
.build().create(TransactionService::class.java) | ||
} | ||
|
||
interface TransactionService { | ||
@POST("api/5.0/documents/request") | ||
suspend fun createTransaction( | ||
@HeaderMap headers: Map<String, String>, | ||
@Body request: TransactionRequest | ||
): TransactionResponse | ||
} | ||
|
||
data class TransactionResponse( | ||
val data: Data | ||
) { | ||
|
||
data class Data( | ||
val eventId: String, | ||
val authToken: String, | ||
val docvTransactionToken: String, | ||
val qrcode: String, | ||
val url: String | ||
) | ||
} | ||
|
||
data class TransactionRequest( | ||
val config: TransactionConfig, | ||
val previousReferenceId: String? = null | ||
) { | ||
|
||
data class TransactionConfig( | ||
val useCaseKey: String, | ||
val language: String = "en" | ||
) | ||
} | ||
|
||
class OkHttpBuilder { | ||
fun getBuilder(): OkHttpClient { | ||
with(OkHttpClient.Builder()) { | ||
readTimeout(120L, TimeUnit.SECONDS) | ||
connectTimeout(120L, TimeUnit.SECONDS) | ||
writeTimeout(120L, TimeUnit.SECONDS) | ||
|
||
if (BuildConfig.DEBUG) { | ||
val loggingInterceptor = HttpLoggingInterceptor() | ||
loggingInterceptor.level = HttpLoggingInterceptor.Level.HEADERS | ||
addInterceptor(loggingInterceptor) | ||
} | ||
return build() | ||
} | ||
} | ||
} |
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