Created
March 10, 2016 18:31
-
-
Save joshlemer/9689b3e0668a9f23f84a to your computer and use it in GitHub Desktop.
Atlas Client Prototype
This file contains 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 characters
object AtlasClient2 { | |
case class Settings(url: String, authorization: String, version: String, dbService: String) | |
object Settings { | |
def fromConfig(config: Config) = Settings("foo","bar","baz","boo") | |
} | |
def apply(settings: Settings) = new AtlasClient2(settings) | |
def apply(config: Config = ConfigFactory.load()) = new AtlasClient2(Settings.fromConfig(config)) | |
} | |
class AtlasClient2(settings: AtlasClient2.Settings) { | |
object Url { | |
def atlasTreeByLid(lid: String) = s"${settings.url}/someRoute" | |
} | |
def getAtlasTreeByLid(lid: String): SendReceive => Future[Option[Location]] = sr => { | |
def respToData(a: AtlasApiResponse) = a.data | |
val pipeline: HttpRequest => Future[Option[Location]] = sr ~> unmarshal[AtlasApiResponse] ~> respToData | |
pipeline(Get(Url.atlasTreeByLid(lid))) | |
} | |
} | |
object InTheApplication { | |
// by default, load from config | |
val ac = AtlasClient2() | |
// override with custom settings | |
val ac2 = new AtlasClient2(Settings("a","b","c","d")) | |
val ac3 = AtlasClient2(Settings("a","b","c","d")) | |
// override with custom Config | |
val ac4 = AtlasClient2(ConfigFactory.empty()) | |
val sr: SendReceive = sendReceive | |
ac.getAtlasTreeByLid("some lid")(sr) | |
// in testing: | |
val srTest: SendReceive = req => Future.successful(HttpResponse(200)) | |
ac.getAtlasTreeByLid("test lid")(srTest) | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment