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

chore: rebuild project due to codegen change #45

Merged
merged 1 commit into from
Nov 9, 2024
Merged
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
1 change: 0 additions & 1 deletion openlayer-java-client-okhttp/build.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,6 @@ plugins {
dependencies {
api(project(":openlayer-java-core"))

implementation("com.google.guava:guava:33.0.0-jre")
implementation("com.squareup.okhttp3:okhttp:4.12.0")

testImplementation(kotlin("test"))
Expand Down
Original file line number Diff line number Diff line change
@@ -1,8 +1,7 @@
package com.openlayer.api.client.okhttp

import com.google.common.collect.ListMultimap
import com.google.common.collect.MultimapBuilder
import com.openlayer.api.core.RequestOptions
import com.openlayer.api.core.http.Headers
import com.openlayer.api.core.http.HttpClient
import com.openlayer.api.core.http.HttpMethod
import com.openlayer.api.core.http.HttpRequest
Expand All @@ -16,7 +15,6 @@ import java.time.Duration
import java.util.concurrent.CompletableFuture
import okhttp3.Call
import okhttp3.Callback
import okhttp3.Headers
import okhttp3.HttpUrl
import okhttp3.HttpUrl.Companion.toHttpUrl
import okhttp3.MediaType
Expand Down Expand Up @@ -95,7 +93,9 @@ private constructor(private val okHttpClient: okhttp3.OkHttpClient, private val
}

val builder = Request.Builder().url(toUrl()).method(method.name, body)
headers.forEach(builder::header)
headers.names().forEach { name ->
headers.values(name).forEach { builder.header(name, it) }
}

return builder.build()
}
Expand All @@ -107,7 +107,9 @@ private constructor(private val okHttpClient: okhttp3.OkHttpClient, private val

val builder = baseUrl.newBuilder()
pathSegments.forEach(builder::addPathSegment)
queryParams.forEach(builder::addQueryParameter)
queryParams.keys().forEach { key ->
queryParams.values(key).forEach { builder.addQueryParameter(key, it) }
}

return builder.toString()
}
Expand All @@ -133,21 +135,18 @@ private constructor(private val okHttpClient: okhttp3.OkHttpClient, private val
return object : HttpResponse {
override fun statusCode(): Int = code

override fun headers(): ListMultimap<String, String> = headers
override fun headers(): Headers = headers

override fun body(): InputStream = body!!.byteStream()

override fun close() = body!!.close()
}
}

private fun Headers.toHeaders(): ListMultimap<String, String> {
val headers =
MultimapBuilder.treeKeys(String.CASE_INSENSITIVE_ORDER)
.arrayListValues()
.build<String, String>()
forEach { pair -> headers.put(pair.first, pair.second) }
return headers
private fun okhttp3.Headers.toHeaders(): Headers {
val headersBuilder = Headers.builder()
forEach { (name, value) -> headersBuilder.put(name, value) }
return headersBuilder.build()
}

companion object {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,8 @@ import com.fasterxml.jackson.databind.json.JsonMapper
import com.openlayer.api.client.OpenlayerClient
import com.openlayer.api.client.OpenlayerClientImpl
import com.openlayer.api.core.ClientOptions
import com.openlayer.api.core.http.Headers
import com.openlayer.api.core.http.QueryParams
import java.net.Proxy
import java.time.Clock
import java.time.Duration
Expand Down Expand Up @@ -36,6 +38,8 @@ class OpenlayerOkHttpClient private constructor() {

fun clock(clock: Clock) = apply { clientOptions.clock(clock) }

fun headers(headers: Headers) = apply { clientOptions.headers(headers) }

fun headers(headers: Map<String, Iterable<String>>) = apply {
clientOptions.headers(headers)
}
Expand All @@ -46,11 +50,73 @@ class OpenlayerOkHttpClient private constructor() {
clientOptions.putHeaders(name, values)
}

fun putAllHeaders(headers: Headers) = apply { clientOptions.putAllHeaders(headers) }

fun putAllHeaders(headers: Map<String, Iterable<String>>) = apply {
clientOptions.putAllHeaders(headers)
}

fun removeHeader(name: String) = apply { clientOptions.removeHeader(name) }
fun replaceHeaders(name: String, value: String) = apply {
clientOptions.replaceHeaders(name, value)
}

fun replaceHeaders(name: String, values: Iterable<String>) = apply {
clientOptions.replaceHeaders(name, values)
}

fun replaceAllHeaders(headers: Headers) = apply { clientOptions.replaceAllHeaders(headers) }

fun replaceAllHeaders(headers: Map<String, Iterable<String>>) = apply {
clientOptions.replaceAllHeaders(headers)
}

fun removeHeaders(name: String) = apply { clientOptions.removeHeaders(name) }

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

fun queryParams(queryParams: QueryParams) = apply { clientOptions.queryParams(queryParams) }

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

fun putQueryParam(key: String, value: String) = apply {
clientOptions.putQueryParam(key, value)
}

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

fun putAllQueryParams(queryParams: QueryParams) = apply {
clientOptions.putAllQueryParams(queryParams)
}

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

fun replaceQueryParams(key: String, value: String) = apply {
clientOptions.replaceQueryParams(key, value)
}

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

fun replaceAllQueryParams(queryParams: QueryParams) = apply {
clientOptions.replaceAllQueryParams(queryParams)
}

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

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

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

fun timeout(timeout: Duration) = apply { this.timeout = timeout }

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,8 @@ import com.fasterxml.jackson.databind.json.JsonMapper
import com.openlayer.api.client.OpenlayerClientAsync
import com.openlayer.api.client.OpenlayerClientAsyncImpl
import com.openlayer.api.core.ClientOptions
import com.openlayer.api.core.http.Headers
import com.openlayer.api.core.http.QueryParams
import java.net.Proxy
import java.time.Clock
import java.time.Duration
Expand Down Expand Up @@ -36,6 +38,8 @@ class OpenlayerOkHttpClientAsync private constructor() {

fun clock(clock: Clock) = apply { clientOptions.clock(clock) }

fun headers(headers: Headers) = apply { clientOptions.headers(headers) }

fun headers(headers: Map<String, Iterable<String>>) = apply {
clientOptions.headers(headers)
}
Expand All @@ -46,11 +50,73 @@ class OpenlayerOkHttpClientAsync private constructor() {
clientOptions.putHeaders(name, values)
}

fun putAllHeaders(headers: Headers) = apply { clientOptions.putAllHeaders(headers) }

fun putAllHeaders(headers: Map<String, Iterable<String>>) = apply {
clientOptions.putAllHeaders(headers)
}

fun removeHeader(name: String) = apply { clientOptions.removeHeader(name) }
fun replaceHeaders(name: String, value: String) = apply {
clientOptions.replaceHeaders(name, value)
}

fun replaceHeaders(name: String, values: Iterable<String>) = apply {
clientOptions.replaceHeaders(name, values)
}

fun replaceAllHeaders(headers: Headers) = apply { clientOptions.replaceAllHeaders(headers) }

fun replaceAllHeaders(headers: Map<String, Iterable<String>>) = apply {
clientOptions.replaceAllHeaders(headers)
}

fun removeHeaders(name: String) = apply { clientOptions.removeHeaders(name) }

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

fun queryParams(queryParams: QueryParams) = apply { clientOptions.queryParams(queryParams) }

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

fun putQueryParam(key: String, value: String) = apply {
clientOptions.putQueryParam(key, value)
}

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

fun putAllQueryParams(queryParams: QueryParams) = apply {
clientOptions.putAllQueryParams(queryParams)
}

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

fun replaceQueryParams(key: String, value: String) = apply {
clientOptions.replaceQueryParams(key, value)
}

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

fun replaceAllQueryParams(queryParams: QueryParams) = apply {
clientOptions.replaceAllQueryParams(queryParams)
}

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

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

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

fun timeout(timeout: Duration) = apply { this.timeout = timeout }

Expand Down
1 change: 0 additions & 1 deletion openlayer-java-core/build.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,6 @@ plugins {
dependencies {
api("com.fasterxml.jackson.core:jackson-core:2.14.3")
api("com.fasterxml.jackson.core:jackson-databind:2.14.3")
api("com.google.guava:guava:33.0.0-jre")

implementation("com.fasterxml.jackson.core:jackson-annotations:2.14.3")
implementation("com.fasterxml.jackson.datatype:jackson-datatype-jdk8:2.14.3")
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ constructor(
) : OpenlayerClientAsync {

private val clientOptionsWithUserAgent =
if (clientOptions.headers.containsKey("User-Agent")) clientOptions
if (clientOptions.headers.names().contains("User-Agent")) clientOptions
else
clientOptions
.toBuilder()
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ constructor(
) : OpenlayerClient {

private val clientOptionsWithUserAgent =
if (clientOptions.headers.containsKey("User-Agent")) clientOptions
if (clientOptions.headers.names().contains("User-Agent")) clientOptions
else
clientOptions
.toBuilder()
Expand Down
Loading