From 911db3e56980d2cd322fd88d3fd54e1808aaacd3 Mon Sep 17 00:00:00 2001 From: Viral Vala Date: Wed, 25 Nov 2020 12:28:34 +0530 Subject: [PATCH] OTT-55 First Commit --- adapters/bidder.go | 9 +- adapters/tagbidder/bidder_macro.go | 646 ++++++++++++++++++++++++ adapters/tagbidder/constant.go | 150 ++++++ adapters/tagbidder/ibidder_macro.go | 153 ++++++ adapters/tagbidder/itagbidder.go | 9 + adapters/tagbidder/macro_processor.go | 149 ++++++ adapters/tagbidder/mapper.go | 194 +++++++ adapters/tagbidder/spotx_bidder_test.go | 151 ++++++ adapters/tagbidder/tagbidder_test.go | 31 ++ 9 files changed, 1488 insertions(+), 4 deletions(-) create mode 100644 adapters/tagbidder/bidder_macro.go create mode 100644 adapters/tagbidder/constant.go create mode 100644 adapters/tagbidder/ibidder_macro.go create mode 100644 adapters/tagbidder/itagbidder.go create mode 100644 adapters/tagbidder/macro_processor.go create mode 100644 adapters/tagbidder/mapper.go create mode 100644 adapters/tagbidder/spotx_bidder_test.go create mode 100644 adapters/tagbidder/tagbidder_test.go diff --git a/adapters/bidder.go b/adapters/bidder.go index fe6b7ba4c79..6d4f5d17c9a 100644 --- a/adapters/bidder.go +++ b/adapters/bidder.go @@ -130,10 +130,11 @@ type ResponseData struct { // RequestData packages together the fields needed to make an http.Request. type RequestData struct { - Method string - Uri string - Body []byte - Headers http.Header + ImpIndex int + Method string + Uri string + Body []byte + Headers http.Header } // ExtImpBidder can be used by Bidders to unmarshal any request.imp[i].ext. diff --git a/adapters/tagbidder/bidder_macro.go b/adapters/tagbidder/bidder_macro.go new file mode 100644 index 00000000000..940b1ab73cd --- /dev/null +++ b/adapters/tagbidder/bidder_macro.go @@ -0,0 +1,646 @@ +package tagbidder + +import "github.com/PubMatic-OpenWrap/openrtb" + +//BidderMacro default implementation +type BidderMacro struct { + IBidderMacro + request *openrtb.BidRequest + isApp bool + imp *openrtb.Imp + publisher *openrtb.Publisher + content *openrtb.Content +} + +//NewBidderMacro contains definition for all openrtb macro's +func NewBidderMacro(request *openrtb.BidRequest) *BidderMacro { + bidder := &BidderMacro{ + request: request, + } + bidder.init() + return bidder +} + +func (tag *BidderMacro) init() { + if nil != tag.request.App { + tag.isApp = true + tag.publisher = tag.request.App.Publisher + tag.content = tag.request.App.Content + } else { + tag.publisher = tag.request.Site.Publisher + tag.content = tag.request.Site.Content + } +} + +//LoadImpression will set current imp +func (tag *BidderMacro) LoadImpression(imp *openrtb.Imp) error { + tag.imp = imp + return nil +} + +/********************* Request *********************/ + +//MacroTest contains definition for Test Parameter +func (tag *BidderMacro) MacroTest(key string) string { + return "" +} + +//MacroTimeout contains definition for Timeout Parameter +func (tag *BidderMacro) MacroTimeout(key string) string { + return "" +} + +//MacroWhitelistSeat contains definition for WhitelistSeat Parameter +func (tag *BidderMacro) MacroWhitelistSeat(key string) string { + return "" +} + +//MacroWhitelistLang contains definition for WhitelistLang Parameter +func (tag *BidderMacro) MacroWhitelistLang(key string) string { + return "" +} + +//MacroBlockedseat contains definition for Blockedseat Parameter +func (tag *BidderMacro) MacroBlockedseat(key string) string { + return "" +} + +//MacroCurrency contains definition for Currency Parameter +func (tag *BidderMacro) MacroCurrency(key string) string { + return "" +} + +//MacroBlockedCategory contains definition for BlockedCategory Parameter +func (tag *BidderMacro) MacroBlockedCategory(key string) string { + return "" +} + +//MacroBlockedAdvertiser contains definition for BlockedAdvertiser Parameter +func (tag *BidderMacro) MacroBlockedAdvertiser(key string) string { + return "" +} + +//MacroBlockedApp contains definition for BlockedApp Parameter +func (tag *BidderMacro) MacroBlockedApp(key string) string { + return "" +} + +/********************* Source *********************/ + +//MacroFD contains definition for FD Parameter +func (tag *BidderMacro) MacroFD(key string) string { + return "" +} + +//MacroTransactionID contains definition for TransactionID Parameter +func (tag *BidderMacro) MacroTransactionID(key string) string { + return "" +} + +//MacroPaymentIDChain contains definition for PaymentIDChain Parameter +func (tag *BidderMacro) MacroPaymentIDChain(key string) string { + return "" +} + +/********************* Regs *********************/ + +//MacroCoppa contains definition for Coppa Parameter +func (tag *BidderMacro) MacroCoppa(key string) string { + return "" +} + +/********************* Impression *********************/ + +//MacroDisplayManager contains definition for DisplayManager Parameter +func (tag *BidderMacro) MacroDisplayManager(key string) string { + return "" +} + +//MacroDisplayManagerVersion contains definition for DisplayManagerVersion Parameter +func (tag *BidderMacro) MacroDisplayManagerVersion(key string) string { + return "" +} + +//MacroInterstitial contains definition for Interstitial Parameter +func (tag *BidderMacro) MacroInterstitial(key string) string { + return "" +} + +//MacroTagID contains definition for TagID Parameter +func (tag *BidderMacro) MacroTagID(key string) string { + return "" +} + +//MacroBidFloor contains definition for BidFloor Parameter +func (tag *BidderMacro) MacroBidFloor(key string) string { + return "" +} + +//MacroBidFloorCurrency contains definition for BidFloorCurrency Parameter +func (tag *BidderMacro) MacroBidFloorCurrency(key string) string { + return "" +} + +//MacroSecure contains definition for Secure Parameter +func (tag *BidderMacro) MacroSecure(key string) string { + return "" +} + +//MacroPMP contains definition for PMP Parameter +func (tag *BidderMacro) MacroPMP(key string) string { + return "" +} + +/********************* Video *********************/ + +//MacroVideoMIMES contains definition for VideoMIMES Parameter +func (tag *BidderMacro) MacroVideoMIMES(key string) string { + return "" +} + +//MacroVideoMinimumDuration contains definition for VideoMinimumDuration Parameter +func (tag *BidderMacro) MacroVideoMinimumDuration(key string) string { + return "" +} + +//MacroVideoMaximumDuration contains definition for VideoMaximumDuration Parameter +func (tag *BidderMacro) MacroVideoMaximumDuration(key string) string { + return "" +} + +//MacroVideoProtocols contains definition for VideoProtocols Parameter +func (tag *BidderMacro) MacroVideoProtocols(key string) string { + return "" +} + +//MacroVideoPlayerWidth contains definition for VideoPlayerWidth Parameter +func (tag *BidderMacro) MacroVideoPlayerWidth(key string) string { + return "" +} + +//MacroVideoPlayerHeight contains definition for VideoPlayerHeight Parameter +func (tag *BidderMacro) MacroVideoPlayerHeight(key string) string { + return "" +} + +//MacroVideoStartDelay contains definition for VideoStartDelay Parameter +func (tag *BidderMacro) MacroVideoStartDelay(key string) string { + return "" +} + +//MacroVideoPlacement contains definition for VideoPlacement Parameter +func (tag *BidderMacro) MacroVideoPlacement(key string) string { + return "" +} + +//MacroVideoLinearity contains definition for VideoLinearity Parameter +func (tag *BidderMacro) MacroVideoLinearity(key string) string { + return "" +} + +//MacroVideoSkip contains definition for VideoSkip Parameter +func (tag *BidderMacro) MacroVideoSkip(key string) string { + return "" +} + +//MacroVideoSkipMinimum contains definition for VideoSkipMinimum Parameter +func (tag *BidderMacro) MacroVideoSkipMinimum(key string) string { + return "" +} + +//MacroVideoSkipAfter contains definition for VideoSkipAfter Parameter +func (tag *BidderMacro) MacroVideoSkipAfter(key string) string { + return "" +} + +//MacroVideoSequence contains definition for VideoSequence Parameter +func (tag *BidderMacro) MacroVideoSequence(key string) string { + return "" +} + +//MacroVideoBlockedAttribute contains definition for VideoBlockedAttribute Parameter +func (tag *BidderMacro) MacroVideoBlockedAttribute(key string) string { + return "" +} + +//MacroVideoMaximumExtended contains definition for VideoMaximumExtended Parameter +func (tag *BidderMacro) MacroVideoMaximumExtended(key string) string { + return "" +} + +//MacroVideoMinimumBitRate contains definition for VideoMinimumBitRate Parameter +func (tag *BidderMacro) MacroVideoMinimumBitRate(key string) string { + return "" +} + +//MacroVideoMaximumBitRate contains definition for VideoMaximumBitRate Parameter +func (tag *BidderMacro) MacroVideoMaximumBitRate(key string) string { + return "" +} + +//MacroVideoBoxing contains definition for VideoBoxing Parameter +func (tag *BidderMacro) MacroVideoBoxing(key string) string { + return "" +} + +//MacroVideoPlaybackMethod contains definition for VideoPlaybackMethod Parameter +func (tag *BidderMacro) MacroVideoPlaybackMethod(key string) string { + return "" +} + +//MacroVideoDelivery contains definition for VideoDelivery Parameter +func (tag *BidderMacro) MacroVideoDelivery(key string) string { + return "" +} + +//MacroVideoPosition contains definition for VideoPosition Parameter +func (tag *BidderMacro) MacroVideoPosition(key string) string { + return "" +} + +//MacroVideoAPI contains definition for VideoAPI Parameter +func (tag *BidderMacro) MacroVideoAPI(key string) string { + return "" +} + +/********************* Site *********************/ + +//MacroSiteID contains definition for SiteID Parameter +func (tag *BidderMacro) MacroSiteID(key string) string { + return "" +} + +//MacroSiteName contains definition for SiteName Parameter +func (tag *BidderMacro) MacroSiteName(key string) string { + return "" +} + +//MacroSitePage contains definition for SitePage Parameter +func (tag *BidderMacro) MacroSitePage(key string) string { + return "" +} + +//MacroSiteReferrer contains definition for SiteReferrer Parameter +func (tag *BidderMacro) MacroSiteReferrer(key string) string { + return "" +} + +//MacroSiteSearch contains definition for SiteSearch Parameter +func (tag *BidderMacro) MacroSiteSearch(key string) string { + return "" +} + +//MacroSiteMobile contains definition for SiteMobile Parameter +func (tag *BidderMacro) MacroSiteMobile(key string) string { + return "" +} + +/********************* App *********************/ + +//MacroAppID contains definition for AppID Parameter +func (tag *BidderMacro) MacroAppID(key string) string { + return "" +} + +//MacroAppName contains definition for AppName Parameter +func (tag *BidderMacro) MacroAppName(key string) string { + return "" +} + +//MacroAppBundle contains definition for AppBundle Parameter +func (tag *BidderMacro) MacroAppBundle(key string) string { + return "" +} + +//MacroAppStoreURL contains definition for AppStoreURL Parameter +func (tag *BidderMacro) MacroAppStoreURL(key string) string { + return "" +} + +//MacroAppVersion contains definition for AppVersion Parameter +func (tag *BidderMacro) MacroAppVersion(key string) string { + return "" +} + +//MacroAppPaid contains definition for AppPaid Parameter +func (tag *BidderMacro) MacroAppPaid(key string) string { + return "" +} + +/********************* Site/App Common *********************/ + +//MacroCategory contains definition for Category Parameter +func (tag *BidderMacro) MacroCategory(key string) string { + return "" +} + +//MacroDomain contains definition for Domain Parameter +func (tag *BidderMacro) MacroDomain(key string) string { + return "" +} + +//MacroSectionCategory contains definition for SectionCategory Parameter +func (tag *BidderMacro) MacroSectionCategory(key string) string { + return "" +} + +//MacroPageCategory contains definition for PageCategory Parameter +func (tag *BidderMacro) MacroPageCategory(key string) string { + return "" +} + +//MacroPrivacyPolicy contains definition for PrivacyPolicy Parameter +func (tag *BidderMacro) MacroPrivacyPolicy(key string) string { + return "" +} + +//MacroKeywords contains definition for Keywords Parameter +func (tag *BidderMacro) MacroKeywords(key string) string { + return "" +} + +/********************* Publisher *********************/ + +//MacroPubID contains definition for PubID Parameter +func (tag *BidderMacro) MacroPubID(key string) string { + return "" +} + +//MacroPubName contains definition for PubName Parameter +func (tag *BidderMacro) MacroPubName(key string) string { + return "" +} + +//MacroPubDomain contains definition for PubDomain Parameter +func (tag *BidderMacro) MacroPubDomain(key string) string { + return "" +} + +/********************* Content *********************/ + +//MacroContentID contains definition for ContentID Parameter +func (tag *BidderMacro) MacroContentID(key string) string { + return "" +} + +//MacroContentEpisode contains definition for ContentEpisode Parameter +func (tag *BidderMacro) MacroContentEpisode(key string) string { + return "" +} + +//MacroContentTitle contains definition for ContentTitle Parameter +func (tag *BidderMacro) MacroContentTitle(key string) string { + return "" +} + +//MacroContentSeries contains definition for ContentSeries Parameter +func (tag *BidderMacro) MacroContentSeries(key string) string { + return "" +} + +//MacroContentSeason contains definition for ContentSeason Parameter +func (tag *BidderMacro) MacroContentSeason(key string) string { + return "" +} + +//MacroContentArtist contains definition for ContentArtist Parameter +func (tag *BidderMacro) MacroContentArtist(key string) string { + return "" +} + +//MacroContentGenre contains definition for ContentGenre Parameter +func (tag *BidderMacro) MacroContentGenre(key string) string { + return "" +} + +//MacroContentAlbum contains definition for ContentAlbum Parameter +func (tag *BidderMacro) MacroContentAlbum(key string) string { + return "" +} + +//MacroContentISrc contains definition for ContentISrc Parameter +func (tag *BidderMacro) MacroContentISrc(key string) string { + return "" +} + +//MacroContentURL contains definition for ContentURL Parameter +func (tag *BidderMacro) MacroContentURL(key string) string { + return "" +} + +//MacroContentCategory contains definition for ContentCategory Parameter +func (tag *BidderMacro) MacroContentCategory(key string) string { + return "" +} + +//MacroContentProductionQuality contains definition for ContentProductionQuality Parameter +func (tag *BidderMacro) MacroContentProductionQuality(key string) string { + return "" +} + +//MacroContentVideoQuality contains definition for ContentVideoQuality Parameter +func (tag *BidderMacro) MacroContentVideoQuality(key string) string { + return "" +} + +//MacroContentContext contains definition for ContentContext Parameter +func (tag *BidderMacro) MacroContentContext(key string) string { + return "" +} + +/********************* Producer *********************/ + +//MacroProducerID contains definition for ProducerID Parameter +func (tag *BidderMacro) MacroProducerID(key string) string { + return "" +} + +//MacroProducerName contains definition for ProducerName Parameter +func (tag *BidderMacro) MacroProducerName(key string) string { + return "" +} + +/********************* Device *********************/ + +//MacroUserAgent contains definition for UserAgent Parameter +func (tag *BidderMacro) MacroUserAgent(key string) string { + return "" +} + +//MacroDNT contains definition for DNT Parameter +func (tag *BidderMacro) MacroDNT(key string) string { + return "" +} + +//MacroLMT contains definition for LMT Parameter +func (tag *BidderMacro) MacroLMT(key string) string { + return "" +} + +//MacroIP contains definition for IP Parameter +func (tag *BidderMacro) MacroIP(key string) string { + return "" +} + +//MacroDeviceType contains definition for DeviceType Parameter +func (tag *BidderMacro) MacroDeviceType(key string) string { + return "" +} + +//MacroMake contains definition for Make Parameter +func (tag *BidderMacro) MacroMake(key string) string { + return "" +} + +//MacroModel contains definition for Model Parameter +func (tag *BidderMacro) MacroModel(key string) string { + return "" +} + +//MacroDeviceOS contains definition for DeviceOS Parameter +func (tag *BidderMacro) MacroDeviceOS(key string) string { + return "" +} + +//MacroDeviceOSVersion contains definition for DeviceOSVersion Parameter +func (tag *BidderMacro) MacroDeviceOSVersion(key string) string { + return "" +} + +//MacroDeviceWidth contains definition for DeviceWidth Parameter +func (tag *BidderMacro) MacroDeviceWidth(key string) string { + return "" +} + +//MacroDeviceHeight contains definition for DeviceHeight Parameter +func (tag *BidderMacro) MacroDeviceHeight(key string) string { + return "" +} + +//MacroDeviceJS contains definition for DeviceJS Parameter +func (tag *BidderMacro) MacroDeviceJS(key string) string { + return "" +} + +//MacroDeviceLanguage contains definition for DeviceLanguage Parameter +func (tag *BidderMacro) MacroDeviceLanguage(key string) string { + return "" +} + +//MacroDeviceIFA contains definition for DeviceIFA Parameter +func (tag *BidderMacro) MacroDeviceIFA(key string) string { + return "" +} + +//MacroDeviceDIDSHA1 contains definition for DeviceDIDSHA1 Parameter +func (tag *BidderMacro) MacroDeviceDIDSHA1(key string) string { + return "" +} + +//MacroDeviceDIDMD5 contains definition for DeviceDIDMD5 Parameter +func (tag *BidderMacro) MacroDeviceDIDMD5(key string) string { + return "" +} + +//MacroDeviceDPIDSHA1 contains definition for DeviceDPIDSHA1 Parameter +func (tag *BidderMacro) MacroDeviceDPIDSHA1(key string) string { + return "" +} + +//MacroDeviceDPIDMD5 contains definition for DeviceDPIDMD5 Parameter +func (tag *BidderMacro) MacroDeviceDPIDMD5(key string) string { + return "" +} + +//MacroDeviceMACSHA1 contains definition for DeviceMACSHA1 Parameter +func (tag *BidderMacro) MacroDeviceMACSHA1(key string) string { + return "" +} + +//MacroDeviceMACMD5 contains definition for DeviceMACMD5 Parameter +func (tag *BidderMacro) MacroDeviceMACMD5(key string) string { + return "" +} + +/********************* Geo *********************/ + +//MacroLatitude contains definition for Latitude Parameter +func (tag *BidderMacro) MacroLatitude(key string) string { + return "" +} + +//MacroLongitude contains definition for Longitude Parameter +func (tag *BidderMacro) MacroLongitude(key string) string { + return "" +} + +//MacroCountry contains definition for Country Parameter +func (tag *BidderMacro) MacroCountry(key string) string { + return "" +} + +//MacroRegion contains definition for Region Parameter +func (tag *BidderMacro) MacroRegion(key string) string { + return "" +} + +//MacroCity contains definition for City Parameter +func (tag *BidderMacro) MacroCity(key string) string { + return "" +} + +//MacroZip contains definition for Zip Parameter +func (tag *BidderMacro) MacroZip(key string) string { + return "" +} + +//MacroUTCOffset contains definition for UTCOffset Parameter +func (tag *BidderMacro) MacroUTCOffset(key string) string { + return "" +} + +/********************* User *********************/ + +//MacroUserID contains definition for UserID Parameter +func (tag *BidderMacro) MacroUserID(key string) string { + return "" +} + +//MacroYearOfBirth contains definition for YearOfBirth Parameter +func (tag *BidderMacro) MacroYearOfBirth(key string) string { + return "" +} + +//MacroGender contains definition for Gender Parameter +func (tag *BidderMacro) MacroGender(key string) string { + return "" +} + +/********************* Extension *********************/ + +//MacroGDPRConsent contains definition for GDPRConsent Parameter +func (tag *BidderMacro) MacroGDPRConsent(key string) string { + return "" +} + +//MacroGDPR contains definition for GDPR Parameter +func (tag *BidderMacro) MacroGDPR(key string) string { + return "" +} + +//MacroUSPrivacy contains definition for USPrivacy Parameter +func (tag *BidderMacro) MacroUSPrivacy(key string) string { + return "" +} + +/********************* Additional *********************/ + +//MacroCacheBuster contains definition for CacheBuster Parameter +func (tag *BidderMacro) MacroCacheBuster(key string) string { + return "" +} + +//Custom contains definition for CacheBuster Parameter +func (tag *BidderMacro) Custom(key string) string { + return "" +} diff --git a/adapters/tagbidder/constant.go b/adapters/tagbidder/constant.go new file mode 100644 index 00000000000..fc460208f62 --- /dev/null +++ b/adapters/tagbidder/constant.go @@ -0,0 +1,150 @@ +package tagbidder + +//List of Tag Bidder Macros +const ( + //Request + MacroTest = `MacroTest` + MacroTimeout = `MacroTimeout` + MacroWhitelistSeat = `MacroWhitelistSeat` + MacroWhitelistLang = `MacroWhitelistLang` + MacroBlockedseat = `MacroBlockedseat` + MacroCurrency = `MacroCurrency` + MacroBlockedCategory = `MacroBlockedCategory` + MacroBlockedAdvertiser = `MacroBlockedAdvertiser` + MacroBlockedApp = `MacroBlockedApp` + + //Source + MacroFD = `MacroFD` + MacroTransactionID = `MacroTransactionID` + MacroPaymentIDChain = `MacroPaymentIDChain` + + //Regs + MacroCoppa = `MacroCoppa` + + //Impression + MacroDisplayManager = `MacroDisplayManager` + MacroDisplayManagerVersion = `MacroDisplayManagerVersion` + MacroInterstitial = `MacroInterstitial` + MacroTagID = `MacroTagID` + MacroBidFloor = `MacroBidFloor` + MacroBidFloorCurrency = `MacroBidFloorCurrency` + MacroSecure = `MacroSecure` + MacroPMP = `MacroPMP` + + //Video + MacroVideoMIMES = `MacroVideoMIMES` + MacroVideoMinimumDuration = `MacroVideoMinimumDuration` + MacroVideoMaximumDuration = `MacroVideoMaximumDuration` + MacroVideoProtocols = `MacroVideoProtocols` + MacroVideoPlayerWidth = `MacroVideoPlayerWidth` + MacroVideoPlayerHeight = `MacroVideoPlayerHeight` + MacroVideoStartDelay = `MacroVideoStartDelay` + MacroVideoPlacement = `MacroVideoPlacement` + MacroVideoLinearity = `MacroVideoLinearity` + MacroVideoSkip = `MacroVideoSkip` + MacroVideoSkipMinimum = `MacroVideoSkipMinimum` + MacroVideoSkipAfter = `MacroVideoSkipAfter` + MacroVideoSequence = `MacroVideoSequence` + MacroVideoBlockedAttribute = `MacroVideoBlockedAttribute` + MacroVideoMaximumExtended = `MacroVideoMaximumExtended` + MacroVideoMinimumBitRate = `MacroVideoMinimumBitRate` + MacroVideoMaximumBitRate = `MacroVideoMaximumBitRate` + MacroVideoBoxing = `MacroVideoBoxing` + MacroVideoPlaybackMethod = `MacroVideoPlaybackMethod` + MacroVideoDelivery = `MacroVideoDelivery` + MacroVideoPosition = `MacroVideoPosition` + MacroVideoAPI = `MacroVideoAPI` + + //Site + MacroSiteID = `MacroSiteID` + MacroSiteName = `MacroSiteName` + MacroSitePage = `MacroSitePage` + MacroSiteReferrer = `MacroSiteReferrer` + MacroSiteSearch = `MacroSiteSearch` + MacroSiteMobile = `MacroSiteMobile` + + //App + MacroAppID = `MacroAppID` + MacroAppName = `MacroAppName` + MacroAppBundle = `MacroAppBundle` + MacroAppStoreURL = `MacroAppStoreURL` + MacroAppVersion = `MacroAppVersion` + MacroAppPaid = `MacroAppPaid` + + //SiteAppCommon + MacroCategory = `MacroCategory` + MacroDomain = `MacroDomain` + MacroSectionCategory = `MacroSectionCategory` + MacroPageCategory = `MacroPageCategory` + MacroPrivacyPolicy = `MacroPrivacyPolicy` + MacroKeywords = `MacroKeywords` + + //Publisher + MacroPubID = `MacroPubID` + MacroPubName = `MacroPubName` + MacroPubDomain = `MacroPubDomain` + + //Content + MacroContentID = `MacroContentID` + MacroContentEpisode = `MacroContentEpisode` + MacroContentTitle = `MacroContentTitle` + MacroContentSeries = `MacroContentSeries` + MacroContentSeason = `MacroContentSeason` + MacroContentArtist = `MacroContentArtist` + MacroContentGenre = `MacroContentGenre` + MacroContentAlbum = `MacroContentAlbum` + MacroContentISrc = `MacroContentISrc` + MacroContentURL = `MacroContentURL` + MacroContentCategory = `MacroContentCategory` + MacroContentProductionQuality = `MacroContentProductionQuality` + MacroContentVideoQuality = `MacroContentVideoQuality` + MacroContentContext = `MacroContentContext` + + //Producer + MacroProducerID = `MacroProducerID` + MacroProducerName = `MacroProducerName` + + //Device + MacroUserAgent = `MacroUserAgent` + MacroDNT = `MacroDNT` + MacroLMT = `MacroLMT` + MacroIP = `MacroIP` + MacroDeviceType = `MacroDeviceType` + MacroMake = `MacroMake` + MacroModel = `MacroModel` + MacroDeviceOS = `MacroDeviceOS` + MacroDeviceOSVersion = `MacroDeviceOSVersion` + MacroDeviceWidth = `MacroDeviceWidth` + MacroDeviceHeight = `MacroDeviceHeight` + MacroDeviceJS = `MacroDeviceJS` + MacroDeviceLanguage = `MacroDeviceLanguage` + MacroDeviceIFA = `MacroDeviceIFA` + MacroDeviceDIDSHA1 = `MacroDeviceDIDSHA1` + MacroDeviceDIDMD5 = `MacroDeviceDIDMD5` + MacroDeviceDPIDSHA1 = `MacroDeviceDPIDSHA1` + MacroDeviceDPIDMD5 = `MacroDeviceDPIDMD5` + MacroDeviceMACSHA1 = `MacroDeviceMACSHA1` + MacroDeviceMACMD5 = `MacroDeviceMACMD5` + + //Geo + MacroLatitude = `MacroLatitude` + MacroLongitude = `MacroLongitude` + MacroCountry = `MacroCountry` + MacroRegion = `MacroRegion` + MacroCity = `MacroCity` + MacroZip = `MacroZip` + MacroUTCOffset = `MacroUTCOffset` + + //User + MacroUserID = `MacroUserID` + MacroYearOfBirth = `MacroYearOfBirth` + MacroGender = `MacroGender` + + //Extension + MacroGDPRConsent = `MacroGDPRConsent` + MacroGDPR = `MacroGDPR` + MacroUSPrivacy = `MacroUSPrivacy` + + //Additional + MacroCacheBuster = `MacroCacheBuster` +) diff --git a/adapters/tagbidder/ibidder_macro.go b/adapters/tagbidder/ibidder_macro.go new file mode 100644 index 00000000000..1716c501924 --- /dev/null +++ b/adapters/tagbidder/ibidder_macro.go @@ -0,0 +1,153 @@ +package tagbidder + +//IBidderMacro interface will capture all macro definition +type IBidderMacro interface { + ITagBidder + + //Request + MacroTest(string) string + MacroTimeout(string) string + MacroWhitelistSeat(string) string + MacroWhitelistLang(string) string + MacroBlockedseat(string) string + MacroCurrency(string) string + MacroBlockedCategory(string) string + MacroBlockedAdvertiser(string) string + MacroBlockedApp(string) string + + //Source + MacroFD(string) string + MacroTransactionID(string) string + MacroPaymentIDChain(string) string + + //Regs + MacroCoppa(string) string + + //Impression + MacroDisplayManager(string) string + MacroDisplayManagerVersion(string) string + MacroInterstitial(string) string + MacroTagID(string) string + MacroBidFloor(string) string + MacroBidFloorCurrency(string) string + MacroSecure(string) string + MacroPMP(string) string + + //Video + MacroVideoMIMES(string) string + MacroVideoMinimumDuration(string) string + MacroVideoMaximumDuration(string) string + MacroVideoProtocols(string) string + MacroVideoPlayerWidth(string) string + MacroVideoPlayerHeight(string) string + MacroVideoStartDelay(string) string + MacroVideoPlacement(string) string + MacroVideoLinearity(string) string + MacroVideoSkip(string) string + MacroVideoSkipMinimum(string) string + MacroVideoSkipAfter(string) string + MacroVideoSequence(string) string + MacroVideoBlockedAttribute(string) string + MacroVideoMaximumExtended(string) string + MacroVideoMinimumBitRate(string) string + MacroVideoMaximumBitRate(string) string + MacroVideoBoxing(string) string + MacroVideoPlaybackMethod(string) string + MacroVideoDelivery(string) string + MacroVideoPosition(string) string + MacroVideoAPI(string) string + + //Site + MacroSiteID(string) string + MacroSiteName(string) string + MacroSitePage(string) string + MacroSiteReferrer(string) string + MacroSiteSearch(string) string + MacroSiteMobile(string) string + + //App + MacroAppID(string) string + MacroAppName(string) string + MacroAppBundle(string) string + MacroAppStoreURL(string) string + MacroAppVersion(string) string + MacroAppPaid(string) string + + //SiteAppCommon + MacroCategory(string) string + MacroDomain(string) string + MacroSectionCategory(string) string + MacroPageCategory(string) string + MacroPrivacyPolicy(string) string + MacroKeywords(string) string + + //Publisher + MacroPubID(string) string + MacroPubName(string) string + MacroPubDomain(string) string + + //Content + MacroContentID(string) string + MacroContentEpisode(string) string + MacroContentTitle(string) string + MacroContentSeries(string) string + MacroContentSeason(string) string + MacroContentArtist(string) string + MacroContentGenre(string) string + MacroContentAlbum(string) string + MacroContentISrc(string) string + MacroContentURL(string) string + MacroContentCategory(string) string + MacroContentProductionQuality(string) string + MacroContentVideoQuality(string) string + MacroContentContext(string) string + + //Producer + MacroProducerID(string) string + MacroProducerName(string) string + + //Device + MacroUserAgent(string) string + MacroDNT(string) string + MacroLMT(string) string + MacroIP(string) string + MacroDeviceType(string) string + MacroMake(string) string + MacroModel(string) string + MacroDeviceOS(string) string + MacroDeviceOSVersion(string) string + MacroDeviceWidth(string) string + MacroDeviceHeight(string) string + MacroDeviceJS(string) string + MacroDeviceLanguage(string) string + MacroDeviceIFA(string) string + MacroDeviceDIDSHA1(string) string + MacroDeviceDIDMD5(string) string + MacroDeviceDPIDSHA1(string) string + MacroDeviceDPIDMD5(string) string + MacroDeviceMACSHA1(string) string + MacroDeviceMACMD5(string) string + + //Geo + MacroLatitude(string) string + MacroLongitude(string) string + MacroCountry(string) string + MacroRegion(string) string + MacroCity(string) string + MacroZip(string) string + MacroUTCOffset(string) string + + //User + MacroUserID(string) string + MacroYearOfBirth(string) string + MacroGender(string) string + + //Extension + MacroGDPRConsent(string) string + MacroGDPR(string) string + MacroUSPrivacy(string) string + + //Additional + MacroCacheBuster(string) string + Custom(string) string +} diff --git a/adapters/tagbidder/itagbidder.go b/adapters/tagbidder/itagbidder.go new file mode 100644 index 00000000000..bca198ad4c2 --- /dev/null +++ b/adapters/tagbidder/itagbidder.go @@ -0,0 +1,9 @@ +package tagbidder + +import "github.com/PubMatic-OpenWrap/openrtb" + +type ITagBidder interface { + Name() string + URL() string + LoadImpression(imp *openrtb.Imp) error +} diff --git a/adapters/tagbidder/macro_processor.go b/adapters/tagbidder/macro_processor.go new file mode 100644 index 00000000000..e139130607d --- /dev/null +++ b/adapters/tagbidder/macro_processor.go @@ -0,0 +1,149 @@ +package tagbidder + +import ( + "bytes" + "encoding/json" + "fmt" + "net/url" + "strings" + + "github.com/golang/glog" +) + +const ( + macroFormatChar byte = '%' + macroFormat string = `%%` + macroFormatLen int = len(macroFormat) + macroEOF int = -1 + customMacroFormat string = `%%VAR_%s%%` + macroEscapeSuffix string = `_ESC` + macroEscapeSuffixLen int = len(macroEscapeSuffix) +) + +//MacroProcessor struct to hold openrtb request and cache values +type MacroProcessor struct { + bidder IBidderMacro + mapper mapper + macroCache map[string]string +} + +//NewMacroProcessor will process macro's of openrtb bid request +func NewMacroProcessor(mapper mapper) *MacroProcessor { + return &MacroProcessor{ + mapper: mapper, + macroCache: make(map[string]string), + } +} + +//SetMacro : Adding Custom Macro Manually +func (mp *MacroProcessor) SetMacro(key, value string) { + mp.macroCache[key] = value +} + +//GetCutsomMacroKey : Returns Custom Macro Keys +func (mp *MacroProcessor) GetCutsomMacroKey(key string) string { + return fmt.Sprintf(customMacroFormat, key) +} + +//Process : Substitute macros in input string +func (mp *MacroProcessor) Process(in string) (response string) { + var out bytes.Buffer + pos, start, end, size, nEscaping := 0, 0, 0, len(in), 0 + skip, found := false, false + + for pos < size { + if skip == false { + if start = strings.Index(in[pos:], macroFormat); -1 == start { + out.WriteString(in[pos:]) + // Normal Exit + //glog.Infof("\n[EXIT=1]") + break + } + start = start + pos + out.WriteString(in[pos:start]) + } + + if end = strings.Index(in[start+macroFormatLen:], macroFormat); -1 == end { + out.WriteString(in[start:]) + // We Found First %% and Not Found Second %% But We are in between of string + //glog.Infof("\n[EXIT=2]") + break + } + end = start + end + (macroFormatLen << 1) + + key := in[start:end] + //glog.Infof("\nSearch[%d] : [%d,%d,%s]", count, start, end, key) + if value, ok := mp.macroCache[key]; ok { + //Found Key and Value: Replace Macro Value + //glog.Infof("\n : <%d,%d,%s,%s>", start, end, key, value) + out.WriteString(value) + pos = end + skip = false + } else { + found = false + nEscaping = 0 + tmpKey := key + for { + if valueCallback, ok := mp.mapper[tmpKey]; ok { + // Found Callback Function for Key + if value := valueCallback.callback(mp.bidder, tmpKey); len(value) > 0 { + if nEscaping > 0 { + //Escaping string nEscaping times + value = escape(value, nEscaping) + } + + if valueCallback.cached { + // Get Value and add it in macro list + mp.macroCache[key] = value + } + + // Replace it in MACRO + out.WriteString(value) + pos = end + skip = false + found = true + break + } + } else if strings.HasSuffix(tmpKey, macroEscapeSuffix) { + //escaping macro found + tmpKey = tmpKey[0 : len(tmpKey)-macroEscapeSuffixLen] + nEscaping++ + continue + } + break + } + + if !found { + if in[start+macroFormatLen] == macroFormatChar { + // Next Character is % then end = start+1, and write '%' in string + end = start + 1 + } else { + // Not Found Key as well as ValueCallback Function + end = end - macroFormatLen + } + out.WriteString(in[start:end]) + pos, start = end, end + skip = true + } + } + } + response = out.String() + glog.V(3).Infof("[MACRO]:in:[%s]\nreplaced:[%s]\n", in, response) + + return +} + +//Dump : will print all cached macro and its values +func (mp *MacroProcessor) Dump() { + if glog.V(3) { + cacheStr, _ := json.Marshal(mp.macroCache) + glog.Infof("[MACRO]: Map:[%s]", string(cacheStr)) + } +} + +func escape(str string, n int) string { + for ; n > 0; n-- { + str = url.QueryEscape(str) + } + return str[:] +} diff --git a/adapters/tagbidder/mapper.go b/adapters/tagbidder/mapper.go new file mode 100644 index 00000000000..d912fe06c69 --- /dev/null +++ b/adapters/tagbidder/mapper.go @@ -0,0 +1,194 @@ +package tagbidder + +type macroCallBack struct { + cached bool + callback func(IBidderMacro, string) string +} + +type mapper map[string]*macroCallBack + +var bidderMapper map[string]mapper + +func (obj mapper) clone() mapper { + cloned := make(mapper, len(obj)) + for k, v := range obj { + newCallback := *v + cloned[k] = &newCallback + } + return cloned +} + +//SetCache value to specific key +func (obj *mapper) SetCache(key string, value bool) { + if value, ok := (*obj)[key]; ok { + value.cached = true + } +} + +//AddCustomMacro for adding custom macro whose definition will be present in IBidderMacro.Custom method +func (obj *mapper) AddCustomMacro(key string, isCached bool) { + (*obj)[key] = ¯oCallBack{cached: isCached, callback: IBidderMacro.Custom} +} + +var _defaultMapper = mapper{ + //Request + MacroTest: ¯oCallBack{cached: false, callback: IBidderMacro.MacroTest}, + MacroTimeout: ¯oCallBack{cached: false, callback: IBidderMacro.MacroTimeout}, + MacroWhitelistSeat: ¯oCallBack{cached: false, callback: IBidderMacro.MacroWhitelistSeat}, + MacroWhitelistLang: ¯oCallBack{cached: false, callback: IBidderMacro.MacroWhitelistLang}, + MacroBlockedseat: ¯oCallBack{cached: false, callback: IBidderMacro.MacroBlockedseat}, + MacroCurrency: ¯oCallBack{cached: false, callback: IBidderMacro.MacroCurrency}, + MacroBlockedCategory: ¯oCallBack{cached: false, callback: IBidderMacro.MacroBlockedCategory}, + MacroBlockedAdvertiser: ¯oCallBack{cached: false, callback: IBidderMacro.MacroBlockedAdvertiser}, + MacroBlockedApp: ¯oCallBack{cached: false, callback: IBidderMacro.MacroBlockedApp}, + + //Source + MacroFD: ¯oCallBack{cached: false, callback: IBidderMacro.MacroFD}, + MacroTransactionID: ¯oCallBack{cached: false, callback: IBidderMacro.MacroTransactionID}, + MacroPaymentIDChain: ¯oCallBack{cached: false, callback: IBidderMacro.MacroPaymentIDChain}, + + //Regs + MacroCoppa: ¯oCallBack{cached: false, callback: IBidderMacro.MacroCoppa}, + + //Impression + MacroDisplayManager: ¯oCallBack{cached: false, callback: IBidderMacro.MacroDisplayManager}, + MacroDisplayManagerVersion: ¯oCallBack{cached: false, callback: IBidderMacro.MacroDisplayManagerVersion}, + MacroInterstitial: ¯oCallBack{cached: false, callback: IBidderMacro.MacroInterstitial}, + MacroTagID: ¯oCallBack{cached: false, callback: IBidderMacro.MacroTagID}, + MacroBidFloor: ¯oCallBack{cached: false, callback: IBidderMacro.MacroBidFloor}, + MacroBidFloorCurrency: ¯oCallBack{cached: false, callback: IBidderMacro.MacroBidFloorCurrency}, + MacroSecure: ¯oCallBack{cached: false, callback: IBidderMacro.MacroSecure}, + MacroPMP: ¯oCallBack{cached: false, callback: IBidderMacro.MacroPMP}, + + //Video + MacroVideoMIMES: ¯oCallBack{cached: false, callback: IBidderMacro.MacroVideoMIMES}, + MacroVideoMinimumDuration: ¯oCallBack{cached: false, callback: IBidderMacro.MacroVideoMinimumDuration}, + MacroVideoMaximumDuration: ¯oCallBack{cached: false, callback: IBidderMacro.MacroVideoMaximumDuration}, + MacroVideoProtocols: ¯oCallBack{cached: false, callback: IBidderMacro.MacroVideoProtocols}, + MacroVideoPlayerWidth: ¯oCallBack{cached: false, callback: IBidderMacro.MacroVideoPlayerWidth}, + MacroVideoPlayerHeight: ¯oCallBack{cached: false, callback: IBidderMacro.MacroVideoPlayerHeight}, + MacroVideoStartDelay: ¯oCallBack{cached: false, callback: IBidderMacro.MacroVideoStartDelay}, + MacroVideoPlacement: ¯oCallBack{cached: false, callback: IBidderMacro.MacroVideoPlacement}, + MacroVideoLinearity: ¯oCallBack{cached: false, callback: IBidderMacro.MacroVideoLinearity}, + MacroVideoSkip: ¯oCallBack{cached: false, callback: IBidderMacro.MacroVideoSkip}, + MacroVideoSkipMinimum: ¯oCallBack{cached: false, callback: IBidderMacro.MacroVideoSkipMinimum}, + MacroVideoSkipAfter: ¯oCallBack{cached: false, callback: IBidderMacro.MacroVideoSkipAfter}, + MacroVideoSequence: ¯oCallBack{cached: false, callback: IBidderMacro.MacroVideoSequence}, + MacroVideoBlockedAttribute: ¯oCallBack{cached: false, callback: IBidderMacro.MacroVideoBlockedAttribute}, + MacroVideoMaximumExtended: ¯oCallBack{cached: false, callback: IBidderMacro.MacroVideoMaximumExtended}, + MacroVideoMinimumBitRate: ¯oCallBack{cached: false, callback: IBidderMacro.MacroVideoMinimumBitRate}, + MacroVideoMaximumBitRate: ¯oCallBack{cached: false, callback: IBidderMacro.MacroVideoMaximumBitRate}, + MacroVideoBoxing: ¯oCallBack{cached: false, callback: IBidderMacro.MacroVideoBoxing}, + MacroVideoPlaybackMethod: ¯oCallBack{cached: false, callback: IBidderMacro.MacroVideoPlaybackMethod}, + MacroVideoDelivery: ¯oCallBack{cached: false, callback: IBidderMacro.MacroVideoDelivery}, + MacroVideoPosition: ¯oCallBack{cached: false, callback: IBidderMacro.MacroVideoPosition}, + MacroVideoAPI: ¯oCallBack{cached: false, callback: IBidderMacro.MacroVideoAPI}, + + //Site + MacroSiteID: ¯oCallBack{cached: false, callback: IBidderMacro.MacroSiteID}, + MacroSiteName: ¯oCallBack{cached: false, callback: IBidderMacro.MacroSiteName}, + MacroSitePage: ¯oCallBack{cached: false, callback: IBidderMacro.MacroSitePage}, + MacroSiteReferrer: ¯oCallBack{cached: false, callback: IBidderMacro.MacroSiteReferrer}, + MacroSiteSearch: ¯oCallBack{cached: false, callback: IBidderMacro.MacroSiteSearch}, + MacroSiteMobile: ¯oCallBack{cached: false, callback: IBidderMacro.MacroSiteMobile}, + + //App + MacroAppID: ¯oCallBack{cached: false, callback: IBidderMacro.MacroAppID}, + MacroAppName: ¯oCallBack{cached: false, callback: IBidderMacro.MacroAppName}, + MacroAppBundle: ¯oCallBack{cached: false, callback: IBidderMacro.MacroAppBundle}, + MacroAppStoreURL: ¯oCallBack{cached: false, callback: IBidderMacro.MacroAppStoreURL}, + MacroAppVersion: ¯oCallBack{cached: false, callback: IBidderMacro.MacroAppVersion}, + MacroAppPaid: ¯oCallBack{cached: false, callback: IBidderMacro.MacroAppPaid}, + + //SiteAppCommon + MacroCategory: ¯oCallBack{cached: false, callback: IBidderMacro.MacroCategory}, + MacroDomain: ¯oCallBack{cached: false, callback: IBidderMacro.MacroDomain}, + MacroSectionCategory: ¯oCallBack{cached: false, callback: IBidderMacro.MacroSectionCategory}, + MacroPageCategory: ¯oCallBack{cached: false, callback: IBidderMacro.MacroPageCategory}, + MacroPrivacyPolicy: ¯oCallBack{cached: false, callback: IBidderMacro.MacroPrivacyPolicy}, + MacroKeywords: ¯oCallBack{cached: false, callback: IBidderMacro.MacroKeywords}, + + //Publisher + MacroPubID: ¯oCallBack{cached: false, callback: IBidderMacro.MacroPubID}, + MacroPubName: ¯oCallBack{cached: false, callback: IBidderMacro.MacroPubName}, + MacroPubDomain: ¯oCallBack{cached: false, callback: IBidderMacro.MacroPubDomain}, + + //Content + MacroContentID: ¯oCallBack{cached: false, callback: IBidderMacro.MacroContentID}, + MacroContentEpisode: ¯oCallBack{cached: false, callback: IBidderMacro.MacroContentEpisode}, + MacroContentTitle: ¯oCallBack{cached: false, callback: IBidderMacro.MacroContentTitle}, + MacroContentSeries: ¯oCallBack{cached: false, callback: IBidderMacro.MacroContentSeries}, + MacroContentSeason: ¯oCallBack{cached: false, callback: IBidderMacro.MacroContentSeason}, + MacroContentArtist: ¯oCallBack{cached: false, callback: IBidderMacro.MacroContentArtist}, + MacroContentGenre: ¯oCallBack{cached: false, callback: IBidderMacro.MacroContentGenre}, + MacroContentAlbum: ¯oCallBack{cached: false, callback: IBidderMacro.MacroContentAlbum}, + MacroContentISrc: ¯oCallBack{cached: false, callback: IBidderMacro.MacroContentISrc}, + MacroContentURL: ¯oCallBack{cached: false, callback: IBidderMacro.MacroContentURL}, + MacroContentCategory: ¯oCallBack{cached: false, callback: IBidderMacro.MacroContentCategory}, + MacroContentProductionQuality: ¯oCallBack{cached: false, callback: IBidderMacro.MacroContentProductionQuality}, + MacroContentVideoQuality: ¯oCallBack{cached: false, callback: IBidderMacro.MacroContentVideoQuality}, + MacroContentContext: ¯oCallBack{cached: false, callback: IBidderMacro.MacroContentContext}, + + //Producer + MacroProducerID: ¯oCallBack{cached: false, callback: IBidderMacro.MacroProducerID}, + MacroProducerName: ¯oCallBack{cached: false, callback: IBidderMacro.MacroProducerName}, + + //Device + MacroUserAgent: ¯oCallBack{cached: false, callback: IBidderMacro.MacroUserAgent}, + MacroDNT: ¯oCallBack{cached: false, callback: IBidderMacro.MacroDNT}, + MacroLMT: ¯oCallBack{cached: false, callback: IBidderMacro.MacroLMT}, + MacroIP: ¯oCallBack{cached: false, callback: IBidderMacro.MacroIP}, + MacroDeviceType: ¯oCallBack{cached: false, callback: IBidderMacro.MacroDeviceType}, + MacroMake: ¯oCallBack{cached: false, callback: IBidderMacro.MacroMake}, + MacroModel: ¯oCallBack{cached: false, callback: IBidderMacro.MacroModel}, + MacroDeviceOS: ¯oCallBack{cached: false, callback: IBidderMacro.MacroDeviceOS}, + MacroDeviceOSVersion: ¯oCallBack{cached: false, callback: IBidderMacro.MacroDeviceOSVersion}, + MacroDeviceWidth: ¯oCallBack{cached: false, callback: IBidderMacro.MacroDeviceWidth}, + MacroDeviceHeight: ¯oCallBack{cached: false, callback: IBidderMacro.MacroDeviceHeight}, + MacroDeviceJS: ¯oCallBack{cached: false, callback: IBidderMacro.MacroDeviceJS}, + MacroDeviceLanguage: ¯oCallBack{cached: false, callback: IBidderMacro.MacroDeviceLanguage}, + MacroDeviceIFA: ¯oCallBack{cached: false, callback: IBidderMacro.MacroDeviceIFA}, + MacroDeviceDIDSHA1: ¯oCallBack{cached: false, callback: IBidderMacro.MacroDeviceDIDSHA1}, + MacroDeviceDIDMD5: ¯oCallBack{cached: false, callback: IBidderMacro.MacroDeviceDIDMD5}, + MacroDeviceDPIDSHA1: ¯oCallBack{cached: false, callback: IBidderMacro.MacroDeviceDPIDSHA1}, + MacroDeviceDPIDMD5: ¯oCallBack{cached: false, callback: IBidderMacro.MacroDeviceDPIDMD5}, + MacroDeviceMACSHA1: ¯oCallBack{cached: false, callback: IBidderMacro.MacroDeviceMACSHA1}, + MacroDeviceMACMD5: ¯oCallBack{cached: false, callback: IBidderMacro.MacroDeviceMACMD5}, + + //Geo + MacroLatitude: ¯oCallBack{cached: false, callback: IBidderMacro.MacroLatitude}, + MacroLongitude: ¯oCallBack{cached: false, callback: IBidderMacro.MacroLongitude}, + MacroCountry: ¯oCallBack{cached: false, callback: IBidderMacro.MacroCountry}, + MacroRegion: ¯oCallBack{cached: false, callback: IBidderMacro.MacroRegion}, + MacroCity: ¯oCallBack{cached: false, callback: IBidderMacro.MacroCity}, + MacroZip: ¯oCallBack{cached: false, callback: IBidderMacro.MacroZip}, + MacroUTCOffset: ¯oCallBack{cached: false, callback: IBidderMacro.MacroUTCOffset}, + + //User + MacroUserID: ¯oCallBack{cached: false, callback: IBidderMacro.MacroUserID}, + MacroYearOfBirth: ¯oCallBack{cached: false, callback: IBidderMacro.MacroYearOfBirth}, + MacroGender: ¯oCallBack{cached: false, callback: IBidderMacro.MacroGender}, + + //Extension + MacroGDPRConsent: ¯oCallBack{cached: false, callback: IBidderMacro.MacroGDPRConsent}, + MacroGDPR: ¯oCallBack{cached: false, callback: IBidderMacro.MacroGDPR}, + MacroUSPrivacy: ¯oCallBack{cached: false, callback: IBidderMacro.MacroUSPrivacy}, + + //Additional + MacroCacheBuster: ¯oCallBack{cached: false, callback: IBidderMacro.MacroCacheBuster}, +} + +//GetNewDefaultMapper will return clone of default mapper function +func GetNewDefaultMapper() mapper { + return _defaultMapper.clone() +} + +//SetBidderMapper will be used by each bidder to set its respective macro mapper +func SetBidderMapper(bidder string, bidderMap mapper) { + bidderMapper[bidder] = bidderMap +} + +//GetBidderMapper will return mapper of specific bidder +func GetBidderMapper(bidder string) mapper { + return bidderMapper[bidder] +} diff --git a/adapters/tagbidder/spotx_bidder_test.go b/adapters/tagbidder/spotx_bidder_test.go new file mode 100644 index 00000000000..b540ed68c56 --- /dev/null +++ b/adapters/tagbidder/spotx_bidder_test.go @@ -0,0 +1,151 @@ +package tagbidder + +import ( + "encoding/json" + + "github.com/PubMatic-OpenWrap/openrtb" + "github.com/PubMatic-OpenWrap/prebid-server/adapters" + "github.com/PubMatic-OpenWrap/prebid-server/errortypes" + "github.com/PubMatic-OpenWrap/prebid-server/openrtb_ext" +) + +const ( + spotxURL = `https://search.spotxchange.com/vast/2.00/85394?VPI=MP4&app[bundle]=[REPLACE_ME]&app[name]=[REPLACE_ME]&app[cat]=[REPLACE_ME]&app[domain]=[REPLACE_ME]&app[privacypolicy]=[REPLACE_ME]&app[storeurl]=[REPLACE_ME]&app[ver]=[REPLACE_ME]&cb=[REPLACE_ME]&device[devicetype]=[REPLACE_ME]&device[ifa]=[REPLACE_ME]&device[make]=[REPLACE_ME]&device[model]=[REPLACE_ME]&device[dnt]=[REPLACE_ME]&player_height=[REPLACE_ME]&player_width=[REPLACE_ME]&ip_addr=[REPLACE_ME]&device[ua]=[REPLACE_ME]]&schain=[REPLACE_ME]` + spotxFixedQueryParams = `` + spotxVariableQueryParams = `` +) + +//SpotxBidderMacro contains openrtb macros for spotx adapter +type SpotxBidderMacro struct { + *BidderMacro + + /*bidder specific extensions*/ + ext *openrtb_ext.ExtImpSpotX +} + +var spotxMapper mapper +var spotxCustomMapper map[string]func(*SpotxBidderMacro) string + +//NewSpotxBidderMacro contains spotx specific parameter parsing +func NewSpotxBidderMacro(request *openrtb.BidRequest) *SpotxBidderMacro { + bidder := &SpotxBidderMacro{ + BidderMacro: NewBidderMacro(request), + } + return bidder +} + +//LoadImpression will set current imp +func (tag *SpotxBidderMacro) LoadImpression(imp *openrtb.Imp) error { + tag.imp = imp + + //reload ext object + var bidderExt adapters.ExtImpBidder + if err := json.Unmarshal(imp.Ext, &bidderExt); err != nil { + return &errortypes.BadInput{Message: err.Error()} + } + + var spotxExt openrtb_ext.ExtImpSpotX + if err := json.Unmarshal(bidderExt.Bidder, &spotxExt); err != nil { + return &errortypes.BadInput{Message: err.Error()} + } + + tag.ext = &spotxExt + return nil +} + +//URL will set current imp +func (tag *SpotxBidderMacro) URL() string { + return spotxURL +} + +//Name will set current imp +func (tag *SpotxBidderMacro) Name() string { + return `spotx` +} + +//Custom contains definition for CacheBuster Parameter +func (tag *SpotxBidderMacro) Custom(key string) string { + //First Method + if callback, ok := spotxCustomMapper[key]; ok { + return callback(tag) + } + + //Second Method + switch key { + case `channel_id`: + //do processing + return channelID(tag) + } + return "" +} + +//MacroVideoAPI overriding default behaviour of MacroVideoAPI +func (tag *SpotxBidderMacro) MacroVideoAPI(key string) string { + return "MP4" +} + +func channelID(tag *SpotxBidderMacro) string { + return tag.ext.ChannelID +} + +//Second Method of Adding Custom Macro's +func addCustomMacro(key string, cached bool, callback func(*SpotxBidderMacro) string) { + spotxMapper.AddCustomMacro(key, cached) + spotxCustomMapper[key] = callback +} + +func initSpotxMapper() { + spotxMapper = GetNewDefaultMapper() + /* + //updating parameter caching status + spotxMapper.SetCache(MacroTest, true) + */ + + /* + //adding custom macros + //First Method + spotxMapper.AddCustomMacro(`ad_unit"`,false) + + //Second Method + addCustomMacro(`channel_id`, false, channelID) + */ + + SetBidderMapper(`spotx`, spotxMapper) +} + +func init() { + initSpotxMapper() +} + +/* +Custom Mapper Example +var spotxCustomMapper map[string]func(*SpotxBidderMacro) string + +//Second Method of Adding Custom Macro's +func addCustomMacro(key string, cached bool, callback func(*SpotxBidderMacro) string) { + spotxMapper.AddCustomMacro(key, cached) + spotxCustomMapper[key] = callback +} + +//Second Method +addCustomMacro(`channel_id`, false, channelID) + +//Custom contains definition for CacheBuster Parameter +func (tag *SpotxBidderMacro) Custom(key string) string { + //First Method + if callback, ok := spotxCustomMapper[key]; ok { + return callback(tag) + } +} + +func channelID(tag *SpotxBidderMacro) string { + return tag.ext.ChannelID +} + +*/ + +/* +https://search.spotxchange.com/vast/2.00/85394?VPI=MP4&app[bundle]=[REPLACE_ME]&app[name]=[REPLACE_ME]&app[cat]=[REPLACE_ME]&app[domain]=[REPLACE_ME]&app[privacypolicy]=[REPLACE_ME]&app[storeurl]=[REPLACE_ME]&app[ver]=[REPLACE_ME]&cb=[REPLACE_ME]&device[devicetype]=[REPLACE_ME]&device[ifa]=[REPLACE_ME]&device[make]=[REPLACE_ME]&device[model]=[REPLACE_ME]&device[dnt]=[REPLACE_ME]&player_height=[REPLACE_ME]&player_width=[REPLACE_ME]&ip_addr=[REPLACE_ME]&device[ua]=[REPLACE_ME]]&schain=[REPLACE_ME] + +https://search.spotxchange.com/vast/2.00/85394?VPI=MP4&app[bundle]=roku.weatherapp&app[name]=myctvapp&app[cat]=IAB6-8&app[domain]=http%3A%2F%2Fpublishername.com/appname&app[privacypolicy]=1&app[storeurl]=http%3A%2F%2Fchannelstore.roku.com/details/11055/weatherapp&app[ver]=1.2.1&cb=7437276459847&device[devicetype]=7&device[ifa]=236A005B-700F-4889-B9CE-999EAB2B605D&device[make]=Roku&device[model]=Roku&device[dnt]=0&player_height=1080&player_width=1920&ip_addr=165.23.234.23&device[ua]=Roku%2FDVP-7.10%2520(047.10E04062A)]&schain=1.0,1!exchange1.com,1234,1,bid-request-1,publisher,publisher.com,ext_stuff!exchange2.com,abcd,1,bid-request2,intermediary,intermediary.com,other_ext_stuff +*/ diff --git a/adapters/tagbidder/tagbidder_test.go b/adapters/tagbidder/tagbidder_test.go new file mode 100644 index 00000000000..3cc1cf430be --- /dev/null +++ b/adapters/tagbidder/tagbidder_test.go @@ -0,0 +1,31 @@ +package tagbidder + +import ( + "fmt" + "net/http" + "testing" + + "github.com/PubMatic-OpenWrap/openrtb" +) + +func getHTTPRequest(tagBidder ITagBidder, mp *MacroProcessor, bidRequest *openrtb.BidRequest) { + for i := range bidRequest.Imp { + tagBidder.LoadImpression(&bidRequest.Imp[i]) + queryString := mp.Process(tagBidder.URL()) + fmt.Printf("Query:%v\n", queryString) + } +} + +func TestBidder(t *testing.T) { + var bidRequest *openrtb.BidRequest + tagBidder := NewSpotxBidderMacro(bidRequest) + mapper := GetBidderMapper(tagBidder.Name()) + mp := NewMacroProcessor(mapper) + + getHTTPRequest(tagBidder, mp, bidRequest) +} + +type IRequestHandler interface { + GetHeaders() http.Header + GetHTTP +}