Skip to content

Commit

Permalink
Merge pull request #1 in SA/sync-prebid-server from CAP-1467 to synac…
Browse files Browse the repository at this point in the history
…ormedia-updates

* commit '36bd18f75c15a1c3d13315ec9c6f083e13792e57':
  CAP-1467 - updates for github comments
  • Loading branch information
Corey Kress authored and Corey Kress committed Oct 7, 2019
2 parents e17042b + 36bd18f commit 0ce2f35
Showing 1 changed file with 16 additions and 9 deletions.
25 changes: 16 additions & 9 deletions adapters/synacormedia/synacormedia.go
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,6 @@ func NewSynacorMediaBidder(endpointTemplate string) adapters.Bidder {
syncTemplate, err := template.New("endpointTemplate").Parse(endpointTemplate)
if err != nil {
glog.Fatal("Unable to parse endpoint url template")
glog.Fatal(endpointTemplate)
return nil
}
return &SynacorMediaAdapter{EndpointTemplate: *syncTemplate}
Expand All @@ -53,29 +52,28 @@ func (a *SynacorMediaAdapter) makeRequest(request *openrtb.BidRequest) (*adapter
var errs []error
var validImps []openrtb.Imp
var re *ReqExt
var firstExtImp *openrtb_ext.ExtImpSynacormedia = nil

for _, imp := range request.Imp {
_, err := getExtImpObj(&imp)
validImp, err := getExtImpObj(&imp)
if err != nil {
errs = append(errs, err)
continue
}
validImps = append(validImps, imp)
if firstExtImp == nil {
firstExtImp = validImp
}
}

if len(validImps) == 0 {
return nil, errs
}

var err error
// need to grab an impression to get the seat id
var firstImp = validImps[0]
firstExtImp, err := getExtImpObj(&firstImp)
if err != nil {
return nil, append(errs, err)
}

if firstExtImp.SeatId == "" {
if firstExtImp == nil || firstExtImp.SeatId == "" {
return nil, append(errs, &errortypes.BadServerResponse{
Message: fmt.Sprintf("Impression missing seat id"),
})
Expand All @@ -97,6 +95,7 @@ func (a *SynacorMediaAdapter) makeRequest(request *openrtb.BidRequest) (*adapter
// set Request Headers
headers := http.Header{}
headers.Add("Content-Type", "application/json;charset=utf-8")
headers.Add("Accept", "application/json")

// create Request Uri
reqUri, err := a.buildEndpointURL(firstExtImp)
Expand Down Expand Up @@ -159,11 +158,19 @@ func (a *SynacorMediaAdapter) MakeBids(internalRequest *openrtb.BidRequest, exte

bidResponse := adapters.NewBidderResponseWithBidsCapacity(1)

// filter out non banner and non video imps
var validRequestImps []openrtb.Imp
for _, imp := range internalRequest.Imp {
if imp.Banner != nil || imp.Video != nil {
validRequestImps = append(validRequestImps, imp)
}
}

for _, sb := range bidResp.SeatBid {
for i := range sb.Bid {
bidResponse.Bids = append(bidResponse.Bids, &adapters.TypedBid{
Bid: &sb.Bid[i],
BidType: getMediaTypeForImp(sb.Bid[i].ImpID, internalRequest.Imp),
BidType: getMediaTypeForImp(sb.Bid[i].ImpID, validRequestImps),
})
}
}
Expand Down

0 comments on commit 0ce2f35

Please sign in to comment.