Skip to content

Instantly share code, notes, and snippets.

@joshlemer
Created March 10, 2016 18:31
Show Gist options
  • Save joshlemer/9689b3e0668a9f23f84a to your computer and use it in GitHub Desktop.
Save joshlemer/9689b3e0668a9f23f84a to your computer and use it in GitHub Desktop.
Atlas Client Prototype
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