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.
PubMatic + OpenWrap: Support request level Bidder Params prebid#1042 (p…
- Loading branch information
1 parent
015ad58
commit d060895
Showing
18 changed files
with
1,415 additions
and
27 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,61 @@ | ||
package adapters | ||
|
||
import ( | ||
"encoding/json" | ||
"errors" | ||
"fmt" | ||
"github.com/mxmCherry/openrtb/v15/openrtb2" | ||
"github.com/prebid/prebid-server/openrtb_ext" | ||
) | ||
|
||
func ExtractAdapterReqBidderParams(bidRequest *openrtb2.BidRequest) (map[string]json.RawMessage, error) { | ||
if bidRequest == nil { | ||
return nil, errors.New("error bidRequest should not be nil") | ||
} | ||
|
||
reqExt := &openrtb_ext.ExtRequest{} | ||
if len(bidRequest.Ext) > 0 { | ||
err := json.Unmarshal(bidRequest.Ext, &reqExt) | ||
if err != nil { | ||
return nil, fmt.Errorf("error decoding Request.ext : %s", err.Error()) | ||
} | ||
} | ||
|
||
if reqExt.Prebid.BidderParams == nil { | ||
return nil, nil | ||
} | ||
|
||
var bidderParams map[string]json.RawMessage | ||
err := json.Unmarshal(reqExt.Prebid.BidderParams, &bidderParams) | ||
if err != nil { | ||
return nil, err | ||
} | ||
|
||
return bidderParams, nil | ||
} | ||
|
||
func ExtractReqExtBidderParams(bidReq *openrtb2.BidRequest) (map[string]map[string]json.RawMessage, error) { | ||
if bidReq == nil { | ||
return nil, errors.New("error bidRequest should not be nil") | ||
} | ||
|
||
reqExt := &openrtb_ext.ExtRequest{} | ||
if len(bidReq.Ext) > 0 { | ||
err := json.Unmarshal(bidReq.Ext, &reqExt) | ||
if err != nil { | ||
return nil, fmt.Errorf("error decoding Request.ext : %s", err.Error()) | ||
} | ||
} | ||
|
||
if reqExt.Prebid.BidderParams == nil { | ||
return nil, nil | ||
} | ||
|
||
var bidderParams map[string]map[string]json.RawMessage | ||
err := json.Unmarshal(reqExt.Prebid.BidderParams, &bidderParams) | ||
if err != nil { | ||
return nil, err | ||
} | ||
|
||
return bidderParams, nil | ||
} |
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,117 @@ | ||
package adapters | ||
|
||
import ( | ||
"encoding/json" | ||
"github.com/mxmCherry/openrtb/v15/openrtb2" | ||
"reflect" | ||
"testing" | ||
) | ||
|
||
func TestExtractAdapterReqBidderParams(t *testing.T) { | ||
type args struct { | ||
bidRequest *openrtb2.BidRequest | ||
} | ||
tests := []struct { | ||
name string | ||
args args | ||
want map[string]json.RawMessage | ||
wantErr bool | ||
}{ | ||
{ | ||
name: "extract bidder params from nil req", | ||
args: args{ | ||
bidRequest: nil, | ||
}, | ||
want: nil, | ||
wantErr: true, | ||
}, | ||
{ | ||
name: "extract bidder params from nil req.Ext", | ||
args: args{ | ||
bidRequest: &openrtb2.BidRequest{Ext: json.RawMessage(`{"prebid":{}}`)}, | ||
}, | ||
want: nil, | ||
wantErr: false, | ||
}, | ||
{ | ||
name: "extract bidder params from req.Ext for input request in adapter code", | ||
args: args{ | ||
bidRequest: &openrtb2.BidRequest{Ext: json.RawMessage(`{"prebid":{"bidderparams": {"profile": 1234, "version": 1}}}`)}, | ||
}, | ||
want: map[string]json.RawMessage{"profile": json.RawMessage(`1234`), "version": json.RawMessage(`1`)}, | ||
wantErr: false, | ||
}, | ||
} | ||
for _, tt := range tests { | ||
t.Run(tt.name, func(t *testing.T) { | ||
got, err := ExtractAdapterReqBidderParams(tt.args.bidRequest) | ||
if (err != nil) != tt.wantErr { | ||
t.Errorf("ExtractReqExtBidderParams() error = %v, wantErr = %v", err, tt.wantErr) | ||
return | ||
} | ||
if !reflect.DeepEqual(got, tt.want) { | ||
t.Errorf("ExtractReqExtBidderParams() got = %v, want = %v", got, tt.want) | ||
} | ||
}) | ||
} | ||
} | ||
|
||
func TestExtractReqExtBidderParams(t *testing.T) { | ||
type args struct { | ||
request *openrtb2.BidRequest | ||
} | ||
tests := []struct { | ||
name string | ||
args args | ||
want map[string]map[string]json.RawMessage | ||
wantErr bool | ||
}{ | ||
{ | ||
name: "extract bidder params from nil req", | ||
args: args{ | ||
request: nil, | ||
}, | ||
want: nil, | ||
wantErr: true, | ||
}, | ||
{ | ||
name: "extract bidder params from nil req.Ext.prebid", | ||
args: args{ | ||
request: &openrtb2.BidRequest{Ext: json.RawMessage(`{"prebid":{}}`)}, | ||
}, | ||
want: nil, | ||
wantErr: false, | ||
}, | ||
{ | ||
name: "extract bidder params from nil req.Ext", | ||
args: args{ | ||
request: &openrtb2.BidRequest{Ext: nil}, | ||
}, | ||
want: nil, | ||
wantErr: false, | ||
}, | ||
{ | ||
name: "extract bidder params from req.Ext for input request before adapter code", | ||
args: args{ | ||
request: &openrtb2.BidRequest{Ext: json.RawMessage(`{"prebid":{"bidderparams": {"pubmatic": {"profile": 1234, "version": 1}, "appnexus": {"key1": 123, "key2": {"innerKey1":"innerValue1"} } }}}`)}, | ||
}, | ||
want: map[string]map[string]json.RawMessage{ | ||
"pubmatic": {"profile": json.RawMessage(`1234`), "version": json.RawMessage(`1`)}, | ||
"appnexus": {"key1": json.RawMessage(`123`), "key2": json.RawMessage(`{"innerKey1":"innerValue1"}`)}, | ||
}, | ||
wantErr: false, | ||
}, | ||
} | ||
for _, tt := range tests { | ||
t.Run(tt.name, func(t *testing.T) { | ||
got, err := ExtractReqExtBidderParams(tt.args.request) | ||
if (err != nil) != tt.wantErr { | ||
t.Errorf("ExtractReqExtBidderParams() error = %v, wantErr = %v", err, tt.wantErr) | ||
return | ||
} | ||
if !reflect.DeepEqual(got, tt.want) { | ||
t.Errorf("ExtractReqExtBidderParams() got = %v, want = %v", got, tt.want) | ||
} | ||
}) | ||
} | ||
} |
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
Oops, something went wrong.