<commit_before>import com.github.scribejava.apis.GoogleApi20
import com.github.scribejava.core.builder.ServiceBuilder
import com.github.scribejava.core.model.OAuth2AccessToken
import com.github.scribejava.core.model.OAuthRequest
import com.github.scribejava.core.model.Response
import com.github.scribejava.core.model.Verb
import com.github.scribejava.core.oauth.OAuth20Service

object GoogleApiClient {

  val google: OAuth20Service =
    new ServiceBuilder(sys.env("GOOGLE_OAUTH_CLIENT_ID"))
      .apiSecret(sys.env("GOOGLE_OAUTH_CLIENT_SECRET"))
      .callback("https://oauthed.herokuapp.com/google/callback")
      .build(GoogleApi20.instance())

  def getProfile(accessToken: OAuth2AccessToken): Either[String,Profile] = {

    import argonaut._
    import argonaut.Argonaut._

    val request: OAuthRequest =
      new OAuthRequest( Verb.GET
                      , "https://www.googleapis.com/oauth2/v2/userinfo?fields=email%2Cname"
                      )
    google.signRequest(accessToken, request)
    val response: Response = google.execute(request)

    implicit val decodeProfile: DecodeJson[Profile] =
      DecodeJson {
        (c: HCursor) =>
          for {
            name  <- (c --\ "name").as[String]
            email <- (c --\ "email").as[String]
          } yield Profile( name = name
                         , email = email
                         )
      }
    response.getBody().decodeEither[Profile]
  }

}<commit_msg>Document Google OAuth2 scopes and API<commit_after>import argonaut.Argonaut._
import argonaut._
import com.github.scribejava.apis.GoogleApi20
import com.github.scribejava.core.builder.ServiceBuilder
import com.github.scribejava.core.model.OAuth2AccessToken
import com.github.scribejava.core.model.OAuthRequest
import com.github.scribejava.core.model.Response
import com.github.scribejava.core.model.Verb
import com.github.scribejava.core.oauth.OAuth20Service

object GoogleApiClient {

  val google: OAuth20Service =
    new ServiceBuilder(sys.env("GOOGLE_OAUTH_CLIENT_ID"))
      .apiSecret(sys.env("GOOGLE_OAUTH_CLIENT_SECRET"))
      .callback("https://oauthed.herokuapp.com/google/callback")
      .build(GoogleApi20.instance())

  def getProfile(accessToken: OAuth2AccessToken): Either[String,Profile] = {

    /*
     * Scopes needed:
     * - https://www.googleapis.com/auth/userinfo.email
     * - https://www.googleapis.com/auth/userinfo.profile
     *
     * See also:
     * - https://developers.google.com/identity/protocols/googlescopes
     * - https://developers.google.com/apis-explorer/#p/oauth2/v2/oauth2.userinfo.get
     */

    val request: OAuthRequest =
      new OAuthRequest( Verb.GET
                      , "https://www.googleapis.com/oauth2/v2/userinfo?fields=email%2Cname"
                      )
    google.signRequest(accessToken, request)
    val response: Response = google.execute(request)

    implicit val decodeProfile: DecodeJson[Profile] =
      DecodeJson {
        (c: HCursor) =>
          for {
            name  <- (c --\ "name").as[String]
            email <- (c --\ "email").as[String]
          } yield Profile( name = name
                         , email = email
                         )
      }
    response.getBody().decodeEither[Profile]
  }

}
{'fraction_non_alphanumeric': 0.11723076923076924, 'fraction_numerical': 0.009230769230769232, 'mean_word_length': 2.702733485193622, 'pattern_counts': {'":': 0, '<': 7, '<?xml version=': 0, '>': 5, 'https://': 8, 'lorem ipsum': 0, 'www.': 4, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '6343317', 'n_tokens_mistral': 1023, 'n_tokens_neox': 978, 'n_words': 145}