in common/src/main/scala/com/gu/media/youtube/YouTubePartnerApi.scala [208:234]
def createOrUpdateClaim(atomId: String, videoId: String, adSettings: AdSettings): Either[VideoUpdateError, String] = {
try {
if(!adSettings.blockAds) {
updateTheVideoAdvertisingOptions(videoId, atomId, adSettings.enableMidroll)
}
getPartnerClaim(atomId, videoId) match {
case Some(claimSnippet) => {
val claimId = claimSnippet.getId
val assetId = claimSnippet.getAssetId
MAMLogger.info(s"Updating an existing claim for $videoId", atomId, videoId)
updateClaim(atomId, claimId, assetId, videoId, adSettings.blockAds)
}
case None => {
MAMLogger.info(s"No existing claim found for $videoId", atomId, videoId)
createVideoClaim(atomId, adSettings.blockAds, videoId)
}
}
}
catch {
case e: GoogleJsonResponseException => {
val error: GoogleJsonError = e.getDetails
MAMLogger.error(s"Failed to create or claim video $videoId. ${error.toString} ${error.getMessage}", atomId, videoId)
Left(VideoUpdateError(error.toString, Some(error.getMessage)))
}
}
}