<commit_before>package io.flow.play.clients

import io.flow.play.util.DefaultConfig

import io.flow.user.v0.Client
import io.flow.user.v0.errors.UnitResponse
import io.flow.common.v0.models.User
import scala.concurrent.{ExecutionContext, Future}

object UserClient {

  val AnonymousUserId = "usr-20151006-2"

}

trait UserTokensClient {

  def getUserByToken(
    token: String
  )(implicit ec: ExecutionContext): Future[Option[User]]

}

@javax.inject.Singleton
class DefaultUserTokensClient() extends UserTokensClient {

  // e.g. http://api.flow.io/users
  def host: String = DefaultConfig.requiredString("user.api.host")

  lazy val client = new Client(host)

  def callWith404[T](
    f: Future[T]
  )(implicit ec: ExecutionContext): Future[Option[T]] = {
    f.map {
      value => Some(value)
    }.recover {
      case UnitResponse(404) => None
      case ex: Throwable => throw ex
    }
  }

  /**
    * Blocking call to fetch a user by API Token.
    */
  def getUserByToken(
    token: String
  )(implicit ec: ExecutionContext): Future[Option[User]] = {
    callWith404( client.users.getTokensByToken(token) )
  }

}
<commit_msg>Add system user and wrap users in UserReference<commit_after>package io.flow.play.clients

import io.flow.play.util.DefaultConfig

import io.flow.user.v0.Client
import io.flow.user.v0.errors.UnitResponse
import io.flow.common.v0.models.{User, UserReference}
import scala.concurrent.{ExecutionContext, Future}

object UserClient {

  val SystemUser = UserReference("usr-20151006-1")
  val AnonymousUser = UserReference("usr-20151006-2")

}

trait UserTokensClient {

  def getUserByToken(
    token: String
  )(implicit ec: ExecutionContext): Future[Option[User]]

}

@javax.inject.Singleton
class DefaultUserTokensClient() extends UserTokensClient {

  // e.g. http://api.flow.io/users
  def host: String = DefaultConfig.requiredString("user.api.host")

  lazy val client = new Client(host)

  def callWith404[T](
    f: Future[T]
  )(implicit ec: ExecutionContext): Future[Option[T]] = {
    f.map {
      value => Some(value)
    }.recover {
      case UnitResponse(404) => None
      case ex: Throwable => throw ex
    }
  }

  /**
    * Blocking call to fetch a user by API Token.
    */
  def getUserByToken(
    token: String
  )(implicit ec: ExecutionContext): Future[Option[User]] = {
    callWith404( client.users.getTokensByToken(token) )
  }

}

{'fraction_non_alphanumeric': 0.12181894034209428, 'fraction_numerical': 0.02127659574468085, 'mean_word_length': 3.6563106796116505, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 9, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, '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': '6803036', 'n_tokens_mistral': 830, 'n_tokens_neox': 794, 'n_words': 177}