Skip to content

Instantly share code, notes, and snippets.

@kinisoftware
Created July 27, 2019 11:16
Show Gist options
  • Select an option

  • Save kinisoftware/c92dfb19955734e232ae57b0d7e1e27a to your computer and use it in GitHub Desktop.

Select an option

Save kinisoftware/c92dfb19955734e232ae57b0d7e1e27a to your computer and use it in GitHub Desktop.
class TheMovieDBService(private val gson: Gson) {
fun getNowPlayingMovies(locale: String): List<Movie> {
val retrofit = Retrofit.Builder()
.addConverterFactory(GsonConverterFactory.create(gson))
.baseUrl("https://api.themoviedb.org/3/")
.build()
val theMovieDBAPI = retrofit.create(TheMovieDBAPI::class.java)
val upcomings = theMovieDBAPI.getNowPlaying(
System.getenv("TheMovieDBApiKey"),
locale,
1,
getRegion(locale)
)
return upcomings.execute().body().results
}
fun getUpcomings(locale: String): List<Movie> {
val retrofit = Retrofit.Builder()
.addConverterFactory(GsonConverterFactory.create(gson))
.baseUrl("https://api.themoviedb.org/3/")
.build()
val theMovieDBAPI = retrofit.create(TheMovieDBAPI::class.java)
val upcomings = theMovieDBAPI.getUpcomings(
System.getenv("TheMovieDBApiKey"),
locale,
1,
getRegion(locale)
)
return upcomings.execute().body().results
}
private fun getRegion(locale: String) = locale.substringAfter('-')
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment