Skip to content

Commit

Permalink
refactor(osv-client)!: Remove the Server enum
Browse files Browse the repository at this point in the history
Convert `Server.PRODUCTION` to a compile constant and remove the unused
`STAGING` constant to simplify code.

Signed-off-by: Martin Nonnenmacher <martin.nonnenmacher@bosch.com>
  • Loading branch information
mnonnenmacher committed Aug 29, 2024
1 parent 6636764 commit f787654
Showing 1 changed file with 7 additions and 13 deletions.
20 changes: 7 additions & 13 deletions clients/osv/src/main/kotlin/OsvService.kt
Original file line number Diff line number Diff line change
Expand Up @@ -47,32 +47,26 @@ interface OsvService {
companion object {
const val BATCH_REQUEST_MAX_SIZE = 1000

/** The URL of the production server. */
const val PRODUCTION_SERVER_URL = "https://api.osv.dev"

/** The URL of the staging server. */
const val STAGING_SERVER_URL = "https://api-staging.osv.dev"

val JSON = Json { namingStrategy = JsonNamingStrategy.SnakeCase }

fun create(serverUrl: String? = null, client: OkHttpClient? = null): OsvService {
val converterFactory = JSON.asConverterFactory(contentType = "application/json".toMediaType())

return Retrofit.Builder()
.apply { client(client ?: defaultHttpClient()) }
.baseUrl(serverUrl ?: Server.PRODUCTION.url)
.baseUrl(serverUrl ?: PRODUCTION_SERVER_URL)
.addConverterFactory(converterFactory)
.build()
.create(OsvService::class.java)
}
}

enum class Server(val url: String) {
/**
* The production API server.
*/
PRODUCTION("https://api.osv.dev"),

/**
* The staging API server.
*/
STAGING("https://api-staging.osv.dev")
}

/**
* Get the vulnerabilities for the package matched by the given [request].
*/
Expand Down

0 comments on commit f787654

Please sign in to comment.