@@ -40,17 +40,18 @@ private val REQUEST_ID_CHARACTERS = ('a'..'z') + ('A'..'Z') + ('0'..'9')
4040
4141class ApiClientHelper private constructor(
4242 private val apiServerDomain : ApiServerDomain ,
43- private val credentials : ApiCredentials ,
43+ private val credentials : ApiCredentials ? ,
4444 private val loggingSettings : LoggingSettings ,
4545 val httpTransport : HttpTransport ,
46- val jsonTransformer : JsonTransformer
46+ val jsonTransformer : JsonTransformer ,
47+ private val requestKind : RequestKind ? = null ,
4748) {
4849
4950 private val log = Logger .getLogger(this ::class .qualifiedName)
5051
5152 constructor (
5253 apiServerDomain: ApiServerDomain ,
53- storeCredentials: ApiStoreCredentials ,
54+ storeCredentials: ApiStoreCredentials ? = null ,
5455 loggingSettings: LoggingSettings ,
5556 httpTransport: HttpTransport ,
5657 jsonTransformerProvider: JsonTransformerProvider
@@ -64,7 +65,7 @@ class ApiClientHelper private constructor(
6465
6566 constructor (
6667 apiServerDomain: ApiServerDomain ,
67- credentials: ApiCredentials ,
68+ credentials: ApiCredentials ? = null ,
6869 loggingSettings: LoggingSettings ,
6970 httpTransport: HttpTransport ,
7071 jsonTransformerProvider: JsonTransformerProvider
@@ -76,6 +77,22 @@ class ApiClientHelper private constructor(
7677 jsonTransformer = jsonTransformerProvider.build(createPolymorphicTypeList())
7778 )
7879
80+ constructor (
81+ apiServerDomain: ApiServerDomain ,
82+ credentials: ApiCredentials ? = null ,
83+ loggingSettings: LoggingSettings ,
84+ httpTransport: HttpTransport ,
85+ jsonTransformerProvider: JsonTransformerProvider ,
86+ requestKind: RequestKind ? ,
87+ ) : this (
88+ apiServerDomain = apiServerDomain,
89+ credentials = credentials,
90+ loggingSettings = loggingSettings,
91+ httpTransport = httpTransport,
92+ jsonTransformer = jsonTransformerProvider.build(createPolymorphicTypeList()),
93+ requestKind = requestKind,
94+ )
95+
7996 @PublishedApi
8097 internal fun <V > makeRequestInt (request : ApiRequest , responseParser : ResponseParser <V >, responseFieldsOverride : ResponseFields ? = null): V {
8198 val requestId = generateRequestId()
@@ -260,8 +277,17 @@ class ApiClientHelper private constructor(
260277 internal fun RequestInfo.toHttpRequest (requestId : String , responseFieldsOverride : ResponseFields ? ): HttpRequest {
261278 val uri = createApiEndpointUri(pathSegments)
262279 val params = if (responseFieldsOverride != null ) params.withResponseFieldsParam(responseFieldsOverride) else params
263- val headers = headers.withRequestId(requestId).withCredentials(credentials)
264-
280+ val headers = headers.withRequestId(requestId).let {
281+ if (requestKind != null ) {
282+ it.withRequestKind(requestKind)
283+ } else {
284+ if (credentials != null ) {
285+ it.withCredentials(credentials)
286+ } else {
287+ it
288+ }
289+ }
290+ }
265291 return when (method) {
266292 HttpMethod .GET -> HttpRequest .HttpGetRequest (
267293 uri = uri,
@@ -302,7 +328,12 @@ class ApiClientHelper private constructor(
302328 null ,
303329 null
304330 )
305- val encodedPath = buildBaseEndpointPath(credentials) + " /" + buildEndpointPath(pathSegments)
331+
332+ val encodedPath = if (requestKind != null ) {
333+ requestKind.buildBaseEndpointPath() + " /" + buildEndpointPath(pathSegments)
334+ } else {
335+ credentials?.let { buildBaseEndpointPath(it) } + " /" + buildEndpointPath(pathSegments)
336+ }
306337 return uri.toString() + encodedPath
307338 }
308339
@@ -443,6 +474,11 @@ internal fun Map<String, String>.withCredentials(credentials: ApiCredentials) =
443474 is ApiAppCredentials -> withAppCredentialsHeaders(credentials)
444475}
445476
477+ @PublishedApi
478+ internal fun Map <String , String >.withRequestKind (requestKind : RequestKind ) = toMutableMap().apply {
479+ putAll(requestKind.buildHeaders())
480+ }
481+
446482internal fun Map <String , String >.withResponseFieldsParam (responseFields : ResponseFields ): Map <String , String > {
447483 return if (responseFields.isAll()) {
448484 this - RESPONSE_FIELDS_PARAM_NAME
0 commit comments