Skip to content
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
2 changes: 1 addition & 1 deletion .release-please-manifest.json
Original file line number Diff line number Diff line change
@@ -1,3 +1,3 @@
{
".": "0.2.0"
".": "0.3.0"
}
6 changes: 3 additions & 3 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@

<!-- x-release-please-start-version -->

[![Maven Central](https://img.shields.io/maven-central/v/com.withorb.api/orb-java)](https://central.sonatype.com/artifact/com.withorb.api/orb-java/0.2.0)
[![Maven Central](https://img.shields.io/maven-central/v/com.withorb.api/orb-java)](https://central.sonatype.com/artifact/com.withorb.api/orb-java/0.3.0)

<!-- x-release-please-end -->

Expand All @@ -25,7 +25,7 @@ The REST API documentation can be found on [docs.withorb.com](https://docs.with
<!-- x-release-please-start-version -->

```kotlin
implementation("com.withorb.api:orb-java:0.2.0")
implementation("com.withorb.api:orb-java:0.3.0")
```

#### Maven
Expand All @@ -34,7 +34,7 @@ implementation("com.withorb.api:orb-java:0.2.0")
<dependency>
<groupId>com.withorb.api</groupId>
<artifactId>orb-java</artifactId>
<version>0.2.0</version>
<version>0.3.0</version>
</dependency>
```

Expand Down
2 changes: 1 addition & 1 deletion build.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ plugins {

allprojects {
group = "com.withorb.api"
version = "0.2.0" // x-release-please-version
version = "0.3.0" // x-release-please-version
}


Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,21 @@ class OrbOkHttpClient private constructor() {
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: 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: Map<String, Iterable<String>>) = apply {
clientOptions.queryParams(queryParams)
Expand All @@ -68,7 +82,23 @@ class OrbOkHttpClient private constructor() {
clientOptions.putAllQueryParams(queryParams)
}

fun removeQueryParam(key: String) = apply { clientOptions.removeQueryParam(key) }
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: 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 @@ -50,7 +50,21 @@ class OrbOkHttpClientAsync private constructor() {
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: 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: Map<String, Iterable<String>>) = apply {
clientOptions.queryParams(queryParams)
Expand All @@ -68,7 +82,23 @@ class OrbOkHttpClientAsync private constructor() {
clientOptions.putAllQueryParams(queryParams)
}

fun removeQueryParam(key: String) = apply { clientOptions.removeQueryParam(key) }
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: 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 @@ -86,7 +86,21 @@ private constructor(
headers.forEach(::putHeaders)
}

fun removeHeader(name: String) = apply { headers.removeAll(name) }
fun replaceHeaders(name: String, value: String) = apply {
headers.replaceValues(name, listOf(value))
}

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

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

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()
Expand All @@ -103,7 +117,21 @@ private constructor(
queryParams.forEach(::putQueryParams)
}

fun removeQueryParam(key: String) = apply { queryParams.removeAll(key) }
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 responseValidation(responseValidation: Boolean) = apply {
this.responseValidation = responseValidation
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@ package com.withorb.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.withorb.api.core.toImmutable

Expand All @@ -11,13 +10,13 @@ private constructor(
@get:JvmName("method") val method: HttpMethod,
@get:JvmName("url") val url: String?,
@get:JvmName("pathSegments") val pathSegments: List<String>,
@get:JvmName("queryParams") val queryParams: ListMultimap<String, String>,
@get:JvmName("headers") val headers: ListMultimap<String, String>,
@get:JvmName("queryParams") val queryParams: ListMultimap<String, String>,
@get:JvmName("body") 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 {
@JvmStatic 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
Loading