Skip to content

Commit

Permalink
Move constants to their own file
Browse files Browse the repository at this point in the history
  • Loading branch information
maxme committed Jan 19, 2024
1 parent b2de8a5 commit 79beb10
Show file tree
Hide file tree
Showing 3 changed files with 17 additions and 4 deletions.
4 changes: 2 additions & 2 deletions gravatar/src/main/java/com/gravatar/GravatarApi.kt
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ package com.gravatar
import android.os.Handler
import android.os.Looper
import android.util.Log
import com.gravatar.GravatarConstants.GRAVATAR_API_BASE_URL
import okhttp3.MultipartBody
import okhttp3.OkHttpClient
import okhttp3.RequestBody.Companion.asRequestBody
Expand All @@ -22,12 +23,11 @@ class GravatarApi(okHttpClient: OkHttpClient? = null) {
retrofit =
Retrofit.Builder().apply {
okHttpClient?.let { client(it) }
baseUrl(API_BASE_URL)
baseUrl(GRAVATAR_API_BASE_URL)
}.build()
}

private companion object {
const val API_BASE_URL = "https://api.gravatar.com/v1/"
const val LOG_TAG = "Gravatar"
}

Expand Down
11 changes: 11 additions & 0 deletions gravatar/src/main/java/com/gravatar/GravatarConstants.kt
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
package com.gravatar

object GravatarConstants {
// Gravatar image / avatar
const val GRAVATAR_IMAGE_BASE_URL = "https://www.gravatar.com/"
const val GRAVATAR_IMAGE_HOST = "www.gravatar.com"
const val GRAVATAR_IMAGE_PATH = "avatar"

// Gravatar API
const val GRAVATAR_API_BASE_URL = "https://api.gravatar.com/v1/"
}
6 changes: 4 additions & 2 deletions gravatar/src/main/java/com/gravatar/GravatarUtils.kt
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
package com.gravatar

import android.net.Uri
import com.gravatar.GravatarConstants.GRAVATAR_IMAGE_HOST
import com.gravatar.GravatarConstants.GRAVATAR_IMAGE_PATH
import java.security.MessageDigest

private fun ByteArray.toHex(): String {
Expand Down Expand Up @@ -30,8 +32,8 @@ fun emailAddressToGravatarUri(
): Uri {
return Uri.Builder()
.scheme("https")
.authority("www.gravatar.com")
.appendPath("avatar")
.authority(GRAVATAR_IMAGE_HOST)
.appendPath(GRAVATAR_IMAGE_PATH)
.appendPath(emailAddressToGravatarHash(email))
.apply {
defaultAvatarImage?.let { appendQueryParameter("d", it.style) }
Expand Down

0 comments on commit 79beb10

Please sign in to comment.