SuperXtra / githubApi

0 stars 0 forks source link

Use custom config class #2

Open patrykcelinski opened 4 years ago

patrykcelinski commented 4 years ago

https://github.com/SuperXtra/githubApi/blob/9f55aed6b5491cfd8849cc0dfd6a36333d144756/app/com/scalac/service/CallExternalApi.scala#L20

Use pureconfig.

Create

case class GithubApiConfig(
                            ghToken: String,
                            baseUrl: String
                          )

In application.conf

{
  gh-token: "e0b8a7575abb45507853143c6e9f9f8743141a26"
  base-url: "https://api.github.com"
}

Then in GithubApiModule you can have:

val githubApiConfig = ConfigSource.defaultApplication.loadOrThrow[GithubApiConfig]
bind(classOf[GithubApiConfig]).toInstance(githubApiConfig)

and inject it to service:

class GetOrganisationContributors @Inject()(ws: WSClient, githubApiConfig: GithubApiConfig) {
patrykcelinski commented 4 years ago

Forgot that you need these imports in GithubApiModule or you will swear at pureconfig and me.

import pureconfig._
import pureconfig.generic.auto._