Skip to content
This repository has been archived by the owner on Dec 22, 2022. It is now read-only.

Commit

Permalink
Rename indexExchange to ix (prebid#657) (prebid#712)
Browse files Browse the repository at this point in the history
  • Loading branch information
ix-certification authored and dbemiller committed Oct 22, 2018
1 parent 592b16a commit edc4959
Show file tree
Hide file tree
Showing 18 changed files with 228 additions and 102 deletions.
58 changes: 30 additions & 28 deletions adapters/indexExchange/index.go → adapters/ix/ix.go
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
package indexExchange
package ix

import (
"bytes"
Expand All @@ -17,31 +17,31 @@ import (
"github.com/prebid/prebid-server/errortypes"
)

type IndexAdapter struct {
type IxAdapter struct {
http *adapters.HTTPAdapter
URI string
}

// used for cookies and such
func (a *IndexAdapter) Name() string {
return "indexExchange"
func (a *IxAdapter) Name() string {
return "ix"
}

func (a *IndexAdapter) SkipNoCookies() bool {
func (a *IxAdapter) SkipNoCookies() bool {
return false
}

type indexParams struct {
SiteID int `json:"siteID"`
SiteID string `json:"siteId"`
}

func (a *IndexAdapter) Call(ctx context.Context, req *pbs.PBSRequest, bidder *pbs.PBSBidder) (pbs.PBSBidSlice, error) {
func (a *IxAdapter) Call(ctx context.Context, req *pbs.PBSRequest, bidder *pbs.PBSBidder) (pbs.PBSBidSlice, error) {
if req.App != nil {
return nil, &errortypes.BadInput{
Message: "Index doesn't support apps",
}
}
mediaTypes := []pbs.MediaType{pbs.MEDIA_TYPE_BANNER, pbs.MEDIA_TYPE_VIDEO}
mediaTypes := []pbs.MediaType{pbs.MEDIA_TYPE_BANNER}
indexReq, err := adapters.MakeOpenRTBGeneric(req, bidder, a.Name(), mediaTypes)

if err != nil {
Expand All @@ -56,9 +56,9 @@ func (a *IndexAdapter) Call(ctx context.Context, req *pbs.PBSRequest, bidder *pb
Message: fmt.Sprintf("unmarshal params '%s' failed: %v", unit.Params, err),
}
}
if params.SiteID == 0 {
if params.SiteID == "" {
return nil, &errortypes.BadInput{
Message: "Missing siteID param",
Message: "Missing siteId param",
}
}

Expand All @@ -72,7 +72,7 @@ func (a *IndexAdapter) Call(ctx context.Context, req *pbs.PBSRequest, bidder *pb
// ext is DFP div ID and KV pairs if avail
//indexReq.Imp[i].Ext = json.RawMessage("{}")
siteCopy := *indexReq.Site
siteCopy.Publisher = &openrtb.Publisher{ID: fmt.Sprintf("%d", params.SiteID)}
siteCopy.Publisher = &openrtb.Publisher{ID: fmt.Sprintf("%s", params.SiteID)}
indexReq.Site = &siteCopy
}
// spec also asks for publisher id if set
Expand Down Expand Up @@ -136,38 +136,40 @@ func (a *IndexAdapter) Call(ctx context.Context, req *pbs.PBSRequest, bidder *pb

bids := make(pbs.PBSBidSlice, 0)

numBids := 0
for _, sb := range bidResp.SeatBid {
for i, bid := range sb.Bid {
numBids++

for _, bid := range sb.Bid {
bidID := bidder.LookupBidID(bid.ImpID)
if bidID == "" {
return nil, &errortypes.BadServerResponse{
Message: fmt.Sprintf("Unknown ad unit code '%s'", bid.ImpID),
}
}

pbid := pbs.PBSBid{
BidID: bidID,
AdUnitCode: bidder.AdUnits[i].Code, // todo: check this
BidderCode: bidder.BidderCode,
Price: bid.Price,
Adm: bid.AdM,
Creative_id: bid.CrID,
Width: bid.W,
Height: bid.H,
DealId: bid.DealID,
for _, adunit := range bidder.AdUnits {
if adunit.BidID == bidID {
pbid := pbs.PBSBid{
BidID: bidID,
AdUnitCode: adunit.Code,
BidderCode: bidder.BidderCode,
Price: bid.Price,
Adm: bid.AdM,
Creative_id: bid.CrID,
Width: bid.W,
Height: bid.H,
DealId: bid.DealID,
CreativeMediaType: "banner",
}
bids = append(bids, &pbid)
}
}
bids = append(bids, &pbid)
}
}
return bids, nil
}

func NewIndexAdapter(config *adapters.HTTPAdapterConfig, uri string) *IndexAdapter {
func NewIxAdapter(config *adapters.HTTPAdapterConfig, uri string) *IxAdapter {
a := adapters.NewHTTPAdapter(config)
return &IndexAdapter{
return &IxAdapter{
http: a,
URI: uri,
}
Expand Down
Loading

0 comments on commit edc4959

Please sign in to comment.