Skip to content

Commit

Permalink
Resolve merge conflicts
Browse files Browse the repository at this point in the history
  • Loading branch information
benben2001 committed Aug 7, 2024
2 parents e4fa1f8 + 804334a commit aaf0f8f
Show file tree
Hide file tree
Showing 210 changed files with 12,767 additions and 1,047 deletions.
8 changes: 7 additions & 1 deletion adapters/adtarget/adtarget.go
Original file line number Diff line number Diff line change
Expand Up @@ -185,7 +185,13 @@ func validateImpressionAndSetExt(imp *openrtb2.Imp) (int, error) {

imp.Ext = impExtBuffer

return impExt.SourceId, nil
aid, err := impExt.SourceId.Int64()
if err != nil {
return 0, &errortypes.BadInput{
Message: fmt.Sprintf("ignoring imp id=%s, aid parsing err: %s", imp.ID, err),
}
}
return int(aid), nil
}

// Builder builds a new instance of the Adtarget adapter for the given bidder with the given config.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@

"expectedMakeRequestsErrors": [
{
"value": "ignoring imp id=unsupported-native-imp, error while decoding impExt, err: json: cannot unmarshal string into Go struct field ExtImpAdtarget.aid of type int",
"value": "ignoring imp id=unsupported-native-imp, error while decoding impExt, err: json: invalid number literal, trying to unmarshal \"\\\"some string instead of int\\\"\" into Number",
"comparison": "literal"
}
]
Expand Down
12 changes: 8 additions & 4 deletions adapters/adtarget/params_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -33,16 +33,21 @@ func TestInvalidParams(t *testing.T) {

for _, invalidParam := range invalidParams {
if err := validator.Validate(openrtb_ext.BidderAdtarget, json.RawMessage(invalidParam)); err == nil {
t.Errorf("Schema allowed unexpected params: %s", invalidParam)
ext := openrtb_ext.ExtImpAdtarget{}
err = json.Unmarshal([]byte(invalidParam), &ext)
if err == nil {
t.Errorf("Schema allowed unexpected params: %s", invalidParam)
}
}
}
}

var validParams = []string{
`{"aid":123}`,
`{"aid":"123"}`,
`{"aid":123,"placementId":1234}`,
`{"aid":123,"siteId":4321}`,
`{"aid":123,"siteId":0,"bidFloor":0}`,
`{"aid":"123","siteId":0,"bidFloor":0}`,
}

var invalidParams = []string{
Expand All @@ -53,8 +58,7 @@ var invalidParams = []string{
`4.2`,
`[]`,
`{}`,
`{"aid":"123"}`,
`{"aid":"0"}`,
`{"aid":"qwerty"}`,
`{"aid":"123","placementId":"123"}`,
`{"aid":123, "placementId":"123", "siteId":"321"}`,
}
8 changes: 7 additions & 1 deletion adapters/adtelligent/adtelligent.go
Original file line number Diff line number Diff line change
Expand Up @@ -187,7 +187,13 @@ func validateImpression(imp *openrtb2.Imp) (int, error) {

imp.Ext = impExtBuffer

return impExt.SourceId, nil
aid, err := impExt.SourceId.Int64()
if err != nil {
return 0, &errortypes.BadInput{
Message: fmt.Sprintf("ignoring imp id=%s, aid parsing err: %s", imp.ID, err),
}
}
return int(aid), nil
}

// Builder builds a new instance of the Adtelligent adapter for the given bidder with the given config.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@

"expectedMakeRequestsErrors": [
{
"value": "ignoring imp id=unsupported-native-imp, error while decoding impExt, err: json: cannot unmarshal string into Go struct field ExtImpAdtelligent.aid of type int",
"value": "ignoring imp id=unsupported-native-imp, error while decoding impExt, err: json: invalid number literal, trying to unmarshal \"\\\"some string instead of int\\\"\" into Number",
"comparison": "literal"
}
]
Expand Down
12 changes: 8 additions & 4 deletions adapters/adtelligent/params_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -33,16 +33,21 @@ func TestInvalidParams(t *testing.T) {

for _, invalidParam := range invalidParams {
if err := validator.Validate(openrtb_ext.BidderAdtelligent, json.RawMessage(invalidParam)); err == nil {
t.Errorf("Schema allowed unexpected params: %s", invalidParam)
ext := openrtb_ext.ExtImpAdtelligent{}
err = json.Unmarshal([]byte(invalidParam), &ext)
if err == nil {
t.Errorf("Schema allowed unexpected params: %s", invalidParam)
}
}
}
}

var validParams = []string{
`{"aid":123}`,
`{"aid":"123"}`,
`{"aid":123,"placementId":1234}`,
`{"aid":123,"siteId":4321}`,
`{"aid":123,"siteId":0,"bidFloor":0}`,
`{"aid":"123","siteId":0,"bidFloor":0}`,
}

var invalidParams = []string{
Expand All @@ -53,8 +58,7 @@ var invalidParams = []string{
`4.2`,
`[]`,
`{}`,
`{"aid":"123"}`,
`{"aid":"0"}`,
`{"aid":"qwerty"}`,
`{"aid":"123","placementId":"123"}`,
`{"aid":123, "placementId":"123", "siteId":"321"}`,
}
156 changes: 156 additions & 0 deletions adapters/bigoad/bigoad.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,156 @@
package bigoad

import (
"encoding/json"
"fmt"
"net/http"
"text/template"

"github.com/prebid/openrtb/v20/openrtb2"
"github.com/prebid/prebid-server/v2/adapters"
"github.com/prebid/prebid-server/v2/config"
"github.com/prebid/prebid-server/v2/errortypes"
"github.com/prebid/prebid-server/v2/macros"
"github.com/prebid/prebid-server/v2/openrtb_ext"
)

type adapter struct {
endpoint *template.Template
}

func Builder(bidderName openrtb_ext.BidderName, config config.Adapter, server config.Server) (adapters.Bidder, error) {
template, err := template.New("endpointTemplate").Parse(config.Endpoint)
if err != nil {
return nil, fmt.Errorf("unable to parse endpoint url template: %v", err)
}

bidder := &adapter{
endpoint: template,
}

return bidder, nil
}

func (a *adapter) MakeRequests(request *openrtb2.BidRequest, requestInfo *adapters.ExtraRequestInfo) ([]*adapters.RequestData, []error) {
bigoadExt, err := getImpExt(&request.Imp[0])
if err != nil {
return nil, []error{err}
}

resolvedUrl, err := a.buildEndpointURL(bigoadExt)
if err != nil {
return nil, []error{err}
}

requestJSON, err := json.Marshal(request)
if err != nil {
return nil, []error{err}
}

requestData := &adapters.RequestData{
Method: "POST",
Uri: resolvedUrl,
Body: requestJSON,
Headers: getHeaders(request),
ImpIDs: openrtb_ext.GetImpIDs(request.Imp),
}

return []*adapters.RequestData{requestData}, nil
}

func getHeaders(request *openrtb2.BidRequest) http.Header {
headers := http.Header{}
addNonEmptyHeaders(&headers, map[string]string{
"Content-Type": "application/json;charset=utf-8",
"Accept": "application/json",
"x-openrtb-version": "2.5",
})
return headers
}

func addNonEmptyHeaders(headers *http.Header, headerValues map[string]string) {
for key, value := range headerValues {
if len(value) > 0 {
headers.Add(key, value)
}
}
}

func getImpExt(imp *openrtb2.Imp) (*openrtb_ext.ExtImpBigoAd, error) {
var bidderExt adapters.ExtImpBidder
if err := json.Unmarshal(imp.Ext, &bidderExt); err != nil {
return nil, &errortypes.BadInput{
Message: fmt.Sprintf("imp %s: unable to unmarshal ext", imp.ID),
}
}
var bigoadExt openrtb_ext.ExtImpBigoAd
if err := json.Unmarshal(bidderExt.Bidder, &bigoadExt); err != nil {
return nil, &errortypes.BadInput{
Message: fmt.Sprintf("imp %s: unable to unmarshal ext.bidder: %v", imp.ID, err),
}
}
imp.Ext = bidderExt.Bidder
return &bigoadExt, nil
}

func (a *adapter) buildEndpointURL(params *openrtb_ext.ExtImpBigoAd) (string, error) {
endpointParams := macros.EndpointTemplateParams{SspId: params.SspId}
return macros.ResolveMacros(a.endpoint, endpointParams)
}

func (a *adapter) MakeBids(request *openrtb2.BidRequest, _ *adapters.RequestData, responseData *adapters.ResponseData) (*adapters.BidderResponse, []error) {
if adapters.IsResponseStatusCodeNoContent(responseData) {
return nil, nil
}

if err := adapters.CheckResponseStatusCodeForErrors(responseData); err != nil {
return nil, []error{err}
}

var bidResponse openrtb2.BidResponse
if err := json.Unmarshal(responseData.Body, &bidResponse); err != nil {
return nil, []error{&errortypes.BadServerResponse{
Message: fmt.Sprintf("Bad server response: %d", err),
}}
}

if len(bidResponse.SeatBid) == 0 {
return nil, []error{&errortypes.BadServerResponse{
Message: "Empty SeatBid array",
}}
}

bidResponseWithCapacity := adapters.NewBidderResponseWithBidsCapacity(len(bidResponse.SeatBid[0].Bid))

var errors []error
seatBid := bidResponse.SeatBid[0]
for i := range seatBid.Bid {
bid := seatBid.Bid[i]
bidType, err := getBidType(request.Imp[0], bid)
if err != nil {
errors = append(errors, err)
continue
}
bidResponseWithCapacity.Bids = append(bidResponseWithCapacity.Bids, &adapters.TypedBid{
Bid: &bid,
BidType: bidType,
})
}

return bidResponseWithCapacity, errors
}

func getBidType(imp openrtb2.Imp, bid openrtb2.Bid) (openrtb_ext.BidType, error) {
switch bid.MType {
case openrtb2.MarkupBanner:
return openrtb_ext.BidTypeBanner, nil
case openrtb2.MarkupNative:
return openrtb_ext.BidTypeNative, nil
case openrtb2.MarkupVideo:
return openrtb_ext.BidTypeVideo, nil
}

return "", &errortypes.BadInput{
Message: fmt.Sprintf("unrecognized bid type in response from bigoad %s", imp.ID),
}
}
29 changes: 29 additions & 0 deletions adapters/bigoad/bigoad_test.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
package bigoad

import (
"testing"

"github.com/prebid/prebid-server/v2/adapters/adapterstest"
"github.com/prebid/prebid-server/v2/config"
"github.com/prebid/prebid-server/v2/openrtb_ext"
"github.com/stretchr/testify/assert"
)

func TestJsonSamples(t *testing.T) {
bidder, buildErr := Builder(openrtb_ext.BidderBigoAd,
config.Adapter{Endpoint: "https://api.imotech.tech/Ad/GetAdOut?sspid={{.SspId}}"},
config.Server{ExternalUrl: "http://hosturl.com", GvlID: 1, DataCenter: "2"})

if buildErr != nil {
t.Fatalf("Builder returned unexpected error %v", buildErr)
}

adapterstest.RunJSONBidderTest(t, "bigoadtest", bidder)
}

func TestEndpointTemplateMalformed(t *testing.T) {
_, buildErr := Builder(openrtb_ext.BidderBigoAd, config.Adapter{
Endpoint: "{{Malformed}}"}, config.Server{ExternalUrl: "http://hosturl.com", GvlID: 1, DataCenter: "2"})

assert.Error(t, buildErr)
}
Loading

0 comments on commit aaf0f8f

Please sign in to comment.