Skip to content

Instantly share code, notes, and snippets.

@brunkb
Created January 7, 2015 02:43
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save brunkb/3f5e22d11d8c0a9e2005 to your computer and use it in GitHub Desktop.
Save brunkb/3f5e22d11d8c0a9e2005 to your computer and use it in GitHub Desktop.
class PricingServiceFirstTry {
// these dependencies would normally be injected
AuthenticationProvider auth = new AuthenticationProvider()
InventorySystem inv = new InventorySystem()
String username = 'test'
String password = 'test'
def logError(String msg) { println msg } // simulated logger
def priceLookup(String clientId, String itemUUID) {
try {
def authenticatedUserToken = auth.authenticateUser(username, password)
if(!inv.open(authenticatedUserToken)) {
throw new RuntimeException('Connection open failed')
} else {
inv.pricingLookup(clientId, itemUUID)
}
} catch(any) {
logError("Something went wrong: ${any.message}".toString())
throw any
} finally {
inv.close()
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment