<commit_before>/*
 * Copyright (C) 2009-2016 Typesafe Inc. <http://www.typesafe.com>
 */
package play.api.libs.ws

import java.io.Closeable
import java.io.File
import java.net.URI
import scala.concurrent.ExecutionContext
import scala.concurrent.Future
import scala.concurrent.duration.Duration
import scala.xml.Elem
import akka.stream.Materializer
import akka.stream.scaladsl.Sink
import akka.stream.scaladsl.Source
import akka.util.ByteString
import play.api.Application
import play.api.http.Writeable
import play.api.libs.json.JsValue
import play.api.libs.iteratee._
import java.io.IOException

/**
 * The WSClient holds the configuration information needed to build a request, and provides a way to get a request holder.
 */
trait WSClient extends Closeable {

  /**
   * The underlying implementation of the client, if any.  You must cast explicitly to the type you want.
   * @tparam T the type you are expecting (i.e. isInstanceOf)
   * @return the backing class.
   */
  def underlying[T]: T

  /**
   * Generates a request holder which can be used to build requests.
   *
   * @param url The base URL to make HTTP requests to.
   * @return a WSRequestHolder
   */
  def url(url: String): WSRequest

  /** Closes this client, and releases underlying resources. */
  @throws[IOException] def close(): Unit
}

/**
 * WSRequestMagnet magnet.  Please see the companion object for implicit definitions.
 *
 * @see <a href="http://spray.io/blog/2012-12-13-the-magnet-pattern/">The magnet pattern</a>
 */
trait WSRequestMagnet {
  def apply(): WSRequest
}

/**
 * Asynchronous API to to query web services, as an http client.
 *
 * Usage example:
 * {{{
 * class MyService @Inject() (ws: WSClient) {
 *   ws.url("http://example.com/feed").get()
 *   ws.url("http://example.com/item").post("content")
 * }
 * }}}
 *
 * When greater flexibility is needed, you can also create clients explicitly and pass them into WS:
 *
 * {{{
 * import play.api.libs.ws._
 * import play.api.libs.ws.ahc._
 * import akka.stream.Materializer
 * import play.api.ApplicationLifecycle
 * import javax.inject.Inject
 * import scala.concurrent.Future
 *
 * class MyService @Inject() (lifecycle: ApplicationLifecycle)(implicit mat: Materializer) {
 *   private val client = new AhcWSClient(new AhcConfigBuilder().build())
 *   client.url("http://example.com/feed").get()
 *   lifecycle.addStopHook(() =>
 *     // Make sure you close the client after use, otherwise you'll leak threads and connections
 *     client.close()
 *     Future.successful(())
 *   }
 * }
 * }}}
 *
 * Or call the client directly:
 *
 * {{{
 * import com.typesafe.config.ConfigFactory
 * import play.api.libs.ws._
 * import play.api.libs.ws.ahc._
 *
 * val configuration = play.api.Configuration(ConfigFactory.parseString(
 * """
 *   |play.ws.ssl.trustManager = ...
 * """.stripMargin))
 * val parser = new DefaultWSConfigParser(configuration, Play.current.classloader)
 * val builder = new AhcConfigBuilder(parser.parse())
 * val secureClient: WSClient = new AhcWSClient(builder.build())
 * val response = secureClient.url("https://secure.com").get()
 * secureClient.close() // must explicitly manage lifecycle
 * }}}
 *
 * The value returned is a {@code Future[WSResponse]}, and you should use Play's asynchronous mechanisms to
 * use this response.
 */
object WS {

  private val wsapiCache = Application.instanceCache[WSAPI]
  protected[play] def wsapi(implicit app: Application): WSAPI = wsapiCache(app)

  import scala.language.implicitConversions

  /**
   * Retrieves or creates underlying HTTP client.  Note that due to the Plugin architecture, an
   * implicit application must be in scope.  Most of the time you will want the current app:
   *
   * {{{
   * import play.api.Play.current
   * val client = WS.client
   * }}}
   */
  def client(implicit app: Application): WSClient = wsapi.client

  /**
   * Prepares a new request using an implicit application.  This creates a default client, which you can then
   * use to construct a request.
   *
   * {{{
   *   import play.api.Play.current
   *   WS.url("http://localhost/").get()
   * }}}
   *
   * @param url the URL to request
   * @param app the implicit application to use.
   */
  def url(url: String)(implicit app: Application): play.api.libs.ws.WSRequest = wsapi(app).url(url)<commit_msg>Deprecate Scala WS object<commit_after>/*
 * Copyright (C) 2009-2016 Typesafe Inc. <http://www.typesafe.com>
 */
package play.api.libs.ws

import java.io.Closeable
import java.io.File
import java.net.URI
import scala.concurrent.ExecutionContext
import scala.concurrent.Future
import scala.concurrent.duration.Duration
import scala.xml.Elem
import akka.stream.Materializer
import akka.stream.scaladsl.Sink
import akka.stream.scaladsl.Source
import akka.util.ByteString
import play.api.Application
import play.api.http.Writeable
import play.api.libs.json.JsValue
import play.api.libs.iteratee._
import java.io.IOException

/**
 * The WSClient holds the configuration information needed to build a request, and provides a way to get a request holder.
 */
trait WSClient extends Closeable {

  /**
   * The underlying implementation of the client, if any.  You must cast explicitly to the type you want.
   * @tparam T the type you are expecting (i.e. isInstanceOf)
   * @return the backing class.
   */
  def underlying[T]: T

  /**
   * Generates a request holder which can be used to build requests.
   *
   * @param url The base URL to make HTTP requests to.
   * @return a WSRequestHolder
   */
  def url(url: String): WSRequest

  /** Closes this client, and releases underlying resources. */
  @throws[IOException] def close(): Unit
}

/**
 * WSRequestMagnet magnet.  Please see the companion object for implicit definitions.
 *
 * @see <a href="http://spray.io/blog/2012-12-13-the-magnet-pattern/">The magnet pattern</a>
 */
trait WSRequestMagnet {
  def apply(): WSRequest
}

/**
 * Asynchronous API to to query web services, as an http client.
 *
 * Usage example:
 * {{{
 * class MyService @Inject() (ws: WSClient) {
 *   ws.url("http://example.com/feed").get()
 *   ws.url("http://example.com/item").post("content")
 * }
 * }}}
 *
 * When greater flexibility is needed, you can also create clients explicitly and pass them into WS:
 *
 * {{{
 * import play.api.libs.ws._
 * import play.api.libs.ws.ahc._
 * import akka.stream.Materializer
 * import play.api.ApplicationLifecycle
 * import javax.inject.Inject
 * import scala.concurrent.Future
 *
 * class MyService @Inject() (lifecycle: ApplicationLifecycle)(implicit mat: Materializer) {
 *   private val client = new AhcWSClient(new AhcConfigBuilder().build())
 *   client.url("http://example.com/feed").get()
 *   lifecycle.addStopHook(() =>
 *     // Make sure you close the client after use, otherwise you'll leak threads and connections
 *     client.close()
 *     Future.successful(())
 *   }
 * }
 * }}}
 *
 * Or call the client directly:
 *
 * {{{
 * import com.typesafe.config.ConfigFactory
 * import play.api.libs.ws._
 * import play.api.libs.ws.ahc._
 *
 * val configuration = play.api.Configuration(ConfigFactory.parseString(
 * """
 *   |play.ws.ssl.trustManager = ...
 * """.stripMargin))
 * val parser = new DefaultWSConfigParser(configuration, Play.current.classloader)
 * val builder = new AhcConfigBuilder(parser.parse())
 * val secureClient: WSClient = new AhcWSClient(builder.build())
 * val response = secureClient.url("https://secure.com").get()
 * secureClient.close() // must explicitly manage lifecycle
 * }}}
 *
 * The value returned is a {@code Future[WSResponse]}, and you should use Play's asynchronous mechanisms to
 * use this response.
 */
@deprecated("Inject WSClient into your component", "2.5.0")
object WS {

  private val wsapiCache = Application.instanceCache[WSAPI]
  protected[play] def wsapi(implicit app: Application): WSAPI = wsapiCache(app)

  import scala.language.implicitConversions

  /**
   * Retrieves or creates underlying HTTP client.  Note that due to the Plugin architecture, an
   * implicit application must be in scope.  Most of the time you will want the current app:
   *
   * {{{
   * import play.api.Play.current
   * val client = WS.client
   * }}}
   */
  @deprecated("Inject WSClient into your component", "2.5.0")
  def client(implicit app: Application): WSClient = wsapi.client

  /**
   * Prepares a new request using an implicit application.  This creates a default client, which you can then
   * use to construct a request.
   *
   * {{{
   *   import play.api.Play.current
   *   WS.url("http://localhost/").get()
   * }}}
   *
   * @param url the URL to request
   * @param app the implicit application to use.
   */
  @deprecated("Inject WSClient into your component", "2.5.0")
  def url(url: String)(implicit app: Application): play.api.libs.ws.WSRequest = wsapi(app).url(url)
{'fraction_non_alphanumeric': 0.12375339981867634, 'fraction_numerical': 0.004646418857660925, 'mean_word_length': 3.6301154249737673, 'pattern_counts': {'":': 0, '<': 9, '<?xml version=': 0, '>': 11, 'https://': 2, 'lorem ipsum': 0, 'www.': 2, 'xml': 2}, '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': '7058379', 'n_tokens_mistral': 2741, 'n_tokens_neox': 2633, 'n_words': 806}