diff --git a/.gitignore b/.gitignore index c3cbaee..62780e8 100644 --- a/.gitignore +++ b/.gitignore @@ -4,59 +4,59 @@ # sbt specific .cache .history -*/.lib/ -*/dist/* -*/target/ -*/project/target/* -*/lib_managed/ -*/src_managed/ -*/project/boot/ -*/project/plugins/project/ +**/.lib/ +**/dist/* +**/target/ +**/project/target/* +**/lib_managed/ +**/src_managed/ +**/project/boot/ +**/project/plugins/project/ # Scala-IDE specific -*/.scala_dependencies -*/.worksheet +**/.scala_dependencies +**/.worksheet akka-epl/.idea/ */.idea/ # ENSIME specific -*/.ensime_cache/ -*/.ensime -*/ensime.sbt +**/.ensime_cache/ +**/.ensime +**/ensime.sbt # react .DS_STORE -*/node_modules +**/node_modules *~ *.pyc .grunt -*/_SpecRunner.html -*/__benchmarks__ -*/build/ -*//remote-repo/ -*/coverage/ -*/.module-cache -*/*.gem -*/docs/.bundle -*/docs/code -*/docs/_site -*/docs/.sass-cache -*/docs/js/* -*/docs/downloads/*.zip -*/docs/vendor/bundle -*/fixtures/dom/public/react-dom.js -*/fixtures/dom/public/react.js -*/test/the-files-to-test.generated.js -*/*.log* -*/chrome-user-data -*/*.sublime-project -*/*.sublime-workspace -*/.idea -*/*.iml +**/_SpecRunner.html +**/__benchmarks__ +**/build/ +**//remote-repo/ +**/coverage/ +**/.module-cache +**/*.gem +**/docs/.bundle +**/docs/code +**/docs/_site +**/docs/.sass-cache +**/docs/js/* +**/docs/downloads/*.zip +**/docs/vendor/bundle +**/fixtures/dom/public/react-dom.js +**/fixtures/dom/public/react.js +**/test/the-files-to-test.generated.js +**/*.log* +**/chrome-user-data +**/*.sublime-project +**/*.sublime-workspace +**/.idea +**/*.iml v.vscode -*/*.swp -*/*.swo -*/*react*min*.js -*/!src/node_modules \ No newline at end of file +**/*.swp +**/*.swo +**/*react*min*.js +**/!src/node_modules diff --git a/akka-epl/project/project/target/config-classes/$731f18e1a71d9df9db04.cache b/akka-epl/project/project/target/config-classes/$731f18e1a71d9df9db04.cache deleted file mode 100644 index 0bc0f08..0000000 --- a/akka-epl/project/project/target/config-classes/$731f18e1a71d9df9db04.cache +++ /dev/null @@ -1 +0,0 @@ -sbt.internals.DslEntry \ No newline at end of file diff --git a/akka-epl/src/main/scala/com/epl/akka_v1/Cloudant.scala b/akka-epl/src/main/scala/com/epl/akka_v1/Cloudant.scala new file mode 100644 index 0000000..39e61f5 --- /dev/null +++ b/akka-epl/src/main/scala/com/epl/akka_v1/Cloudant.scala @@ -0,0 +1,12 @@ +package com.epl.akka_v1 + +object Cloudant { + + + + + + + + +} diff --git a/akka-epl/src/main/scala/com/epl/akka_v1/HttpClient.scala b/akka-epl/src/main/scala/com/epl/akka_v1/HttpClient.scala new file mode 100644 index 0000000..7f4736a --- /dev/null +++ b/akka-epl/src/main/scala/com/epl/akka_v1/HttpClient.scala @@ -0,0 +1,85 @@ +package com.epl.akka_v1 + +import akka.actor.ActorSystem +import akka.http.scaladsl.Http +import akka.http.scaladsl.marshalling.Marshal +import akka.http.scaladsl.model.headers.BasicHttpCredentials +import akka.http.scaladsl.model.{HttpMethods, HttpRequest, RequestEntity, headers} +import akka.http.scaladsl.unmarshalling.Unmarshal +import akka.stream.ActorMaterializer +import akka.util.ByteString +import com.epl.akka.DocumentType + +import scala.concurrent.Future + +object HttpClient { + + implicit val system = ActorSystem() + implicit val materializer = ActorMaterializer() + implicit val ec = system.dispatcher + + final val config = system.settings.config + + private val authorization = headers.Authorization(BasicHttpCredentials(config.getString("cloudant.username"), config.getString("cloudant.password"))) + + + /** + * POST call to Cloudant database API + * @param jsonString + * @return + */ + def post(jsonString: String): Future[String] = { + val responseEntity = for { + request <- Marshal(jsonString).to[RequestEntity] + response <- Http().singleRequest(HttpRequest( + method = HttpMethods.POST, + uri = config.getString("cloudant.post_url"), + headers = List(authorization), + entity = request)) + entity <- Unmarshal(response.entity).to[ByteString] + } yield entity + + responseEntity.mapTo[String] + + } + + + /** + * GET call to Cloudant database API + * @param documentType + * @return + */ + def get(documentType: DocumentType.Documenttype): Future[String] = { + val responseEntity = for { + response <- Http().singleRequest(HttpRequest( + method = HttpMethods.GET, + uri = getUrl(documentType), + headers = List(authorization))) + entity <- Unmarshal(response.entity).to[ByteString] + } yield entity + + responseEntity.mapTo[String] + + } + + + /** + * Get URI based on the type of document requested. + * @param documentType + * @return + */ + def getUrl(documentType: DocumentType.Documenttype): String ={ + var url: String = null + if(documentType.equals(DocumentType.TeamTable)){ + url = config.getString("cloudant.get_tables_url") + }else if(documentType.equals(DocumentType.Results)){ + url = config.getString("cloudant.get_results_url") + }else{ + url = config.getString("cloudant.get_fixtures_url") + } + url + } + + + +}