Skip to content

Commit

Permalink
OTT-54 Adding Default VAST Bidder Implementation
Browse files Browse the repository at this point in the history
  • Loading branch information
pm-viral-vala committed Jan 12, 2021
1 parent c9e9c82 commit fde6dc4
Showing 22 changed files with 177 additions and 218 deletions.
70 changes: 0 additions & 70 deletions adapters/tagbidder/bidder_config.go.bak

This file was deleted.

Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
package tagbidder
package vastbidder

import (
"encoding/json"
@@ -21,17 +21,17 @@ type BidderMacro struct {

//Configuration Parameters
Conf *config.Adapter
//BidderConf *BidderConfig

//OpenRTB Specific Parameters
Request *openrtb.BidRequest
IsApp bool
HasGeo bool
Imp *openrtb.Imp
Publisher *openrtb.Publisher
Content *openrtb.Content
UserExt *openrtb_ext.ExtUser
RegsExt *openrtb_ext.ExtRegs
Request *openrtb.BidRequest
IsApp bool
HasGeo bool
Imp *openrtb.Imp
ImpBidderExt map[string]interface{}
Publisher *openrtb.Publisher
Content *openrtb.Content
UserExt *openrtb_ext.ExtUser
RegsExt *openrtb_ext.ExtRegs
}

//NewBidderMacro contains definition for all openrtb macro's
@@ -78,46 +78,41 @@ func (tag *BidderMacro) InitBidRequest(request *openrtb.BidRequest) {
//LoadImpression will set current imp
func (tag *BidderMacro) LoadImpression(imp *openrtb.Imp) error {
tag.Imp = imp
return nil
}

//GetBidderKeys will set bidder level keys
func (tag *BidderMacro) GetBidderKeys() map[string]string {
var bidderExt adapters.ExtImpBidder
if err := json.Unmarshal(tag.Imp.Ext, &bidderExt); err != nil {
return nil
if err := json.Unmarshal(imp.Ext, &bidderExt); err != nil {
return err
}

ext := map[string]interface{}{}
if err := json.Unmarshal(bidderExt.Bidder, &ext); err != nil {
return nil
tag.ImpBidderExt = map[string]interface{}{}
if err := json.Unmarshal(bidderExt.Bidder, &tag.ImpBidderExt); err != nil {
return err
}

return normalizeJSON(ext)
return nil
}

//GetBidderKeys will set bidder level keys
func (tag *BidderMacro) GetBidderKeys() map[string]string {
return NormalizeJSON(tag.ImpBidderExt)
}

//SetAdapterConfig will set Adapter config
func (tag *BidderMacro) SetAdapterConfig(conf *config.Adapter) {
tag.Conf = conf
}

/*
//SetBidderConfig will set Bidder config
func (tag *BidderMacro) SetBidderConfig(conf *BidderConfig) {
tag.BidderConf = conf
}
*/

//GetURI get URL
func (tag *BidderMacro) GetURI() string {
//1. check for impression level URL
//2. check for bidder config level URL
//3. check for adapter config level URL
/*
if nil != tag.BidderConf && len(tag.BidderConf.URL) > 0 {
return tag.BidderConf.URL

//check for URI at impression level
if nil != tag.ImpBidderExt {
if value, ok := tag.ImpBidderExt["url"]; ok {
return value.(string)
}
*/
}

//check for URI at config level
return tag.Conf.Endpoint
}

@@ -300,7 +295,7 @@ func (tag *BidderMacro) MacroVideoMaximumDuration(key string) string {
func (tag *BidderMacro) MacroVideoProtocols(key string) string {
if nil != tag.Imp.Video {
value := tag.Imp.Video.Protocols
return objectArrayToString(len(value), comma, func(i int) string {
return ObjectArrayToString(len(value), comma, func(i int) string {
return strconv.FormatInt(int64(value[i]), intBase)
})
}
@@ -383,7 +378,7 @@ func (tag *BidderMacro) MacroVideoSequence(key string) string {
func (tag *BidderMacro) MacroVideoBlockedAttribute(key string) string {
if nil != tag.Imp.Video {
value := tag.Imp.Video.BAttr
return objectArrayToString(len(value), comma, func(i int) string {
return ObjectArrayToString(len(value), comma, func(i int) string {
return strconv.FormatInt(int64(value[i]), intBase)
})
}
@@ -426,7 +421,7 @@ func (tag *BidderMacro) MacroVideoBoxing(key string) string {
func (tag *BidderMacro) MacroVideoPlaybackMethod(key string) string {
if nil != tag.Imp.Video {
value := tag.Imp.Video.PlaybackMethod
return objectArrayToString(len(value), comma, func(i int) string {
return ObjectArrayToString(len(value), comma, func(i int) string {
return strconv.FormatInt(int64(value[i]), intBase)
})
}
@@ -437,7 +432,7 @@ func (tag *BidderMacro) MacroVideoPlaybackMethod(key string) string {
func (tag *BidderMacro) MacroVideoDelivery(key string) string {
if nil != tag.Imp.Video {
value := tag.Imp.Video.Delivery
return objectArrayToString(len(value), comma, func(i int) string {
return ObjectArrayToString(len(value), comma, func(i int) string {
return strconv.FormatInt(int64(value[i]), intBase)
})
}
@@ -456,7 +451,7 @@ func (tag *BidderMacro) MacroVideoPosition(key string) string {
func (tag *BidderMacro) MacroVideoAPI(key string) string {
if nil != tag.Imp.Video {
value := tag.Imp.Video.API
return objectArrayToString(len(value), comma, func(i int) string {
return ObjectArrayToString(len(value), comma, func(i int) string {
return strconv.FormatInt(int64(value[i]), intBase)
})
}
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
package tagbidder
package vastbidder

const (
intBase = 10
@@ -153,11 +153,3 @@ const (
//Additional
MacroCacheBuster = `cachebuster`
)

//ResponseHandlerType list of tag based response handlers
type ResponseHandlerType string

const (
OpenRTBResponseHandlerType ResponseHandlerType = `openrtb`
VASTTagResponseHandlerType ResponseHandlerType = `vasttag`
)
Original file line number Diff line number Diff line change
@@ -1,9 +1,10 @@
package tagbidder
package vastbidder

import (
"errors"
"net/http"

"github.com/PubMatic-OpenWrap/prebid-server/openrtb_ext"

"github.com/PubMatic-OpenWrap/openrtb"
"github.com/PubMatic-OpenWrap/prebid-server/config"
)
@@ -20,7 +21,6 @@ type IBidderMacro interface {
LoadImpression(imp *openrtb.Imp) error
GetBidderKeys() map[string]string
SetAdapterConfig(*config.Adapter)
//SetBidderConfig(*BidderConfig)
GetURI() string
GetHeaders() http.Header

@@ -171,22 +171,18 @@ type IBidderMacro interface {
MacroCacheBuster(string) string
}

var bidderMacroMap = map[string]func() IBidderMacro{}
var bidderMacroMap = map[openrtb_ext.BidderName]func() IBidderMacro{}

//RegisterNewBidderMacro will be used by each bidder to set its respective macro IBidderMacro
func RegisterNewBidderMacro(bidder string, macro func() IBidderMacro) {
func RegisterNewBidderMacro(bidder openrtb_ext.BidderName, macro func() IBidderMacro) {
bidderMacroMap[bidder] = macro
}

//GetNewBidderMacro will return IBidderMacro of specific bidder
func GetNewBidderMacro(bidder string) (IBidderMacro, error) {
func GetNewBidderMacro(bidder openrtb_ext.BidderName) IBidderMacro {
callback, ok := bidderMacroMap[bidder]
if ok {
return callback(), nil
return callback()
}
return nil, errors.New(`missing bidder macro`)
}

func init() {
RegisterNewBidderMacro(`spotx`, NewBidderMacro)
return NewBidderMacro()
}
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
package tagbidder
package vastbidder

import (
"errors"
@@ -13,6 +13,13 @@ type ITagResponseHandler interface {
MakeBids(internalRequest *openrtb.BidRequest, externalRequest *adapters.RequestData, response *adapters.ResponseData) (*adapters.BidderResponse, []error)
}

//ResponseHandlerType list of tag based response handlers
type ResponseHandlerType string

const (
VASTTagResponseHandlerType ResponseHandlerType = `vasttag`
)

//GetResponseHandler returns response handler
func GetResponseHandler(responseType ResponseHandlerType) (ITagResponseHandler, error) {
switch responseType {
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
package tagbidder
package vastbidder

import (
"bytes"
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
package tagbidder
package vastbidder

type macroCallBack struct {
cached bool
@@ -165,7 +165,7 @@ var _defaultMapper = Mapper{
MacroCacheBuster: &macroCallBack{cached: false, callback: IBidderMacro.MacroCacheBuster},
}

//GetNewDefaultMapper will return clone of default Mapper function
func GetNewDefaultMapper() Mapper {
//GetDefaultMapper will return clone of default Mapper function
func GetDefaultMapper() Mapper {
return _defaultMapper.clone()
}
26 changes: 26 additions & 0 deletions adapters/vastbidder/sample_spotx_macro.go.bak
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
package vastbidder

import (
"github.com/PubMatic-OpenWrap/prebid-server/openrtb_ext"
)

//SpotxMacro default implementation
type SpotxMacro struct {
*BidderMacro
}

//NewSpotxMacro contains definition for all openrtb macro's
func NewSpotxMacro() IBidderMacro {
return &SpotxMacro{
BidderMacro: &BidderMacro{},
}
}

//GetBidderKeys will set bidder level keys
func (tag *SpotxMacro) GetBidderKeys() map[string]string {
return NormalizeJSON(tag.ImpBidderExt)
}

func init() {
RegisterNewBidderMacro(openrtb_ext.BidderSpotX, NewSpotxMacro)
}
Loading

0 comments on commit fde6dc4

Please sign in to comment.