Skip to content

Instantly share code, notes, and snippets.

@eddie-yim
Created December 23, 2017 12:50
Show Gist options
  • Save eddie-yim/e0af27834f06afdbf654ac71db628f0f to your computer and use it in GitHub Desktop.
Save eddie-yim/e0af27834f06afdbf654ac71db628f0f to your computer and use it in GitHub Desktop.
영화진흥위원회(kobis) Open API를 통한 박스오피스 조회
package controllers
import javax.inject.{Inject, Singleton}
import play.api.libs.ws.{WSClient, WSRequest}
import play.api.mvc._
import scala.concurrent.ExecutionContext
@Singleton
class BoxOfficeController @Inject()(cc: ControllerComponents)(ws: WSClient)(implicit exec: ExecutionContext) extends AbstractController(cc) {
val API_URL = "http://www.kobis.or.kr/kobisopenapi/webservice/rest/boxoffice/searchDailyBoxOfficeList.json"
val KEY = "YOUR_KEY"
def list(date: String) = Action.async { implicit request =>
val wsReq: WSRequest = ws.url(API_URL)
.addHttpHeaders("Application" -> "application/json")
.addQueryStringParameters("key" -> KEY, "targetDt" -> date)
wsReq.get().map { response =>
Ok(response.body).as("application/json")
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment