forked from prebid/prebid-server
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge remote-tracking branch 'origin/master' into feature/smaato-adap…
…ter-video * origin/master: (26 commits) Fix bid dedup (prebid#1456) moving docs to website repo (prebid#1443) Fixing comment for usage of deal priority field (prebid#1451) Fix minor error message spelling mistake "vastml" -> "vastxml" (prebid#1455) Adform adapter: additional targeting params added (prebid#1424) Added adpod_id to request extension (prebid#1444) Fixes bug (prebid#1448) Validate External Cache Host (prebid#1422) Enable geo activation of GDPR flag (prebid#1427) Update the fallback GVL to last version (prebid#1440) Fix no bid debug log (prebid#1375) Eplanning adapter: Get domain from page (prebid#1434) Fix TCF1 Fetcher Fallback (prebid#1438) Refactor rate converter separating scheduler from converter logic to improve testability (prebid#1394) [WIP] Bid deduplication enhancement (prebid#1430) Video endpoint bid selection enhancements (prebid#1419) update to the latest go-gdpr release (prebid#1436) Default TCF1 GVL in anticipation of IAB no longer hosting the v1 GVL (prebid#1433) Tcf2 id support (prebid#1420) Remove redundad struct (prebid#1432) ...
- Loading branch information
Showing
142 changed files
with
5,664 additions
and
3,031 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,138 @@ | ||
package adprime | ||
|
||
import ( | ||
"encoding/json" | ||
"fmt" | ||
"net/http" | ||
|
||
"github.com/buger/jsonparser" | ||
"github.com/mxmCherry/openrtb" | ||
"github.com/prebid/prebid-server/adapters" | ||
"github.com/prebid/prebid-server/errortypes" | ||
"github.com/prebid/prebid-server/openrtb_ext" | ||
) | ||
|
||
// AdprimeAdapter struct | ||
type AdprimeAdapter struct { | ||
URI string | ||
} | ||
|
||
// NewAdprimeBidder Initializes the Bidder | ||
func NewAdprimeBidder(endpoint string) *AdprimeAdapter { | ||
return &AdprimeAdapter{ | ||
URI: endpoint, | ||
} | ||
} | ||
|
||
// MakeRequests create bid request for adprime demand | ||
func (a *AdprimeAdapter) MakeRequests(request *openrtb.BidRequest, reqInfo *adapters.ExtraRequestInfo) ([]*adapters.RequestData, []error) { | ||
var errs []error | ||
var err error | ||
var tagID string | ||
|
||
var adapterRequests []*adapters.RequestData | ||
|
||
reqCopy := *request | ||
for _, imp := range request.Imp { | ||
reqCopy.Imp = []openrtb.Imp{imp} | ||
|
||
tagID, err = jsonparser.GetString(reqCopy.Imp[0].Ext, "bidder", "TagID") | ||
if err != nil { | ||
errs = append(errs, err) | ||
continue | ||
} | ||
|
||
reqCopy.Imp[0].TagID = tagID | ||
|
||
adapterReq, errors := a.makeRequest(&reqCopy) | ||
if adapterReq != nil { | ||
adapterRequests = append(adapterRequests, adapterReq) | ||
} | ||
errs = append(errs, errors...) | ||
} | ||
return adapterRequests, errs | ||
} | ||
|
||
func (a *AdprimeAdapter) makeRequest(request *openrtb.BidRequest) (*adapters.RequestData, []error) { | ||
|
||
var errs []error | ||
|
||
reqJSON, err := json.Marshal(request) | ||
|
||
if err != nil { | ||
errs = append(errs, err) | ||
return nil, errs | ||
} | ||
|
||
headers := http.Header{} | ||
headers.Add("Content-Type", "application/json;charset=utf-8") | ||
headers.Add("Accept", "application/json") | ||
return &adapters.RequestData{ | ||
Method: "POST", | ||
Uri: a.URI, | ||
Body: reqJSON, | ||
Headers: headers, | ||
}, errs | ||
} | ||
|
||
// MakeBids makes the bids | ||
func (a *AdprimeAdapter) MakeBids(internalRequest *openrtb.BidRequest, externalRequest *adapters.RequestData, response *adapters.ResponseData) (*adapters.BidderResponse, []error) { | ||
var errs []error | ||
|
||
if response.StatusCode == http.StatusNoContent { | ||
return nil, nil | ||
} | ||
|
||
if response.StatusCode == http.StatusNotFound { | ||
return nil, []error{&errortypes.BadServerResponse{ | ||
Message: fmt.Sprintf("Page not found: %d. Run with request.debug = 1 for more info", response.StatusCode), | ||
}} | ||
} | ||
|
||
if response.StatusCode != http.StatusOK { | ||
return nil, []error{&errortypes.BadServerResponse{ | ||
Message: fmt.Sprintf("Unexpected status code: %d. Run with request.debug = 1 for more info", response.StatusCode), | ||
}} | ||
} | ||
|
||
var bidResp openrtb.BidResponse | ||
|
||
if err := json.Unmarshal(response.Body, &bidResp); err != nil { | ||
return nil, []error{err} | ||
} | ||
|
||
bidResponse := adapters.NewBidderResponseWithBidsCapacity(1) | ||
|
||
for _, sb := range bidResp.SeatBid { | ||
for i := range sb.Bid { | ||
bidType, err := getMediaTypeForImp(sb.Bid[i].ImpID, internalRequest.Imp) | ||
if err != nil { | ||
errs = append(errs, err) | ||
} else { | ||
b := &adapters.TypedBid{ | ||
Bid: &sb.Bid[i], | ||
BidType: bidType, | ||
} | ||
bidResponse.Bids = append(bidResponse.Bids, b) | ||
} | ||
} | ||
} | ||
return bidResponse, errs | ||
} | ||
|
||
func getMediaTypeForImp(impID string, imps []openrtb.Imp) (openrtb_ext.BidType, error) { | ||
mediaType := openrtb_ext.BidTypeBanner | ||
for _, imp := range imps { | ||
if imp.ID == impID { | ||
if imp.Banner == nil && imp.Video != nil { | ||
mediaType = openrtb_ext.BidTypeVideo | ||
} | ||
return mediaType, nil | ||
} | ||
} | ||
|
||
// This shouldnt happen. Lets handle it just incase by returning an error. | ||
return "", &errortypes.BadInput{ | ||
Message: fmt.Sprintf("Failed to find impression \"%s\" ", impID), | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,12 @@ | ||
package adprime | ||
|
||
import ( | ||
"testing" | ||
|
||
"github.com/prebid/prebid-server/adapters/adapterstest" | ||
) | ||
|
||
func TestJsonSamples(t *testing.T) { | ||
adprimeAdapter := NewAdprimeBidder("http://delta.adprime.com/?c=o&m=ortb") | ||
adapterstest.RunJSONBidderTest(t, "adprimetest", adprimeAdapter) | ||
} |
Oops, something went wrong.