Skip to content

Commit

Permalink
code refactoring
Browse files Browse the repository at this point in the history
  • Loading branch information
ashishshinde-pubm committed Mar 29, 2024
1 parent 3582ee7 commit 0671490
Show file tree
Hide file tree
Showing 9 changed files with 22 additions and 43 deletions.
2 changes: 0 additions & 2 deletions adapters/adapterstest/test_json.go
Original file line number Diff line number Diff line change
Expand Up @@ -162,8 +162,6 @@ func getTestExtraRequestInfo(t *testing.T, filename string, spec *testSpec, isAm
} else if isVideoTest {
reqInfo.PbsEntryPoint = "video"
}
reqInfo = updateRequestInfoForOW(reqInfo, filename) // OW specific : required for oRTB bidder

return &reqInfo
}

Expand Down
20 changes: 0 additions & 20 deletions adapters/adapterstest/test_json_ow.go

This file was deleted.

13 changes: 6 additions & 7 deletions adapters/ortbbidder/ortbbidder.go
Original file line number Diff line number Diff line change
Expand Up @@ -23,9 +23,9 @@ const (
// adapterInfo contains oRTB bidder specific info required in MakeRequests/MakeBids functions
type adapterInfo struct {
config.Adapter
requestMode string
extraInfo extraAdapterInfo
}
type ExtraAdapterInfo struct {
type extraAdapterInfo struct {
RequestMode string `json:"requestMode"`
}

Expand All @@ -47,15 +47,15 @@ func (o adapterInfo) prepareRequestData(request *openrtb2.BidRequest) (*adapters

// Builder returns an instance of oRTB adapter
func Builder(bidderName openrtb_ext.BidderName, config config.Adapter, server config.Server) (adapters.Bidder, error) {
extraAdapterInfo := ExtraAdapterInfo{}
extraAdapterInfo := extraAdapterInfo{}
if len(config.ExtraAdapterInfo) > 0 {
err := json.Unmarshal([]byte(config.ExtraAdapterInfo), &extraAdapterInfo)
if err != nil {
return nil, fmt.Errorf("Failed to parse extra_info for bidder:[%s] err:[%s]", bidderName, err.Error())
}
}
return &adapter{
adapterInfo: adapterInfo{config, extraAdapterInfo.RequestMode},
adapterInfo: adapterInfo{config, extraAdapterInfo},
}, nil
}

Expand All @@ -67,7 +67,7 @@ func (o *adapter) MakeRequests(request *openrtb2.BidRequest, requestInfo *adapte
var errs []error
adapterInfo := o.adapterInfo
// bidder request supports single impression in single HTTP call.
if adapterInfo.requestMode == RequestModeSingle {
if adapterInfo.extraInfo.RequestMode == RequestModeSingle {
requestData := make([]*adapters.RequestData, 0, len(request.Imp))
requestCopy := *request
for _, imp := range request.Imp {
Expand Down Expand Up @@ -107,7 +107,6 @@ func (o *adapter) MakeBids(request *openrtb2.BidRequest, requestData *adapters.R
bidResponse := adapters.BidderResponse{
Bids: make([]*adapters.TypedBid, 0),
}
var errs []error
for _, seatBid := range response.SeatBid {
for bidInd, bid := range seatBid.Bid {
bidResponse.Bids = append(bidResponse.Bids, &adapters.TypedBid{
Expand All @@ -116,7 +115,7 @@ func (o *adapter) MakeBids(request *openrtb2.BidRequest, requestData *adapters.R
})
}
}
return &bidResponse, errs
return &bidResponse, nil
}

// getMediaTypeForBid returns the BidType as per the bid.MType field
Expand Down
22 changes: 11 additions & 11 deletions adapters/ortbbidder/ortbbidder_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -57,7 +57,7 @@ func TestMakeRequests(t *testing.T) {
requestInfo: &adapters.ExtraRequestInfo{
BidderCoreName: openrtb_ext.BidderName("ortb_test_multi_requestmode"),
},
adapterInfo: adapterInfo{config.Adapter{Endpoint: "http://test_bidder.com"}, ""},
adapterInfo: adapterInfo{config.Adapter{Endpoint: "http://test_bidder.com"}, extraAdapterInfo{RequestMode: ""}},
},
want: want{
requestData: []*adapters.RequestData{
Expand All @@ -82,7 +82,7 @@ func TestMakeRequests(t *testing.T) {
requestInfo: &adapters.ExtraRequestInfo{
BidderCoreName: openrtb_ext.BidderName("ortb_test_single_requestmode"),
},
adapterInfo: adapterInfo{config.Adapter{Endpoint: "http://test_bidder.com"}, "single"},
adapterInfo: adapterInfo{config.Adapter{Endpoint: "http://test_bidder.com"}, extraAdapterInfo{RequestMode: "single"}},
},
want: want{
requestData: []*adapters.RequestData{
Expand Down Expand Up @@ -293,33 +293,32 @@ func TestGetMediaTypeForBid(t *testing.T) {
}

func TestJsonSamplesForSingleRequestMode(t *testing.T) {
bidder, buildErr := Builder("ortb_test_single_requestmode",
bidder, buildErr := Builder("owgeneric_single_requestmode",
config.Adapter{
Endpoint: "http://test_bidder.com",
ExtraAdapterInfo: `{"requestMode":"single"}`,
}, config.Server{})
if buildErr != nil {
t.Fatalf("Builder returned unexpected error %v", buildErr)
}
adapterstest.RunJSONBidderTest(t, "ortb_test_single_requestmode", bidder)
adapterstest.RunJSONBidderTest(t, "ortbbiddertest/owortb_generic_single_requestmode", bidder)
}

func TestJsonSamplesForMultiRequestMode(t *testing.T) {
bidder, buildErr := Builder("ortb_test_multi_requestmode",
bidder, buildErr := Builder("owgeneric_multi_requestmode",
config.Adapter{
Endpoint: "http://test_bidder.com",
ExtraAdapterInfo: ``,
}, config.Server{})
if buildErr != nil {
t.Fatalf("Builder returned unexpected error %v", buildErr)
}
adapterstest.RunJSONBidderTest(t, "ortb_test_multi_requestmode", bidder)
adapterstest.RunJSONBidderTest(t, "ortbbiddertest/owortb_generic_multi_requestmode", bidder)
}

func Test_oRTBAdapterInfo_prepareRequestData(t *testing.T) {
type fields struct {
Adapter config.Adapter
requestMode string
Adapter config.Adapter
}
type args struct {
request *openrtb2.BidRequest
Expand Down Expand Up @@ -371,8 +370,7 @@ func Test_oRTBAdapterInfo_prepareRequestData(t *testing.T) {
for _, tt := range tests {
t.Run(tt.name, func(t *testing.T) {
o := adapterInfo{
Adapter: tt.fields.Adapter,
requestMode: tt.fields.requestMode,
Adapter: tt.fields.Adapter,
}
got, err := o.prepareRequestData(tt.args.request)
assert.Equal(t, tt.want.requestData, got, "mismatched requestData")
Expand Down Expand Up @@ -422,7 +420,9 @@ func TestBuilder(t *testing.T) {
want: want{
bidder: &adapter{
adapterInfo: adapterInfo{
requestMode: "single",
extraInfo: extraAdapterInfo{
RequestMode: "single",
},
Adapter: config.Adapter{
ExtraAdapterInfo: `{"requestMode":"single"}`,
},
Expand Down
1 change: 1 addition & 0 deletions go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -79,6 +79,7 @@ require (
github.com/subosito/gotenv v1.4.2 // indirect
github.com/xeipuuv/gojsonpointer v0.0.0-20180127040702-4e3ac2762d5f // indirect
github.com/xeipuuv/gojsonreference v0.0.0-20180127040603-bd5ef7bd5415 // indirect
github.com/yudai/pp v2.0.1+incompatible // indirect
golang.org/x/crypto v0.0.0-20220525230936-793ad666bf5e // indirect
golang.org/x/sys v0.14.0 // indirect
google.golang.org/genproto v0.0.0-20230110181048-76db0878b65f // indirect
Expand Down
1 change: 1 addition & 0 deletions go.sum
Original file line number Diff line number Diff line change
Expand Up @@ -504,6 +504,7 @@ github.com/yudai/gojsondiff v1.0.0/go.mod h1:AY32+k2cwILAkW1fbgxQ5mUmMiZFgLIV+FB
github.com/yudai/golcs v0.0.0-20170316035057-ecda9a501e82 h1:BHyfKlQyqbsFN5p3IfnEUduWvb9is428/nNb5L3U01M=
github.com/yudai/golcs v0.0.0-20170316035057-ecda9a501e82/go.mod h1:lgjkn3NuSvDfVJdfcVVdX+jpBxNmX4rDAzaS45IcYoM=
github.com/yudai/pp v2.0.1+incompatible h1:Q4//iY4pNF6yPLZIigmvcl7k/bPgrcTPIFIcmawg5bI=
github.com/yudai/pp v2.0.1+incompatible/go.mod h1:PuxR/8QJ7cyCkFp/aUDS+JY727OFEZkTdatxwunjIkc=
github.com/yuin/goldmark v1.1.25/go.mod h1:3hX8gzYuyVAZsxl0MRgGTJEmQBFcNTphYh9decYSb74=
github.com/yuin/goldmark v1.1.27/go.mod h1:3hX8gzYuyVAZsxl0MRgGTJEmQBFcNTphYh9decYSb74=
github.com/yuin/goldmark v1.1.32/go.mod h1:3hX8gzYuyVAZsxl0MRgGTJEmQBFcNTphYh9decYSb74=
Expand Down
6 changes: 3 additions & 3 deletions static/bidder-params/owortb_magnite.json
Original file line number Diff line number Diff line change
Expand Up @@ -4,10 +4,10 @@
"description": "A schema which validates params accepted by the magnite (oRTB Integration) adapter",
"type": "object",
"properties": {
"bidder-param": {
"adunitID": {
"type": "string",
"description": "Example of bidder-param"
"description": "adunitID param"
}
},
"required": ["bidder-param"]
"required": ["adunitID"]
}

0 comments on commit 0671490

Please sign in to comment.