diff --git a/gravatar-quickeditor/src/main/java/com/gravatar/quickeditor/ui/avatarpicker/AvatarPicker.kt b/gravatar-quickeditor/src/main/java/com/gravatar/quickeditor/ui/avatarpicker/AvatarPicker.kt index 47d0f0e8..c81a25cb 100644 --- a/gravatar-quickeditor/src/main/java/com/gravatar/quickeditor/ui/avatarpicker/AvatarPicker.kt +++ b/gravatar-quickeditor/src/main/java/com/gravatar/quickeditor/ui/avatarpicker/AvatarPicker.kt @@ -65,6 +65,7 @@ import com.gravatar.ui.components.ComponentState import com.yalantis.ucrop.UCrop import kotlinx.coroutines.Dispatchers import kotlinx.coroutines.withContext +import java.net.URI @Composable internal fun AvatarPicker( @@ -201,7 +202,7 @@ private suspend fun AvatarPickerAction.handle( ) { when (this) { is AvatarPickerAction.AvatarSelected -> { - onAvatarSelected(AvatarUpdateResult(avatar.imageUrl.toUri())) + onAvatarSelected(AvatarUpdateResult(avatar.imageUrl.toString().toUri())) snackState.showQESnackbar( message = context.getString(R.string.avatar_selected_confirmation), withDismissAction = true, @@ -302,7 +303,7 @@ private fun AvatarPickerPreview() { emailAvatars = EmailAvatars( avatars = listOf( Avatar { - imageUrl = "/image/url" + imageUrl = URI.create("https://gravatar.com/avatar/test") imageId = "1" rating = Avatar.Rating.G altText = "alt" diff --git a/gravatar-quickeditor/src/main/java/com/gravatar/quickeditor/ui/avatarpicker/AvatarPickerViewModel.kt b/gravatar-quickeditor/src/main/java/com/gravatar/quickeditor/ui/avatarpicker/AvatarPickerViewModel.kt index cd39f9ce..85ad19af 100644 --- a/gravatar-quickeditor/src/main/java/com/gravatar/quickeditor/ui/avatarpicker/AvatarPickerViewModel.kt +++ b/gravatar-quickeditor/src/main/java/com/gravatar/quickeditor/ui/avatarpicker/AvatarPickerViewModel.kt @@ -25,7 +25,6 @@ import kotlinx.coroutines.flow.asStateFlow import kotlinx.coroutines.flow.receiveAsFlow import kotlinx.coroutines.flow.update import kotlinx.coroutines.launch -import java.net.URI internal class AvatarPickerViewModel( private val email: Email, @@ -245,7 +244,7 @@ internal fun Profile.copyAvatar(avatar: Avatar): Profile { hash = this@copyAvatar.hash displayName = this@copyAvatar.displayName profileUrl = this@copyAvatar.profileUrl - avatarUrl = URI.create(avatar.imageUrl) + avatarUrl = avatar.imageUrl avatarAltText = avatar.altText location = this@copyAvatar.location description = this@copyAvatar.description diff --git a/gravatar-quickeditor/src/main/java/com/gravatar/quickeditor/ui/components/AvatarsSection.kt b/gravatar-quickeditor/src/main/java/com/gravatar/quickeditor/ui/components/AvatarsSection.kt index d8712150..b5d4d5e6 100644 --- a/gravatar-quickeditor/src/main/java/com/gravatar/quickeditor/ui/components/AvatarsSection.kt +++ b/gravatar-quickeditor/src/main/java/com/gravatar/quickeditor/ui/components/AvatarsSection.kt @@ -20,6 +20,7 @@ import com.gravatar.quickeditor.ui.avatarpicker.AvatarsSectionUiState import com.gravatar.quickeditor.ui.editor.AvatarPickerContentLayout import com.gravatar.restapi.models.Avatar import com.gravatar.ui.GravatarTheme +import java.net.URI @Composable internal fun AvatarsSection( @@ -89,7 +90,7 @@ private fun AvatarSectionPreview() { avatars = listOf( AvatarUi.Uploaded( avatar = Avatar { - imageUrl = "/image/url" + imageUrl = URI.create("https://gravatar.com/avatar/test") imageId = "1" rating = Avatar.Rating.G altText = "alt" @@ -118,7 +119,7 @@ private fun AvatarSectionGridPreview() { avatars = List(6) { AvatarUi.Uploaded( avatar = Avatar { - imageUrl = "/image/url" + imageUrl = URI.create("https://gravatar.com/avatar/test") imageId = it.toString() rating = Avatar.Rating.G altText = "alt" diff --git a/gravatar-quickeditor/src/main/java/com/gravatar/quickeditor/ui/components/HorizontalAvatarsSection.kt b/gravatar-quickeditor/src/main/java/com/gravatar/quickeditor/ui/components/HorizontalAvatarsSection.kt index 2f232d73..f0ad4482 100644 --- a/gravatar-quickeditor/src/main/java/com/gravatar/quickeditor/ui/components/HorizontalAvatarsSection.kt +++ b/gravatar-quickeditor/src/main/java/com/gravatar/quickeditor/ui/components/HorizontalAvatarsSection.kt @@ -37,6 +37,7 @@ import com.gravatar.quickeditor.ui.avatarpicker.AvatarsSectionUiState import com.gravatar.quickeditor.ui.editor.AvatarPickerContentLayout import com.gravatar.restapi.models.Avatar import com.gravatar.ui.GravatarTheme +import java.net.URI @Composable internal fun HorizontalAvatarsSection( @@ -144,7 +145,7 @@ private fun HorizontalAvatarSectionPreview() { avatars = List(6) { AvatarUi.Uploaded( avatar = Avatar { - imageUrl = "/image/url" + imageUrl = URI.create("https://gravatar.com/avatar/test") imageId = it.toString() rating = Avatar.Rating.G altText = "alt" diff --git a/gravatar-quickeditor/src/main/java/com/gravatar/quickeditor/ui/components/LazyAvatarList.kt b/gravatar-quickeditor/src/main/java/com/gravatar/quickeditor/ui/components/LazyAvatarList.kt index 1d872274..d4425a1a 100644 --- a/gravatar-quickeditor/src/main/java/com/gravatar/quickeditor/ui/components/LazyAvatarList.kt +++ b/gravatar-quickeditor/src/main/java/com/gravatar/quickeditor/ui/components/LazyAvatarList.kt @@ -43,7 +43,7 @@ internal val avatarSize = 96.dp internal fun Avatar(avatar: AvatarUi, onAvatarSelected: (Avatar) -> Unit, modifier: Modifier) { when (avatar) { is AvatarUi.Uploaded -> SelectableAvatar( - imageUrl = avatar.avatar.imageUrl, + imageUrl = avatar.avatar.imageUrl.toString(), isSelected = avatar.isSelected, isLoading = avatar.isLoading, onAvatarClicked = { diff --git a/gravatar-quickeditor/src/main/java/com/gravatar/quickeditor/ui/components/VerticalAvatarsSection.kt b/gravatar-quickeditor/src/main/java/com/gravatar/quickeditor/ui/components/VerticalAvatarsSection.kt index 87c43bd3..ae42e964 100644 --- a/gravatar-quickeditor/src/main/java/com/gravatar/quickeditor/ui/components/VerticalAvatarsSection.kt +++ b/gravatar-quickeditor/src/main/java/com/gravatar/quickeditor/ui/components/VerticalAvatarsSection.kt @@ -37,6 +37,7 @@ import com.gravatar.quickeditor.ui.avatarpicker.AvatarsSectionUiState import com.gravatar.quickeditor.ui.editor.AvatarPickerContentLayout import com.gravatar.restapi.models.Avatar import com.gravatar.ui.GravatarTheme +import java.net.URI @Composable internal fun VerticalAvatarsSection( @@ -183,7 +184,7 @@ private fun VerticalAvatarSectionPreview() { avatars = List(6) { AvatarUi.Uploaded( avatar = Avatar { - imageUrl = "/image/url" + imageUrl = URI.create("https://gravatar.com/avatar/test") imageId = it.toString() rating = Avatar.Rating.G altText = "alt" diff --git a/gravatar-quickeditor/src/test/java/com/gravatar/quickeditor/data/repository/AvatarRepositoryTest.kt b/gravatar-quickeditor/src/test/java/com/gravatar/quickeditor/data/repository/AvatarRepositoryTest.kt index 8480c01e..2a7d3189 100644 --- a/gravatar-quickeditor/src/test/java/com/gravatar/quickeditor/data/repository/AvatarRepositoryTest.kt +++ b/gravatar-quickeditor/src/test/java/com/gravatar/quickeditor/data/repository/AvatarRepositoryTest.kt @@ -21,6 +21,7 @@ import org.junit.Before import org.junit.Rule import org.junit.Test import java.io.File +import java.net.URI class AvatarRepositoryTest { private val testDispatcher = StandardTestDispatcher() @@ -154,7 +155,7 @@ class AvatarRepositoryTest { } private fun createAvatar(id: String, isSelected: Boolean = false) = Avatar { - imageUrl = "/image/url" + imageUrl = URI.create("https://gravatar.com/avatar/test") imageId = id rating = Avatar.Rating.G altText = "alt" diff --git a/gravatar-quickeditor/src/test/java/com/gravatar/quickeditor/ui/avatarpicker/AvatarPickerTest.kt b/gravatar-quickeditor/src/test/java/com/gravatar/quickeditor/ui/avatarpicker/AvatarPickerTest.kt index 461c20c1..1b47c6aa 100644 --- a/gravatar-quickeditor/src/test/java/com/gravatar/quickeditor/ui/avatarpicker/AvatarPickerTest.kt +++ b/gravatar-quickeditor/src/test/java/com/gravatar/quickeditor/ui/avatarpicker/AvatarPickerTest.kt @@ -10,6 +10,7 @@ import com.gravatar.ui.components.ComponentState import com.gravatar.uitestutils.RoborazziTest import org.junit.Test import org.robolectric.annotation.Config +import java.net.URI class AvatarPickerTest : RoborazziTest() { private val profile = defaultProfile( @@ -28,14 +29,14 @@ class AvatarPickerTest : RoborazziTest() { emailAvatars = EmailAvatars( avatars = listOf( Avatar { - imageUrl = "/image/url1" + imageUrl = URI.create("https://gravatar.com/avatar/test") imageId = "1" rating = Avatar.Rating.G altText = "alt" updatedDate = "" }, Avatar { - imageUrl = "/image/url2" + imageUrl = URI.create("https://gravatar.com/avatar/test2") imageId = "2" rating = Avatar.Rating.G altText = "alt" @@ -60,14 +61,14 @@ class AvatarPickerTest : RoborazziTest() { emailAvatars = EmailAvatars( avatars = listOf( Avatar { - imageUrl = "/image/url1" + imageUrl = URI.create("https://gravatar.com/avatar/test") imageId = "1" rating = Avatar.Rating.G altText = "alt" updatedDate = "" }, Avatar { - imageUrl = "/image/url2" + imageUrl = URI.create("https://gravatar.com/avatar/test2") imageId = "2" rating = Avatar.Rating.G altText = "alt" diff --git a/gravatar-quickeditor/src/test/java/com/gravatar/quickeditor/ui/avatarpicker/AvatarPickerViewModelTest.kt b/gravatar-quickeditor/src/test/java/com/gravatar/quickeditor/ui/avatarpicker/AvatarPickerViewModelTest.kt index 3196ba54..8a3561d5 100644 --- a/gravatar-quickeditor/src/test/java/com/gravatar/quickeditor/ui/avatarpicker/AvatarPickerViewModelTest.kt +++ b/gravatar-quickeditor/src/test/java/com/gravatar/quickeditor/ui/avatarpicker/AvatarPickerViewModelTest.kt @@ -30,6 +30,7 @@ import org.junit.Before import org.junit.Rule import org.junit.Test import java.io.File +import java.net.URI class AvatarPickerViewModelTest { private val testDispatcher = StandardTestDispatcher() @@ -550,7 +551,7 @@ class AvatarPickerViewModelTest { ) private fun createAvatar(id: String) = Avatar { - imageUrl = "/image/url" + imageUrl = URI.create("https://gravatar.com/avatar/test") imageId = id rating = Avatar.Rating.G altText = "alt" diff --git a/gravatar-quickeditor/src/test/java/com/gravatar/quickeditor/ui/components/AvatarsSectionTest.kt b/gravatar-quickeditor/src/test/java/com/gravatar/quickeditor/ui/components/AvatarsSectionTest.kt index 296807ad..8d2259dc 100644 --- a/gravatar-quickeditor/src/test/java/com/gravatar/quickeditor/ui/components/AvatarsSectionTest.kt +++ b/gravatar-quickeditor/src/test/java/com/gravatar/quickeditor/ui/components/AvatarsSectionTest.kt @@ -8,6 +8,7 @@ import com.gravatar.restapi.models.Avatar import com.gravatar.uitestutils.RoborazziTest import org.junit.Test import org.robolectric.annotation.Config +import java.net.URI class AvatarsSectionTest : RoborazziTest() { @Test @@ -86,7 +87,7 @@ private fun createAvatarList(size: Int): List { return List(size) { AvatarUi.Uploaded( avatar = Avatar { - imageUrl = "/image/url/$it" + imageUrl = URI.create("https://gravatar.com/avatar/test/$it") imageId = it.toString() rating = Avatar.Rating.G altText = "alt" diff --git a/gravatar/api/gravatar.api b/gravatar/api/gravatar.api index 34d76c82..2f4500f0 100644 --- a/gravatar/api/gravatar.api +++ b/gravatar/api/gravatar.api @@ -166,11 +166,11 @@ public final class com/gravatar/extensions/UserProfileExtensionsKt { } public final class com/gravatar/restapi/models/Avatar { - public synthetic fun (Ljava/lang/String;Ljava/lang/String;Lcom/gravatar/restapi/models/Avatar$Rating;Ljava/lang/String;Ljava/lang/String;Ljava/lang/Boolean;Lkotlin/jvm/internal/DefaultConstructorMarker;)V + public synthetic fun (Ljava/lang/String;Ljava/net/URI;Lcom/gravatar/restapi/models/Avatar$Rating;Ljava/lang/String;Ljava/lang/String;Ljava/lang/Boolean;Lkotlin/jvm/internal/DefaultConstructorMarker;)V public fun equals (Ljava/lang/Object;)Z public final fun getAltText ()Ljava/lang/String; public final fun getImageId ()Ljava/lang/String; - public final fun getImageUrl ()Ljava/lang/String; + public final fun getImageUrl ()Ljava/net/URI; public final fun getRating ()Lcom/gravatar/restapi/models/Avatar$Rating; public final fun getSelected ()Ljava/lang/Boolean; public final fun getUpdatedDate ()Ljava/lang/String; @@ -183,7 +183,7 @@ public final class com/gravatar/restapi/models/Avatar$Builder { public final fun build ()Lcom/gravatar/restapi/models/Avatar; public final fun getAltText ()Ljava/lang/String; public final fun getImageId ()Ljava/lang/String; - public final fun getImageUrl ()Ljava/lang/String; + public final fun getImageUrl ()Ljava/net/URI; public final fun getRating ()Lcom/gravatar/restapi/models/Avatar$Rating; public final fun getSelected ()Ljava/lang/Boolean; public final fun getUpdatedDate ()Ljava/lang/String; @@ -191,8 +191,8 @@ public final class com/gravatar/restapi/models/Avatar$Builder { public final synthetic fun setAltText (Ljava/lang/String;)V public final fun setImageId (Ljava/lang/String;)Lcom/gravatar/restapi/models/Avatar$Builder; public final synthetic fun setImageId (Ljava/lang/String;)V - public final fun setImageUrl (Ljava/lang/String;)Lcom/gravatar/restapi/models/Avatar$Builder; - public final synthetic fun setImageUrl (Ljava/lang/String;)V + public final fun setImageUrl (Ljava/net/URI;)Lcom/gravatar/restapi/models/Avatar$Builder; + public final synthetic fun setImageUrl (Ljava/net/URI;)V public final fun setRating (Lcom/gravatar/restapi/models/Avatar$Rating;)Lcom/gravatar/restapi/models/Avatar$Builder; public final synthetic fun setRating (Lcom/gravatar/restapi/models/Avatar$Rating;)V public final fun setSelected (Ljava/lang/Boolean;)Lcom/gravatar/restapi/models/Avatar$Builder; diff --git a/gravatar/openapi/api-gravatar.json b/gravatar/openapi/api-gravatar.json index 4c225707..d51a67b1 100644 --- a/gravatar/openapi/api-gravatar.json +++ b/gravatar/openapi/api-gravatar.json @@ -68,6 +68,7 @@ "image_url": { "type": "string", "description": "Image URL", + "format": "uri", "examples": [ "https://gravatar.com/userimage/252014526/d38bele5a98a2bbc40df69172a2a8348.jpeg" ] @@ -558,6 +559,7 @@ }, "Error": { "type": "object", + "description": "An error response from the API.", "properties": { "error": { "type": "string", @@ -689,9 +691,9 @@ ], "parameters": [ { - "name": "selected_email", + "name": "selected_email_hash", "in": "query", - "description": "The email address used to determine which avatar is selected. The 'selected' attribute in the avatar list will be set to 'true' for the avatar associated with this email.", + "description": "The sha256 hash of the email address used to determine which avatar is selected. The 'selected' attribute in the avatar list will be set to 'true' for the avatar associated with this email.", "schema": { "type": "string", "default": null diff --git a/gravatar/src/main/java/com/gravatar/restapi/apis/AvatarsApi.kt b/gravatar/src/main/java/com/gravatar/restapi/apis/AvatarsApi.kt index 2aa3bee8..948907bb 100644 --- a/gravatar/src/main/java/com/gravatar/restapi/apis/AvatarsApi.kt +++ b/gravatar/src/main/java/com/gravatar/restapi/apis/AvatarsApi.kt @@ -26,12 +26,12 @@ internal interface AvatarsApi { * Responses: * - 200: Successful retrieval of avatars * - * @param selectedEmail The email address used to determine which avatar is selected. The 'selected' attribute in the avatar list will be set to 'true' for the avatar associated with this email. (optional, default to "null") + * @param selectedEmailHash The sha256 hash of the email address used to determine which avatar is selected. The 'selected' attribute in the avatar list will be set to 'true' for the avatar associated with this email. (optional, default to "null") * @return [kotlin.collections.List] */ @GET("me/avatars") suspend fun getAvatars( - @Query("selected_email") selectedEmail: kotlin.String? = "null", + @Query("selected_email_hash") selectedEmailHash: kotlin.String? = "null", ): Response> /** diff --git a/gravatar/src/main/java/com/gravatar/restapi/models/Avatar.kt b/gravatar/src/main/java/com/gravatar/restapi/models/Avatar.kt index 22a2d383..ecea532d 100644 --- a/gravatar/src/main/java/com/gravatar/restapi/models/Avatar.kt +++ b/gravatar/src/main/java/com/gravatar/restapi/models/Avatar.kt @@ -27,7 +27,7 @@ public class Avatar private constructor( public val imageId: kotlin.String, // Image URL @SerializedName("image_url") - public val imageUrl: kotlin.String, + public val imageUrl: java.net.URI, // Rating associated with the image. @SerializedName("rating") public val rating: Avatar.Rating, @@ -79,7 +79,7 @@ public class Avatar private constructor( // Image URL @set:JvmSynthetic // Hide 'void' setter from Java - public var imageUrl: kotlin.String? = null + public var imageUrl: java.net.URI? = null // Rating associated with the image. @set:JvmSynthetic // Hide 'void' setter from Java @@ -99,7 +99,7 @@ public class Avatar private constructor( public fun setImageId(imageId: kotlin.String?): Builder = apply { this.imageId = imageId } - public fun setImageUrl(imageUrl: kotlin.String?): Builder = apply { this.imageUrl = imageUrl } + public fun setImageUrl(imageUrl: java.net.URI?): Builder = apply { this.imageUrl = imageUrl } public fun setRating(rating: Avatar.Rating?): Builder = apply { this.rating = rating } diff --git a/gravatar/src/main/java/com/gravatar/restapi/models/Error.kt b/gravatar/src/main/java/com/gravatar/restapi/models/Error.kt index ec7a8851..affff12b 100644 --- a/gravatar/src/main/java/com/gravatar/restapi/models/Error.kt +++ b/gravatar/src/main/java/com/gravatar/restapi/models/Error.kt @@ -11,7 +11,7 @@ import com.google.gson.annotations.SerializedName import java.util.Objects /** - * + * An error response from the API. * * @param error The error message * @param code The error code for the error message diff --git a/gravatar/src/main/java/com/gravatar/services/AvatarService.kt b/gravatar/src/main/java/com/gravatar/services/AvatarService.kt index 3da499f0..cb081b2c 100644 --- a/gravatar/src/main/java/com/gravatar/services/AvatarService.kt +++ b/gravatar/src/main/java/com/gravatar/services/AvatarService.kt @@ -69,7 +69,7 @@ public class AvatarService(private val okHttpClient: OkHttpClient? = null) { withContext(GravatarSdkDI.dispatcherIO) { val service = instance.getGravatarV3Service(okHttpClient, oauthToken) - val response = service.getAvatars(selectedEmail = hash.toString()) + val response = service.getAvatars(selectedEmailHash = hash.toString()) if (response.isSuccessful) { response.body() ?: error("Response body is null") diff --git a/gravatar/src/test/java/com/gravatar/services/AvatarServiceTest.kt b/gravatar/src/test/java/com/gravatar/services/AvatarServiceTest.kt index 8e34c878..e7be7c87 100644 --- a/gravatar/src/test/java/com/gravatar/services/AvatarServiceTest.kt +++ b/gravatar/src/test/java/com/gravatar/services/AvatarServiceTest.kt @@ -14,6 +14,7 @@ import org.junit.Rule import org.junit.Test import retrofit2.Response import java.io.File +import java.net.URI class AvatarServiceTest { @get:Rule @@ -24,7 +25,7 @@ class AvatarServiceTest { private val avatar = Avatar { imageId = "id" - imageUrl = "url" + imageUrl = URI.create("https://gravatar.com/avatar/test") selected = false altText = "" rating = Avatar.Rating.G