Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- def getSearchProductItemFitmentPage(searchProduct: SearchProduct, itemId: String, page: Int): FitmentPage = {
- DB.FitmentPagesDB.ensureOpen
- val fitmentPageKey = s"${searchProduct.productId}/$itemId/$page"
- // Try fetching the response from our cache first
- if(DB.FitmentPagesDB.contains(fitmentPageKey)) {
- val fitmentPageJson = DB.FitmentPagesDB(fitmentPageKey)
- val fitmentPage = JSON.fromJSON[FitmentPage](fitmentPageJson)
- if(Option(fitmentPage.status).isDefined) return fitmentPage
- }
- // Request data from remote sercie
- val fitmentPageUrl = createFitmentUrl(searchProduct, itemId, page)
- val (fitmentPageJson, fitmentPage) = Service.call("Calling Fitment JSON URL", logging = logger, maxRetries = 3) {
- val fitmentPageJson: String = urlDownloader.getString(fitmentPageUrl, UrlDownloaderOptions.default)
- val fitmentPage: FitmentPage = JSON.fromJSON[FitmentPage](fitmentPageJson)
- if(fitmentPage.status == null) throw new Exception(s"$fitmentPageUrl results had a null status: $fitmentPageJson")
- (fitmentPageJson, fitmentPage)
- }
- DB.FitmentPagesDB.update(fitmentPageKey, fitmentPageJson) // cache the response so we don't have to re-request it
- fitmentPageJson
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement