Last active
June 1, 2017 16:16
-
-
Save ScalaWilliam/39d9fc69204a9428b95c to your computer and use it in GitHub Desktop.
Revisions
-
ScalaWilliam revised this gist
Aug 20, 2014 . 1 changed file with 10 additions and 1 deletion.There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode charactersOriginal file line number Diff line number Diff line change @@ -1,5 +1,14 @@ <repositories> <repository> <id>typesafe</id> <name>typesafe-releases</name> <url>http://repo.typesafe.com/typesafe/releases</url> </repository> </repositories> <dependencies> <dependency> <groupId>com.typesafe.play</groupId> <artifactId>play-ws_2.11</artifactId> <version>2.3.3</version> </dependency> </dependencies> -
ScalaWilliam revised this gist
Aug 20, 2014 . 1 changed file with 0 additions and 1 deletion.There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode charactersOriginal file line number Diff line number Diff line change @@ -1,4 +1,3 @@ <dependency> <groupId>com.typesafe.play</groupId> <artifactId>play-ws_2.11</artifactId> -
ScalaWilliam revised this gist
Aug 20, 2014 . 2 changed files with 6 additions and 1 deletion.There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode charactersOriginal file line number Diff line number Diff line change @@ -1,4 +1,3 @@ Here are the first ten Planet Scala titles: Planet Scala Big Data Engineer / Data Scientist at Recruit IT (Full-time) This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode charactersOriginal file line number Diff line number Diff line change @@ -0,0 +1,6 @@ <dependency> <groupId>com.typesafe.play</groupId> <artifactId>play-ws_2.11</artifactId> <version>2.3.3</version> </dependency> -
ScalaWilliam created this gist
Aug 20, 2014 .There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode charactersOriginal file line number Diff line number Diff line change @@ -0,0 +1,62 @@ package com.scalawilliam.example.play import play.api.libs.ws._ /** * Play's Scala WS library is very very cool. Provides you with plenty niceties. * See more: https://www.playframework.com/documentation/2.3.x/ScalaWS * * Unfortunately it by default requires a Play application context. * But you do not necessarily always want that. * * William Narmontas, Scala Consultant, London. UK * https://www.scalawilliam.com/ */ object WSWithoutPlayApp extends App { class StandaloneWSAPI(wsClientConfig: WSClientConfig = DefaultWSClientConfig()) extends WSAPI with java.io.Closeable { import play.api.libs.ws.ning.{NingWSClient, NingAsyncHttpClientConfigBuilder} lazy val configuration = new NingAsyncHttpClientConfigBuilder(wsClientConfig).build() lazy val ningWsClient = new NingWSClient(configuration) override val client: WSClient = ningWsClient override def url(url: String): WSRequestHolder = client.url(url) def close(): Unit = { ningWsClient.close() } } val standaloneWSAPI = new StandaloneWSAPI() // Standard Play-style WSAPI val wsAPI: WSAPI = standaloneWSAPI def holder = { wsAPI.url("http://www.planetscala.com/atom.xml") .withHeaders("Accept" -> "application/xml") .withRequestTimeout(10000) } import scala.concurrent._ import scala.concurrent.duration._ import scala.concurrent.ExecutionContext.Implicits.global import scala.concurrent.Await def getPlanetScalaTitles: Future[Seq[String]] = { holder.get().map(_.xml \\ "title" map (_.text)) } println("Here are the first ten Planet Scala titles:") try { Await.result(getPlanetScalaTitles, 10.seconds) take 10 foreach println } finally { // required, else there'll be threads hanging around // you might not care to do this though. standaloneWSAPI.close() } } This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode charactersOriginal file line number Diff line number Diff line change @@ -0,0 +1,14 @@ Here are the first ten Planet Scala titles: Planet Scala Big Data Engineer / Data Scientist at Recruit IT (Full-time) Functional Jobs: Search 'scala' Mobile Enterprise Integration with Scala, MongoDB and Swagger Janx Spirit Scala: Next Steps Scala 2.11.2 is now available! Scala for Java Developers Relentless Scaling Play 2.3 Applications on OpenShift Process finished with exit code 0