Skip to content

Commit

Permalink
we can't use snip here because of backslash
Browse files Browse the repository at this point in the history
  • Loading branch information
eed3si9n committed May 8, 2018
1 parent 37524a7 commit 3f5fb97
Show file tree
Hide file tree
Showing 2 changed files with 70 additions and 2 deletions.
36 changes: 35 additions & 1 deletion src/reference/00-Getting-Started/02-sbt-by-example.md
Original file line number Diff line number Diff line change
Expand Up @@ -348,7 +348,41 @@ Let's add Play JSON to `helloCore`.

After `reload`, add `core/src/main/scala/example/core/Weather.scala`:

@@snip [example-weather]($root$/src/sbt-test/ref/example-weather/core/src/main/scala/example/core/Weather.scala) {}
```scala
package example.core

import gigahorse._, support.okhttp.Gigahorse
import scala.concurrent._
import play.api.libs.json._

object Weather {
lazy val http = Gigahorse.http(Gigahorse.config)
def weather: Future[String] = {
val r = Gigahorse.url("https://query.yahooapis.com/v1/public/yql").get.
addQueryString(
"q" -> """select item.condition
|from weather.forecast where woeid in (select woeid from geo.places(1) where text='New York, NY')
|and u='c'""".stripMargin,
"format" -> "json"
)

import ExecutionContext.Implicits._
for {
f <- http.run(r, Gigahorse.asString)
x <- parse(f)
} yield x
}

def parse(rawJson: String): Future[String] = {
val js = Json.parse(rawJson)
(js \\\\ "text").headOption match {
case Some(JsString(x)) => Future.successful(x.toLowerCase)
case _ => Future.failed(sys.error(rawJson))
}
}
}

```

Next, change `src/main/scala/example/Hello.scala` as follows:

Expand Down
36 changes: 35 additions & 1 deletion src/reference/ja/00-Getting-Started/02-scala-by-example.md
Original file line number Diff line number Diff line change
Expand Up @@ -342,7 +342,41 @@ sbt:Hello> ~testQuick

`reload` 後、`core/src/main/scala/example/core/Weather.scala` を追加する:

@@snip [example-weather]($root$/src/sbt-test/ref/example-weather/core/src/main/scala/example/core/Weather.scala) {}
```scala
package example.core

import gigahorse._, support.okhttp.Gigahorse
import scala.concurrent._
import play.api.libs.json._

object Weather {
lazy val http = Gigahorse.http(Gigahorse.config)
def weather: Future[String] = {
val r = Gigahorse.url("https://query.yahooapis.com/v1/public/yql").get.
addQueryString(
"q" -> """select item.condition
|from weather.forecast where woeid in (select woeid from geo.places(1) where text='New York, NY')
|and u='c'""".stripMargin,
"format" -> "json"
)

import ExecutionContext.Implicits._
for {
f <- http.run(r, Gigahorse.asString)
x <- parse(f)
} yield x
}

def parse(rawJson: String): Future[String] = {
val js = Json.parse(rawJson)
(js \\\\ "text").headOption match {
case Some(JsString(x)) => Future.successful(x.toLowerCase)
case _ => Future.failed(sys.error(rawJson))
}
}
}

```

次に `src/main/scala/example/Hello.scala` を以下のように変更する:

Expand Down

0 comments on commit 3f5fb97

Please sign in to comment.