Skip to content

Commit

Permalink
IQzone Bidder Adapter: add new bid param (prebid#1987)
Browse files Browse the repository at this point in the history
add IQZone adapter
  • Loading branch information
IQZoneAdx authored and shunj-nb committed Nov 8, 2022
1 parent 249c293 commit 75fd968
Show file tree
Hide file tree
Showing 13 changed files with 229 additions and 31 deletions.
80 changes: 64 additions & 16 deletions adapters/iqzone/iqzone.go
Original file line number Diff line number Diff line change
Expand Up @@ -23,19 +23,71 @@ func Builder(bidderName openrtb_ext.BidderName, config config.Adapter) (adapters
return bidder, nil
}

func (a *adapter) MakeRequests(request *openrtb2.BidRequest, requestInfo *adapters.ExtraRequestInfo) ([]*adapters.RequestData, []error) {
requestJSON, err := json.Marshal(request)
if err != nil {
return nil, []error{err}
func (a *adapter) MakeRequests(request *openrtb2.BidRequest, reqInfo *adapters.ExtraRequestInfo) ([]*adapters.RequestData, []error) {
var errs []error
var err error
var adapterRequests []*adapters.RequestData

reqCopy := *request
for _, imp := range request.Imp {
reqCopy.Imp = []openrtb2.Imp{imp}

var bidderExt adapters.ExtImpBidder
var iqzoneExt openrtb_ext.ImpExtIQZone

if err = json.Unmarshal(reqCopy.Imp[0].Ext, &bidderExt); err != nil {
return nil, append(errs, err)
}
if err = json.Unmarshal(bidderExt.Bidder, &iqzoneExt); err != nil {
return nil, append(errs, err)
}

finalyImpExt := reqCopy.Imp[0].Ext
if iqzoneExt.PlacementID != "" {
finalyImpExt, _ = json.Marshal(map[string]interface{}{
"bidder": map[string]interface{}{
"placementId": iqzoneExt.PlacementID,
"type": "publisher",
},
})
} else if iqzoneExt.EndpointID != "" {
finalyImpExt, _ = json.Marshal(map[string]interface{}{
"bidder": map[string]interface{}{
"endpointId": iqzoneExt.EndpointID,
"type": "network",
},
})
}

reqCopy.Imp[0].Ext = finalyImpExt

adapterReq, errors := a.makeRequest(&reqCopy)
if adapterReq != nil {
adapterRequests = append(adapterRequests, adapterReq)
}
errs = append(errs, errors...)
}
return adapterRequests, errs
}

func (a *adapter) makeRequest(request *openrtb2.BidRequest) (*adapters.RequestData, []error) {
var errs []error

requestData := &adapters.RequestData{
Method: "POST",
Uri: a.endpoint,
Body: requestJSON,
reqJSON, err := json.Marshal(request)
if err != nil {
errs = append(errs, err)
return nil, errs
}

return []*adapters.RequestData{requestData}, nil
headers := http.Header{}
headers.Add("Content-Type", "application/json;charset=utf-8")
headers.Add("Accept", "application/json")
return &adapters.RequestData{
Method: "POST",
Uri: a.endpoint,
Body: reqJSON,
Headers: headers,
}, errs
}

func (a *adapter) MakeBids(request *openrtb2.BidRequest, requestData *adapters.RequestData, responseData *adapters.ResponseData) (*adapters.BidderResponse, []error) {
Expand Down Expand Up @@ -75,20 +127,16 @@ func (a *adapter) MakeBids(request *openrtb2.BidRequest, requestData *adapters.R
}

func getMediaTypeForImp(impID string, imps []openrtb2.Imp) (openrtb_ext.BidType, error) {
var mediaType openrtb_ext.BidType = ""
for _, imp := range imps {
if imp.ID == impID {
if imp.Banner != nil {
mediaType = openrtb_ext.BidTypeBanner
return mediaType, nil
return openrtb_ext.BidTypeBanner, nil
}
if imp.Banner == nil && imp.Video != nil {
mediaType = openrtb_ext.BidTypeVideo
return mediaType, nil
return openrtb_ext.BidTypeVideo, nil
}
if imp.Banner == nil && imp.Video == nil && imp.Native != nil {
mediaType = openrtb_ext.BidTypeNative
return mediaType, nil
return openrtb_ext.BidTypeNative, nil
}
}
}
Expand Down
133 changes: 133 additions & 0 deletions adapters/iqzone/iqzonetest/exemplary/endpointId.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,133 @@
{
"mockBidRequest": {
"id": "test-request-id",
"device": {
"ip": "123.123.123.123",
"ua": "iPad"
},
"app": {
"id": "1",
"bundle": "com.wls.testwlsapplication"
},
"imp": [
{
"id": "test-imp-id",
"tagid": "test",
"banner": {
"format": [
{
"w": 300,
"h": 250
},
{
"w": 300,
"h": 600
}
]
},
"ext": {
"bidder": {
"endpointId": "test"
}
}
}
]
},
"httpCalls": [
{
"expectedRequest": {
"uri": "http://smartssp-us-east.iqzone.com/pserver",
"body": {
"id": "test-request-id",
"imp": [
{
"id": "test-imp-id",
"tagid": "test",
"banner": {
"format": [
{
"w": 300,
"h": 250
},
{
"w": 300,
"h": 600
}
]
},
"ext": {
"bidder": {
"endpointId": "test",
"type": "network"
}
}
}
],
"app": {
"id": "1",
"bundle": "com.wls.testwlsapplication"
},
"device": {
"ip": "123.123.123.123",
"ua": "iPad"
}
}
},
"mockResponse": {
"status": 200,
"body": {
"id": "test-request-id",
"seatbid": [
{
"bid": [
{
"id": "test_bid_id",
"impid": "test-imp-id",
"price": 0.27543,
"adm": "<iframe id=\"adm-banner-16\" width=\"300\" height=\"250\" frameborder=\"0\" marginheight=\"0\" marginwidth=\"0\" style=\"{overflow:hidden}\" src=\"http://smartssp-us-east.iqzone.com/pserver&k=882b2510ed6d6c94fa69c99aa522a708\"></iframe>",
"cid": "test_cid",
"crid": "test_crid",
"dealid": "test_dealid",
"w": 300,
"h": 250,
"ext": {
"prebid": {
"type": "banner"
}
}
}
],
"seat": "iqzone"
}
],
"cur": "USD"
}
}
}
],
"expectedBidResponses": [
{
"bids": [
{
"bid": {
"id": "test_bid_id",
"impid": "test-imp-id",
"price": 0.27543,
"adm": "<iframe id=\"adm-banner-16\" width=\"300\" height=\"250\" frameborder=\"0\" marginheight=\"0\" marginwidth=\"0\" style=\"{overflow:hidden}\" src=\"http://smartssp-us-east.iqzone.com/pserver&k=882b2510ed6d6c94fa69c99aa522a708\"></iframe>",
"cid": "test_cid",
"crid": "test_crid",
"dealid": "test_dealid",
"w": 300,
"h": 250,
"ext": {
"prebid": {
"type": "banner"
}
}
},
"type": "banner"
}
]
}
]
}
3 changes: 2 additions & 1 deletion adapters/iqzone/iqzonetest/exemplary/simple-banner.json
Original file line number Diff line number Diff line change
Expand Up @@ -57,7 +57,8 @@
},
"ext": {
"bidder": {
"placementId": "test"
"placementId": "test",
"type": "publisher"
}
}
}
Expand Down
3 changes: 2 additions & 1 deletion adapters/iqzone/iqzonetest/exemplary/simple-native.json
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,8 @@
},
"ext": {
"bidder": {
"placementId": "test"
"placementId": "test",
"type": "publisher"
}
}
}
Expand Down
3 changes: 2 additions & 1 deletion adapters/iqzone/iqzonetest/exemplary/simple-video.json
Original file line number Diff line number Diff line change
Expand Up @@ -63,7 +63,8 @@
},
"ext": {
"bidder": {
"placementId": "test"
"placementId": "test",
"type": "publisher"
}
}
}
Expand Down
3 changes: 2 additions & 1 deletion adapters/iqzone/iqzonetest/exemplary/simple-web-banner.json
Original file line number Diff line number Diff line change
Expand Up @@ -57,7 +57,8 @@
},
"ext": {
"bidder": {
"placementId": "test"
"placementId": "test",
"type": "publisher"
}
}
}
Expand Down
3 changes: 2 additions & 1 deletion adapters/iqzone/iqzonetest/supplemental/bad_media_type.json
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,8 @@
"id": "test-imp-id",
"ext": {
"bidder": {
"placementId": "test"
"placementId": "test",
"type": "publisher"
}
}
}
Expand Down
3 changes: 2 additions & 1 deletion adapters/iqzone/iqzonetest/supplemental/bad_response.json
Original file line number Diff line number Diff line change
Expand Up @@ -54,7 +54,8 @@
},
"ext": {
"bidder": {
"placementId": "test"
"placementId": "test",
"type": "publisher"
}
}
}
Expand Down
3 changes: 2 additions & 1 deletion adapters/iqzone/iqzonetest/supplemental/status-204.json
Original file line number Diff line number Diff line change
Expand Up @@ -54,7 +54,8 @@
},
"ext": {
"bidder": {
"placementId": "test"
"placementId": "test",
"type": "publisher"
}
}
}
Expand Down
5 changes: 3 additions & 2 deletions adapters/iqzone/iqzonetest/supplemental/status-not-200.json
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@
},
"ext": {
"bidder": {
"TagID": "test"
"placementId": "test"
}
}
}
Expand Down Expand Up @@ -54,7 +54,8 @@
},
"ext": {
"bidder": {
"TagID": "test"
"placementId": "test",
"type": "publisher"
}
}
}
Expand Down
6 changes: 4 additions & 2 deletions adapters/iqzone/params_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -36,10 +36,12 @@ func TestInvalidParams(t *testing.T) {
var validParams = []string{
`{"placementId": "test"}`,
`{"placementId": "1"}`,
`{"endpointId": "test"}`,
`{"endpointId": "1"}`,
}

var invalidParams = []string{
`{"placementId": 42}`,
`{}`,
`{"someOtherParam": "value"}`,
`{"endpointId": 42}`,
`{"placementId": "1", "endpointId": "1"}`,
}
1 change: 1 addition & 0 deletions openrtb_ext/imp_iqzone.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,4 +2,5 @@ package openrtb_ext

type ImpExtIQZone struct {
PlacementID string `json:"placementId"`
EndpointID string `json:"endpointId"`
}
14 changes: 10 additions & 4 deletions static/bidder-params/iqzone.json
Original file line number Diff line number Diff line change
@@ -1,15 +1,21 @@
{
"$schema": "http://json-schema.org/draft-04/schema#",
"title": "IQZone Adapter Params",
"description": "A schema which validates params accepted by the IQZone adapter",
"title": "IQzone Adapter Params",
"description": "A schema which validates params accepted by the IQzone adapter",
"type": "object",

"properties": {
"placementId": {
"type": "string",
"description": "Placement ID"
},
"endpointId": {
"type": "string",
"description": "Endpoint ID"
}
},

"required": ["placementId"]
"oneOf": [
{ "required": ["placementId"] },
{ "required": ["endpointId"] }
]
}

0 comments on commit 75fd968

Please sign in to comment.