Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- interface AlbumsAPIService {
- @GET("search?")
- suspend fun getAllAlbums(
- @Query("term") term: String = "hate",
- @Query("media") media: String = "music",
- @Query("entity") entityType: String = "album",
- @Query("attribute") attribute: String = "albumTerm"
- ): Response<ITunesResponse>
- }
- class AlbumsRepository @Inject constructor(private val api: AlbumsAPIService) {
- suspend fun getAllAlbums() = api.getAllAlbums()
- }
- class AlbumsViewModel @ViewModelInject constructor(
- private val repository: AlbumsRepository
- ): ViewModel() {
- init {
- getAllAlbums()
- }
- private fun getAllAlbums() {
- viewModelScope.launch {
- val response = repository.getAllAlbums()
- Log.d("ViewModel", response.body()!!.toString())
- }
- }
- }
- data class ITunesResponse(
- val resultCount: Int,
- val albums: List<Album>
- )
- data class Album(
- @field:Json(name = "amgArtistId") val amgArtistId: Int?,
- @field:Json(name = "artistId") val artistId: Int?,
- @field:Json(name = "artistName") val artistName: String?,
- @field:Json(name = "artistViewUrl") val artistViewUrl: String?,
- @field:Json(name = "artworkUrl100") val artworkUrl100: String?,
- @field:Json(name = "artworkUrl60") val artworkUrl60: String?,
- @field:Json(name = "collectionCensoredName") val collectionCensoredName: String?,
- @field:Json(name = "collectionExplicitness") val collectionExplicitness: String?,
- @field:Json(name = "collectionId") val collectionId: Int?,
- @field:Json(name = "collectionName") val collectionName: String?,
- @field:Json(name = "collectionPrice") val collectionPrice: Double?,
- @field:Json(name = "collectionType") val collectionType: String?,
- @field:Json(name = "collectionViewUrl") val collectionViewUrl: String?,
- @field:Json(name = "contentAdvisoryRating") val contentAdvisoryRating: String?,
- @field:Json(name = "copyright") val copyright: String?,
- @field:Json(name = "country") val country: String?,
- @field:Json(name = "currency") val currency: String?,
- @field:Json(name = "primaryGenreName") val primaryGenreName: String?,
- @field:Json(name = "releaseDate") val releaseDate: String?,
- @field:Json(name = "trackCount") val trackCount: Int?,
- @field:Json(name = "wrapperType") val wrapperType: String?
- )
Advertisement
Add Comment
Please, Sign In to add comment