Skip to content

Commit

Permalink
Pangle: add appid & placementid to bidder param (prebid#1842)
Browse files Browse the repository at this point in the history
Co-authored-by: hcai <caihengsheng@bytedance.com>
  • Loading branch information
2 people authored and sachin-pubmatic committed Aug 2, 2021
1 parent b4616ee commit b14dec2
Show file tree
Hide file tree
Showing 19 changed files with 282 additions and 19 deletions.
44 changes: 31 additions & 13 deletions adapters/pangle/pangle.go
Original file line number Diff line number Diff line change
Expand Up @@ -16,9 +16,16 @@ type adapter struct {
Endpoint string
}

type NetworkIDs struct {
AppID string `json:"appid,omitempty"`
PlacementID string `json:"placementid,omitempty"`
}

type wrappedExtImpBidder struct {
*adapters.ExtImpBidder
AdType int `json:"adtype,omitempty"`
AdType int `json:"adtype,omitempty"`
IsPrebid bool `json:"is_prebid,omitempty"`
NetworkIDs *NetworkIDs `json:"networkids,omitempty"`
}

type pangleBidExt struct {
Expand Down Expand Up @@ -78,23 +85,34 @@ func (a *adapter) MakeRequests(request *openrtb2.BidRequest, requestInfo *adapte
errs = append(errs, fmt.Errorf("failed unmarshalling imp ext (err)%s", err.Error()))
continue
}
// get token & networkIDs
var bidderImpExt openrtb_ext.ImpExtPangle
if err := json.Unmarshal(impExt.Bidder, &bidderImpExt); err != nil {
errs = append(errs, fmt.Errorf("failed unmarshalling bidder imp ext (err)%s", err.Error()))
continue
}
// detect and fill adtype
if adType := getAdType(imp, &impExt); adType == -1 {
adType := getAdType(imp, &impExt)
if adType == -1 {
errs = append(errs, &errortypes.BadInput{Message: "not a supported adtype"})
continue
} else {
impExt.AdType = adType
if newImpExt, err := json.Marshal(impExt); err == nil {
imp.Ext = newImpExt
} else {
errs = append(errs, fmt.Errorf("failed re-marshalling imp ext with adtype"))
continue
}
// remarshal imp.ext
impExt.AdType = adType
impExt.IsPrebid = true
if len(bidderImpExt.AppID) > 0 && len(bidderImpExt.PlacementID) > 0 {
impExt.NetworkIDs = &NetworkIDs{
AppID: bidderImpExt.AppID,
PlacementID: bidderImpExt.PlacementID,
}
} else if len(bidderImpExt.AppID) > 0 || len(bidderImpExt.PlacementID) > 0 {
errs = append(errs, &errortypes.BadInput{Message: "only one of appid or placementid is provided"})
continue
}
// for setting token
var bidderImpExt openrtb_ext.ImpExtPangle
if err := json.Unmarshal(impExt.Bidder, &bidderImpExt); err != nil {
errs = append(errs, fmt.Errorf("failed unmarshalling bidder imp ext (err)%s", err.Error()))
if newImpExt, err := json.Marshal(impExt); err == nil {
imp.Ext = newImpExt
} else {
errs = append(errs, fmt.Errorf("failed re-marshalling imp ext"))
continue
}

Expand Down
1 change: 1 addition & 0 deletions adapters/pangle/pangletest/exemplary/app_banner.json
Original file line number Diff line number Diff line change
Expand Up @@ -62,6 +62,7 @@
"bidder": {
"token": "123"
},
"is_prebid": true,
"prebid": null
}
}
Expand Down
1 change: 1 addition & 0 deletions adapters/pangle/pangletest/exemplary/app_banner_instl.json
Original file line number Diff line number Diff line change
Expand Up @@ -64,6 +64,7 @@
"bidder": {
"token": "123"
},
"is_prebid": true,
"prebid": null
}
}
Expand Down
1 change: 1 addition & 0 deletions adapters/pangle/pangletest/exemplary/app_native.json
Original file line number Diff line number Diff line change
Expand Up @@ -52,6 +52,7 @@
"bidder": {
"token": "123"
},
"is_prebid": true,
"prebid": null
}
}
Expand Down
1 change: 1 addition & 0 deletions adapters/pangle/pangletest/exemplary/app_video_instl.json
Original file line number Diff line number Diff line change
Expand Up @@ -76,6 +76,7 @@
"bidder": {
"token": "123"
},
"is_prebid": true,
"prebid": null
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -79,6 +79,7 @@
"is_rewarded_inventory": 1,
"storedrequest": null
},
"is_prebid": true,
"bidder": {
"token": "123"
}
Expand Down
4 changes: 3 additions & 1 deletion adapters/pangle/pangletest/params/race/banner.json
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
{
"token": "123"
"token": "123",
"appid": "123",
"placementid": "123"
}
4 changes: 3 additions & 1 deletion adapters/pangle/pangletest/params/race/native.json
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
{
"token": "123"
"token": "123",
"appid": "123",
"placementid": "123"
}
4 changes: 3 additions & 1 deletion adapters/pangle/pangletest/params/race/video.json
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
{
"token": "123"
"token": "123",
"appid": "123",
"placementid": "123"
}
155 changes: 155 additions & 0 deletions adapters/pangle/pangletest/supplemental/appid_placementid_check.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,155 @@
{
"mockBidRequest": {
"id": "test-request-id",
"app": {
"bundle": "com.prebid"
},
"device": {
"ifa": "87857b31-8942-4646-ae80-ab9c95bf3fab"
},
"imp": [
{
"id": "test-imp-id",
"video": {
"mimes": [
"video/mp4"
],
"protocols": [
2,
5
],
"w": 1024,
"h": 576,
"ext": {
"foo": "bar"
}
},
"ext": {
"prebid": {
"is_rewarded_inventory": 1
},
"bidder": {
"token": "123",
"appid": "123456",
"placementid": "78910"
}
}
}
]
},
"httpCalls": [
{
"expectedRequest": {
"uri": "https://pangle.io/api/get_ads",
"headers": {
"Content-Type": [
"application/json"
],
"TOKEN": [
"123"
]
},
"body": {
"id": "test-request-id",
"app": {
"bundle": "com.prebid"
},
"device": {
"ifa": "87857b31-8942-4646-ae80-ab9c95bf3fab"
},
"imp": [
{
"id": "test-imp-id",
"video": {
"mimes": [
"video/mp4"
],
"protocols": [
2,
5
],
"w": 1024,
"h": 576,
"ext": {
"foo": "bar"
}
},
"ext": {
"adtype": 7,
"prebid": {
"bidder": null,
"is_rewarded_inventory": 1,
"storedrequest": null
},
"is_prebid": true,
"networkids": {
"appid": "123456",
"placementid": "78910"
},
"bidder": {
"token": "123",
"appid": "123456",
"placementid": "78910"
}
}
}
]
}
},
"mockResponse": {
"status": 200,
"body": {
"id": "test-request-id",
"seatbid": [
{
"seat": "seat-id",
"bid": [
{
"id": "1",
"impid": "test-imp-id",
"adid": "11110126",
"price": 0.500000,
"adm": "some-test-ad",
"crid": "test-crid",
"h": 250,
"w": 300,
"ext": {
"pangle": {
"adtype": 7
}
}
}
]
}
],
"cur": "USD"
}
}
}
],
"expectedBidResponses": [
{
"currency": "USD",
"bids": [
{
"bid": {
"id": "1",
"impid": "test-imp-id",
"adid": "11110126",
"price": 0.5,
"adm": "some-test-ad",
"crid": "test-crid",
"w": 300,
"h": 250,
"ext": {
"pangle": {
"adtype": 7
}
}
},
"type": "video"
}
]
}
]
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,47 @@
{
"mockBidRequest": {
"id": "test-request-id",
"app": {
"bundle": "com.prebid"
},
"device": {
"ifa": "87857b31-8942-4646-ae80-ab9c95bf3fab"
},
"imp": [
{
"id": "test-imp-id",
"video": {
"mimes": [
"video/mp4"
],
"protocols": [
2,
5
],
"w": 1024,
"h": 576,
"ext": {
"foo": "bar"
}
},
"ext": {
"prebid": {
"is_rewarded_inventory": 1
},
"bidder": {
"token": "123",
"placementid": "78910"
}
}
}
]
},
"httpCalls": [],
"expectedBidResponses": [],
"expectedMakeRequestsErrors": [
{
"value": "only one of appid or placementid is provided",
"comparison": "literal"
}
]
}
Original file line number Diff line number Diff line change
Expand Up @@ -62,6 +62,7 @@
"bidder": {
"token": "123"
},
"is_prebid": true,
"prebid": null
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -62,6 +62,7 @@
"bidder": {
"token": "123"
},
"is_prebid": true,
"prebid": null
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -62,6 +62,7 @@
"bidder": {
"token": "123"
},
"is_prebid": true,
"prebid": null
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -62,6 +62,7 @@
"bidder": {
"token": "123"
},
"is_prebid": true,
"prebid": null
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -62,6 +62,7 @@
"bidder": {
"token": "123"
},
"is_prebid": true,
"prebid": null
}
}
Expand Down
7 changes: 7 additions & 0 deletions adapters/pangle/param_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -9,13 +9,20 @@ import (

var validParams = []string{
`{"token": "SomeAccessToken"}`,
`{"token": "SomeAccessToken", "appid": "12345", "placementid": "12345"}`,
}

var invalidParams = []string{
`{"token": ""}`,
`{"token": 42}`,
`{"token": null}`,
`{}`,
// appid & placementid
`{"appid": "12345", "placementid": "12345"}`,
`{"token": "SomeAccessToken", "appid": "12345"}`,
`{"token": "SomeAccessToken", "placementid": "12345"}`,
`{"token": "SomeAccessToken", "appid": 12345, "placementid": 12345}`,
`{"token": "SomeAccessToken", "appid": null, "placementid": null}`,
}

func TestValidParams(t *testing.T) {
Expand Down
Loading

0 comments on commit b14dec2

Please sign in to comment.