Skip to content
This repository has been archived by the owner on Apr 14, 2024. It is now read-only.

Commit

Permalink
Cleanup
Browse files Browse the repository at this point in the history
  • Loading branch information
yschimke committed Aug 7, 2022
1 parent a2ae3f8 commit cb523e3
Show file tree
Hide file tree
Showing 22 changed files with 30 additions and 30 deletions.
2 changes: 1 addition & 1 deletion src/main/kotlin/com/baulsupp/okurl/Main.kt
Original file line number Diff line number Diff line change
Expand Up @@ -289,7 +289,7 @@ class Main : CommandLineClient() {
)
}

if (isEventStream(response.body?.contentType())) {
if (isEventStream(response.body.contentType())) {
response.handleSseResponse(SseOutput(outputHandler))
} else {
outputHandler.showOutput(response)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -91,7 +91,7 @@ class SimpleWebServer(

@JvmStatic
fun main(args: Array<String>) {
SimpleWebServer.forCode().use { ws ->
forCode().use { ws ->
val s = runBlocking {
ws.waitForCode()
}
Expand Down
8 changes: 4 additions & 4 deletions src/main/kotlin/com/baulsupp/okurl/completion/UrlList.kt
Original file line number Diff line number Diff line change
Expand Up @@ -56,9 +56,9 @@ data class UrlList(val match: Match, val urls: List<String>) {

private fun regex(prefix: String): String {
return when (match) {
UrlList.Match.EXACT -> prefix
UrlList.Match.HOSTS -> "[^/]*:?/?/?[^/]*"
UrlList.Match.SITE -> "$prefix.*"
Match.EXACT -> prefix
Match.HOSTS -> "[^/]*:?/?/?[^/]*"
Match.SITE -> "$prefix.*"
}
}

Expand All @@ -80,7 +80,7 @@ data class UrlList(val match: Match, val urls: List<String>) {
override fun toString() = urls.joinToString("\n")

companion object {
val None = UrlList(UrlList.Match.EXACT, listOf())
val None = UrlList(Match.EXACT, listOf())

fun fromResource(serviceName: String): UrlList? {
return UrlList::class.java.getResource("/urls/$serviceName.txt")?.let {
Expand Down
2 changes: 1 addition & 1 deletion src/main/kotlin/com/baulsupp/okurl/credentials/TokenSet.kt
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ sealed class Token {
val DefaultToken = TokenSet("default")

data class TokenSet(val name: String) : Token() {
override fun name(): String? = name
override fun name(): String = name
}

data class TokenValue(val token: Any) : Token()
Expand Down
4 changes: 2 additions & 2 deletions src/main/kotlin/com/baulsupp/okurl/kotlin/kotlin.kt
Original file line number Diff line number Diff line change
Expand Up @@ -159,7 +159,7 @@ suspend inline fun <reified T> OkHttpClient.queryMapValue(
// TODO
fun HttpUrl.request(): Request = Request.Builder().url(this).build()

suspend fun OkHttpClient.queryForString(request: Request): String = execute(request).body!!.readString()
suspend fun OkHttpClient.queryForString(request: Request): String = execute(request).body.readString()

suspend fun OkHttpClient.queryForString(url: String, tokenSet: Token = DefaultToken): String =
this.queryForString(request(url, tokenSet))
Expand All @@ -173,7 +173,7 @@ suspend fun OkHttpClient.execute(request: Request): Response {
val response = call.await()

if (!response.isSuccessful) {
val responseString = response.body?.readString()
val responseString = response.body.readString()

val msg: String = if (responseString.isNullOrEmpty()) {
response.statusMessage()
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ class OkHttpResponseExtractor : ResponseExtractor<Response> {
override fun mimeType(response: Response): String? {
val host = response.request.url.host

val mediaType = response.body?.contentType()
val mediaType = response.body.contentType()

return when {
host == "graph.facebook.com" && mediaType?.subtype == "javascript" -> JSON.toString()
Expand All @@ -18,7 +18,7 @@ class OkHttpResponseExtractor : ResponseExtractor<Response> {
}
}

override fun source(response: Response): BufferedSource = response.body!!.source()
override fun source(response: Response): BufferedSource = response.body.source()

override fun filename(response: Response): String {
val segments = response.request.url.pathSegments
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ data class FilteredBasicCredentials(val basicCredentials: BasicCredentials, val
return tokens.any { it.matches(url) }
}

fun firstMatch(tokens: Collection<FilteredBasicCredentials>, url: HttpUrl): FilteredBasicCredentials? {
fun firstMatch(tokens: Collection<FilteredBasicCredentials>, url: HttpUrl): FilteredBasicCredentials {
return tokens.first { it.matches(url) }
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -84,7 +84,7 @@ class CoinbaseAuthInterceptor : Oauth2AuthInterceptor() {
return CoinbaseAuthFlow.login(client, outputHandler, clientId, clientSecret, scopes)
}

override suspend fun renew(client: OkHttpClient, credentials: Oauth2Token): Oauth2Token? {
override suspend fun renew(client: OkHttpClient, credentials: Oauth2Token): Oauth2Token {
val body = FormBody.Builder()
.add("client_id", credentials.clientId!!)
.add("client_secret", credentials.clientSecret!!)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,7 @@ class FitbitAuthInterceptor : Oauth2AuthInterceptor() {
)
)

override suspend fun renew(client: OkHttpClient, credentials: Oauth2Token): Oauth2Token? {
override suspend fun renew(client: OkHttpClient, credentials: Oauth2Token): Oauth2Token {
val body = FormBody.Builder().add("grant_type", "refresh_token")
.add("refresh_token", credentials.refreshToken!!)
.build()
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ class GiphyAuthInterceptor : Oauth2AuthInterceptor() {
"https://github.com/Giphy/GiphyAPI", null
)

override fun defaultCredentials(): Oauth2Token? = Oauth2Token("dc6zaTOxFJmzC")
override fun defaultCredentials(): Oauth2Token = Oauth2Token("dc6zaTOxFJmzC")

override suspend fun intercept(chain: Interceptor.Chain, credentials: Oauth2Token): Response {
var request = chain.request()
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -104,7 +104,7 @@ suspend inline fun <reified T> OkHttpClient.queryResponsePages(
val page1 = execute(request(url, tokenSet))

val page1Results = async {
val string = page1.body!!.readString()
val string = page1.body.readString()

@Suppress("BlockingMethodInNonBlockingContext")
Main.moshi.listAdapter<T>().fromJson(string)!!
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,11 +5,11 @@ import com.baulsupp.okurl.services.google.model.Parameter
class DiscoveryParameter(private val name: String, private val parameter: Parameter) {
fun name(): String = name

fun type(): String? = parameter.type
fun type(): String = parameter.type

fun description(): String? = parameter.description

fun location(): String? = parameter.location
fun location(): String = parameter.location

fun pattern(): String? = parameter.pattern
}
Original file line number Diff line number Diff line change
Expand Up @@ -59,7 +59,7 @@ class GoogleAuthInterceptor : Oauth2AuthInterceptor() {
return response
}

override fun authFlow(): AuthFlow<Oauth2Token>? {
override fun authFlow(): AuthFlow<Oauth2Token> {
return GoogleAuthFlow(serviceDefinition)
}

Expand All @@ -82,7 +82,7 @@ class GoogleAuthInterceptor : Oauth2AuthInterceptor() {

override fun canRenew(credentials: Oauth2Token): Boolean = credentials.isRenewable()

override suspend fun renew(client: OkHttpClient, credentials: Oauth2Token): Oauth2Token? {
override suspend fun renew(client: OkHttpClient, credentials: Oauth2Token): Oauth2Token {
val body = FormBody.Builder().add("client_id", credentials.clientId!!)
.add("refresh_token", credentials.refreshToken!!)
.add("client_secret", credentials.clientSecret!!)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ object UpdateDiscoverIndex: CommandLineClient() {
withContext(Dispatchers.IO) {
val discoveryJsonSink =
File("src/main/resources/com/baulsupp/okurl/services/google/discovery.json").sink()
response.body!!.source().writeToSink(discoveryJsonSink)
response.body.source().writeToSink(discoveryJsonSink)
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@ class MapboxAuthInterceptor : Oauth2AuthInterceptor() {
return Oauth2Token(apiKey)
}

override fun defaultCredentials(): Oauth2Token? = Oauth2Token(
override fun defaultCredentials(): Oauth2Token = Oauth2Token(
"pk.eyJ1IjoieXNjaGlta2UiLCJhIjoiY2tlb3E5MWIyMWp4eDJ2azdraWg5cHkxYyJ9.UHmWRzY_VE7gqIjCwIAmNA"
)
}
Original file line number Diff line number Diff line change
Expand Up @@ -58,7 +58,7 @@ class MicrosoftAuthInterceptor : Oauth2AuthInterceptor() {
return MicrosoftAuthFlow.login(client, outputHandler, clientId, clientSecret, scopes)
}

override suspend fun renew(client: OkHttpClient, credentials: Oauth2Token): Oauth2Token? {
override suspend fun renew(client: OkHttpClient, credentials: Oauth2Token): Oauth2Token {

val body = FormBody.Builder().add("grant_type", "refresh_token")
.add("redirect_uri", "http://localhost:3000/callback")
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -99,7 +99,7 @@ class SpotifyAuthInterceptor : Oauth2AuthInterceptor() {
return super.errorMessage(ce)
}

override suspend fun renew(client: OkHttpClient, credentials: Oauth2Token): Oauth2Token? {
override suspend fun renew(client: OkHttpClient, credentials: Oauth2Token): Oauth2Token {
val tokenUrl = "https://accounts.spotify.com/api/token"

val body = FormBody.Builder()
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -61,11 +61,11 @@ class StravaAuthInterceptor : Oauth2AuthInterceptor() {
return false
}

val body = result.body!!.source().peek().readUtf8()
val body = result.body.source().peek().readUtf8()
return body.contains("\"field\":\"access_token\",\"code\":\"invalid\"")
}

override suspend fun renew(client: OkHttpClient, credentials: Oauth2Token): Oauth2Token? {
override suspend fun renew(client: OkHttpClient, credentials: Oauth2Token): Oauth2Token {
val responseMap = client.query<AuthResponse>(request("https://www.strava.com/oauth/token") {
post(form {
add("grant_type", "refresh_token")
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,7 @@ class TravisCIAuthInterceptor : AuthInterceptor<TravisToken>() {

// TODO incorrect response type for errors
if (!response.isSuccessful && response.header("Content-Type") == "application/json") {
val newBody = response.body!!.bytes().toResponseBody(null)
val newBody = response.body.bytes().toResponseBody(null)
response = response.newBuilder().body(newBody).removeHeader("Content-Type").build()
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,6 @@ package com.baulsupp.okurl.services.travisci

data class TravisToken(val token: String? = null) {
companion object {
fun external(): TravisToken? = TravisToken()
fun external(): TravisToken = TravisToken()
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -66,7 +66,7 @@ class UberAuthInterceptor : Oauth2AuthInterceptor() {
override fun hosts(credentialsStore: CredentialsStore): Set<String> =
setOf("api.uber.com", "login.uber.com", "sandbox-api.uber.com")

override suspend fun renew(client: OkHttpClient, credentials: Oauth2Token): Oauth2Token? {
override suspend fun renew(client: OkHttpClient, credentials: Oauth2Token): Oauth2Token {
val tokenUrl = "https://login.uber.com/oauth/v2/token"

val body = FormBody.Builder().add("client_id", credentials.clientId!!)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ class UriTransportRegistry(val handlers: List<UriHandler>) {
}

fun forUri(uri: String): Reporter<Span> {
return UriTransportRegistry.fromServices().findClient(uri)
return fromServices().findClient(uri)
}
}
}

0 comments on commit cb523e3

Please sign in to comment.