Last active
June 30, 2022 13:33
-
-
Save Astroa7m/d923d0cb7545e3ba1eb8c289f1933bbd to your computer and use it in GitHub Desktop.
Remote image service
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
interface RemoteImageService { | |
/** | |
* returns a random image object from unsplash api | |
* @param clientId should be replaced with your client id | |
* which you can obtain it from unsplash api | |
*/ | |
@GET | |
suspend fun getRandomImageObject( | |
@Url unsplashBaseUrl: String = "https://api.unsplash.com/photos/random", | |
@Query("client_id") clientId: String = BuildConfig.CLIENT_ID, | |
@Query("query") query: String | |
): Response<RemoteImage> | |
/** | |
* returns a random image bytes from unsplash api | |
* @param clientId should be replaced with your client id | |
* which you can obtain it from unsplash api | |
*/ | |
@GET | |
suspend fun getRandomImageBytes( | |
@Url imageUrl: String, | |
@Query("client_id") clientId: String = BuildConfig.CLIENT_ID | |
): Response<ResponseBody> | |
companion object{ | |
val serviceInstance: RemoteImageService by lazy { | |
val logging = HttpLoggingInterceptor().apply { | |
level = HttpLoggingInterceptor.Level.BODY | |
} | |
val client = OkHttpClient.Builder().addInterceptor(logging).build() | |
Retrofit.Builder() | |
.client(client) | |
.baseUrl("http://localhost/") | |
.addConverterFactory(GsonConverterFactory.create()) | |
.build() | |
.create(RemoteImageService::class.java) | |
} | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment