Skip to content

Commit

Permalink
Unnecessary nested if statements are removed, and request.Source.ext …
Browse files Browse the repository at this point in the history
…is passed as a parameter.
  • Loading branch information
maximilianozurita committed Feb 20, 2025
1 parent 1af0c02 commit a10a4c3
Showing 1 changed file with 14 additions and 7 deletions.
21 changes: 14 additions & 7 deletions adapters/eplanning/eplanning.go
Original file line number Diff line number Diff line change
Expand Up @@ -196,12 +196,9 @@ func (adapter *EPlanningAdapter) MakeRequests(request *openrtb2.BidRequest, reqI
query.Set("vv", vastVersionDefault)
}
if request.Source != nil && request.Source.Ext != nil {
if openRtbSchain := unmarshalSupplyChain(request); openRtbSchain != nil && len(openRtbSchain.Nodes) <= 2 {
if schainValue := makeSupplyChain(*openRtbSchain); schainValue != "" {
query.Set("sch", schainValue)
}
}
setSchain(request.Source.Ext, &query)
}

uriObj.RawQuery = query.Encode()
uri := uriObj.String()

Expand All @@ -218,9 +215,19 @@ func (adapter *EPlanningAdapter) MakeRequests(request *openrtb2.BidRequest, reqI
return requests, errors
}

func unmarshalSupplyChain(req *openrtb2.BidRequest) *openrtb2.SupplyChain {
func setSchain(ext json.RawMessage, query *url.Values) {
openRtbSchain := unmarshalSupplyChain(ext)
if openRtbSchain == nil || len(openRtbSchain.Nodes) > 2 {
return
}
if schainValue := makeSupplyChain(*openRtbSchain); schainValue != "" {
query.Set("sch", schainValue)
}
}

func unmarshalSupplyChain(ext json.RawMessage) *openrtb2.SupplyChain {
var extSChain openrtb_ext.ExtRequestPrebidSChain
err := jsonutil.Unmarshal(req.Source.Ext, &extSChain)
err := jsonutil.Unmarshal(ext, &extSChain)
if err != nil {
return nil
}
Expand Down

0 comments on commit a10a4c3

Please sign in to comment.