Skip to content

Commit

Permalink
chore: rebuild project due to codegen change (#6)
Browse files Browse the repository at this point in the history
  • Loading branch information
stainless-app[bot] authored and stainless-bot committed Nov 5, 2024
1 parent 265f2f1 commit d36ecb0
Show file tree
Hide file tree
Showing 5 changed files with 70 additions and 43 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@ package com.omnistack.api.core.http

import com.google.common.collect.ArrayListMultimap
import com.google.common.collect.ListMultimap
import com.google.common.collect.Multimap
import com.google.common.collect.MultimapBuilder
import com.omnistack.api.core.toImmutable

Expand All @@ -11,13 +10,13 @@ private constructor(
val method: HttpMethod,
val url: String?,
val pathSegments: List<String>,
val queryParams: ListMultimap<String, String>,
val headers: ListMultimap<String, String>,
val queryParams: ListMultimap<String, String>,
val body: HttpRequestBody?,
) {

override fun toString(): String =
"HttpRequest{method=$method, pathSegments=$pathSegments, queryParams=$queryParams, headers=$headers, body=$body}"
"HttpRequest{method=$method, url=$url, pathSegments=$pathSegments, headers=$headers, queryParams=$queryParams, body=$body}"

companion object {
fun builder() = Builder()
Expand All @@ -27,65 +26,93 @@ private constructor(

private var method: HttpMethod? = null
private var url: String? = null
private var pathSegments: MutableList<String> = ArrayList()
private var queryParams: ListMultimap<String, String> = ArrayListMultimap.create()
private var body: HttpRequestBody? = null
private var pathSegments: MutableList<String> = mutableListOf()
private var headers: ListMultimap<String, String> =
MultimapBuilder.treeKeys(String.CASE_INSENSITIVE_ORDER).arrayListValues().build()
private var queryParams: ListMultimap<String, String> = ArrayListMultimap.create()
private var body: HttpRequestBody? = null

fun method(method: HttpMethod) = apply { this.method = method }

fun url(url: String) = apply { this.url = url }

fun addPathSegment(pathSegment: String) = apply { this.pathSegments.add(pathSegment) }
fun addPathSegment(pathSegment: String) = apply { pathSegments.add(pathSegment) }

fun addPathSegments(vararg pathSegments: String) = apply {
for (pathSegment in pathSegments) {
this.pathSegments.add(pathSegment)
}
this.pathSegments.addAll(pathSegments)
}

fun putQueryParam(name: String, value: String) = apply {
this.queryParams.replaceValues(name, listOf(value))
fun headers(headers: Map<String, Iterable<String>>) = apply {
this.headers.clear()
putAllHeaders(headers)
}

fun putQueryParams(name: String, values: Iterable<String>) = apply {
this.queryParams.replaceValues(name, values)
fun putHeader(name: String, value: String) = apply { headers.put(name, value) }

fun putHeaders(name: String, values: Iterable<String>) = apply {
headers.putAll(name, values)
}

fun putAllQueryParams(queryParams: Map<String, Iterable<String>>) = apply {
queryParams.forEach(this::putQueryParams)
fun putAllHeaders(headers: Map<String, Iterable<String>>) = apply {
headers.forEach(::putHeaders)
}

fun putAllQueryParams(queryParams: Multimap<String, String>) = apply {
queryParams.asMap().forEach(this::putQueryParams)
fun replaceHeaders(name: String, value: String) = apply {
headers.replaceValues(name, listOf(value))
}

fun putHeader(name: String, value: String) = apply {
this.headers.replaceValues(name, listOf(value))
fun replaceHeaders(name: String, values: Iterable<String>) = apply {
headers.replaceValues(name, values)
}

fun putHeaders(name: String, values: Iterable<String>) = apply {
this.headers.replaceValues(name, values)
fun replaceAllHeaders(headers: Map<String, Iterable<String>>) = apply {
headers.forEach(::replaceHeaders)
}

fun putAllHeaders(headers: Map<String, Iterable<String>>) = apply {
headers.forEach(this::putHeaders)
fun removeHeaders(name: String) = apply { headers.removeAll(name) }

fun removeAllHeaders(names: Set<String>) = apply { names.forEach(::removeHeaders) }

fun queryParams(queryParams: Map<String, Iterable<String>>) = apply {
this.queryParams.clear()
putAllQueryParams(queryParams)
}

fun putAllHeaders(headers: Multimap<String, String>) = apply {
headers.asMap().forEach(this::putHeaders)
fun putQueryParam(key: String, value: String) = apply { queryParams.put(key, value) }

fun putQueryParams(key: String, values: Iterable<String>) = apply {
queryParams.putAll(key, values)
}

fun putAllQueryParams(queryParams: Map<String, Iterable<String>>) = apply {
queryParams.forEach(::putQueryParams)
}

fun replaceQueryParams(key: String, value: String) = apply {
queryParams.replaceValues(key, listOf(value))
}

fun replaceQueryParams(key: String, values: Iterable<String>) = apply {
queryParams.replaceValues(key, values)
}

fun replaceAllQueryParams(queryParams: Map<String, Iterable<String>>) = apply {
queryParams.forEach(::replaceQueryParams)
}

fun removeQueryParams(key: String) = apply { queryParams.removeAll(key) }

fun removeAllQueryParams(keys: Set<String>) = apply { keys.forEach(::removeQueryParams) }

fun body(body: HttpRequestBody) = apply { this.body = body }

fun build(): HttpRequest =
HttpRequest(
checkNotNull(method) { "`method` is required but was not set" },
url,
pathSegments.toImmutable(),
queryParams.toImmutable(),
headers,
queryParams.toImmutable(),
body,
)
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -35,10 +35,10 @@ constructor(
HttpRequest.builder()
.method(HttpMethod.POST)
.addPathSegments("completions")
.putAllQueryParams(clientOptions.queryParams)
.putAllQueryParams(params.getQueryParams())
.putAllHeaders(clientOptions.headers)
.putAllHeaders(params.getHeaders())
.putAllQueryParams(clientOptions.queryParams.asMap())
.replaceAllQueryParams(params.getQueryParams())
.putAllHeaders(clientOptions.headers.asMap())
.replaceAllHeaders(params.getHeaders())
.body(json(clientOptions.jsonMapper, params.getBody()))
.build()
return clientOptions.httpClient.executeAsync(request, requestOptions).let { response ->
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -35,10 +35,10 @@ constructor(
HttpRequest.builder()
.method(HttpMethod.POST)
.addPathSegments("chat", "completions")
.putAllQueryParams(clientOptions.queryParams)
.putAllQueryParams(params.getQueryParams())
.putAllHeaders(clientOptions.headers)
.putAllHeaders(params.getHeaders())
.putAllQueryParams(clientOptions.queryParams.asMap())
.replaceAllQueryParams(params.getQueryParams())
.putAllHeaders(clientOptions.headers.asMap())
.replaceAllHeaders(params.getHeaders())
.body(json(clientOptions.jsonMapper, params.getBody()))
.build()
return clientOptions.httpClient.executeAsync(request, requestOptions).let { response ->
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -35,10 +35,10 @@ constructor(
HttpRequest.builder()
.method(HttpMethod.POST)
.addPathSegments("completions")
.putAllQueryParams(clientOptions.queryParams)
.putAllQueryParams(params.getQueryParams())
.putAllHeaders(clientOptions.headers)
.putAllHeaders(params.getHeaders())
.putAllQueryParams(clientOptions.queryParams.asMap())
.replaceAllQueryParams(params.getQueryParams())
.putAllHeaders(clientOptions.headers.asMap())
.replaceAllHeaders(params.getHeaders())
.body(json(clientOptions.jsonMapper, params.getBody()))
.build()
return clientOptions.httpClient.execute(request, requestOptions).let { response ->
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -35,10 +35,10 @@ constructor(
HttpRequest.builder()
.method(HttpMethod.POST)
.addPathSegments("chat", "completions")
.putAllQueryParams(clientOptions.queryParams)
.putAllQueryParams(params.getQueryParams())
.putAllHeaders(clientOptions.headers)
.putAllHeaders(params.getHeaders())
.putAllQueryParams(clientOptions.queryParams.asMap())
.replaceAllQueryParams(params.getQueryParams())
.putAllHeaders(clientOptions.headers.asMap())
.replaceAllHeaders(params.getHeaders())
.body(json(clientOptions.jsonMapper, params.getBody()))
.build()
return clientOptions.httpClient.execute(request, requestOptions).let { response ->
Expand Down

0 comments on commit d36ecb0

Please sign in to comment.