Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Mobfox: Add rout to adexcange #1702

Merged
merged 36 commits into from
Feb 25, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
36 commits
Select commit Hold shift + click to select a range
c89ad6f
initial
Nov 12, 2020
6a18762
set bidder without syncer
Nov 12, 2020
69c5f02
Update mobfoxpb.json
mobfxoHB Nov 20, 2020
1a60c80
indent
Nov 20, 2020
d99cc13
Merge branch 'master' of github.com-mobfox:mobfxoHB/prebid-server
Nov 20, 2020
92dd67c
Update params_test.go
mobfxoHB Nov 23, 2020
8ddce98
fix json schema
Nov 23, 2020
a2f6239
Merge branch 'master' of github.com-mobfox:mobfxoHB/prebid-server
Nov 23, 2020
1c39b7c
remove unnecessary openrtb_ext
Nov 23, 2020
bce640e
fixes
Nov 23, 2020
6e50704
fixes
Nov 23, 2020
756a0b2
fixes
Nov 23, 2020
57f8d48
fixes
Nov 23, 2020
daee391
remove dublicates
Nov 25, 2020
8f4ed31
optimize MakeRequest
Nov 25, 2020
5808bfb
New Adapter Initialization Framework
Dec 1, 2020
f8797c2
merge upstream
Dec 1, 2020
a71a349
merge upstream
Dec 1, 2020
4983a92
add imp extension to resolve build error
Dec 2, 2020
347e392
fix
Dec 2, 2020
4bfb589
fix
Dec 2, 2020
1fa0f3f
fix
Dec 2, 2020
15f0d40
fix
Dec 3, 2020
fd9eb6b
fix
Dec 3, 2020
12944af
Merge branch 'master' into master
mobfxoHB Dec 4, 2020
184b16e
Update mobfoxpb.go
mobfxoHB Dec 9, 2020
aab7fb9
mediatype check
Dec 9, 2020
3a73dcb
Merge branch 'master' of github.com-mobfox:mobfxoHB/prebid-server
Dec 9, 2020
b4d0dd7
remove imp ext
Dec 11, 2020
de45983
Merge remote-tracking branch 'upstream/master'
Dec 15, 2020
258c6f1
Merge remote-tracking branch 'upstream/master'
Dec 22, 2020
2b2e039
mobilefuse conflict fix
Dec 23, 2020
491fd7d
Merge remote-tracking branch 'upstream/master'
Feb 16, 2021
5b4ac6a
initial
Feb 16, 2021
5fe651f
test make bid errors
Feb 23, 2021
b7f60ab
change error message, remove logging
Feb 23, 2021
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
53 changes: 39 additions & 14 deletions adapters/mobfoxpb/mobfoxpb.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ import (
"encoding/json"
"fmt"
"net/http"
"strings"

"github.com/buger/jsonparser"
"github.com/mxmCherry/openrtb"
Expand All @@ -13,6 +14,16 @@ import (
"github.com/prebid/prebid-server/openrtb_ext"
)

const (
ROUTE_NATIVE = "o"
ROUTE_RTB = "rtb"
METHOD_NATIVE = "ortb"
METHOD_RTB = "req"
MACROS_ROUTE = "__route__"
MACROS_METHOD = "__method__"
MACROS_KEY = "__key__"
)

type adapter struct {
URI string
}
Expand All @@ -28,21 +39,36 @@ func Builder(bidderName openrtb_ext.BidderName, config config.Adapter) (adapters
// MakeRequests create bid request for mobfoxpb demand
func (a *adapter) MakeRequests(request *openrtb.BidRequest, reqInfo *adapters.ExtraRequestInfo) ([]*adapters.RequestData, []error) {
var errs []error
var err error
var tagID string

var route string
var method string
var adapterRequests []*adapters.RequestData

requestURI := a.URI
reqCopy := *request
imp := request.Imp[0]
tagID, err = jsonparser.GetString(imp.Ext, "bidder", "TagID")
if err != nil {
errs = append(errs, err)
tagID, errTag := jsonparser.GetString(imp.Ext, "bidder", "TagID")
key, errKey := jsonparser.GetString(imp.Ext, "bidder", "key")
if errTag != nil && errKey != nil {
errs = append(errs, &errortypes.BadInput{
Message: fmt.Sprintf("Invalid or non existing key and tagId, atleast one should be present"),
})
return nil, errs
}
imp.TagID = tagID

if key != "" {
route = ROUTE_RTB
method = METHOD_RTB
requestURI = strings.Replace(requestURI, MACROS_KEY, key, 1)
} else if tagID != "" {
method = METHOD_NATIVE
route = ROUTE_NATIVE
}

requestURI = strings.Replace(requestURI, MACROS_ROUTE, route, 1)
requestURI = strings.Replace(requestURI, MACROS_METHOD, method, 1)

reqCopy.Imp = []openrtb.Imp{imp}
adapterReq, err := a.makeRequest(&reqCopy)
adapterReq, err := a.makeRequest(&reqCopy, requestURI)
if err != nil {
errs = append(errs, err)
}
Expand All @@ -52,7 +78,7 @@ func (a *adapter) MakeRequests(request *openrtb.BidRequest, reqInfo *adapters.Ex
return adapterRequests, errs
}

func (a *adapter) makeRequest(request *openrtb.BidRequest) (*adapters.RequestData, error) {
func (a *adapter) makeRequest(request *openrtb.BidRequest, requestURI string) (*adapters.RequestData, error) {
reqJSON, err := json.Marshal(request)

if err != nil {
Expand All @@ -64,7 +90,7 @@ func (a *adapter) makeRequest(request *openrtb.BidRequest) (*adapters.RequestDat
headers.Add("Accept", "application/json")
return &adapters.RequestData{
Method: "POST",
Uri: a.URI,
Uri: requestURI,
Body: reqJSON,
Headers: headers,
}, nil
Expand Down Expand Up @@ -98,11 +124,10 @@ func (a *adapter) MakeBids(internalRequest *openrtb.BidRequest, externalRequest
if err != nil {
errs = append(errs, err)
} else {
b := &adapters.TypedBid{
bidResponse.Bids = append(bidResponse.Bids, &adapters.TypedBid{
Bid: &bid,
BidType: bidType,
}
bidResponse.Bids = append(bidResponse.Bids, b)
})
}
}
}
Expand All @@ -126,6 +151,6 @@ func getMediaTypeForImp(impID string, imps []openrtb.Imp) (openrtb_ext.BidType,

// This shouldnt happen. Lets handle it just incase by returning an error.
return "", &errortypes.BadServerResponse{
Message: fmt.Sprintf("Failed to find impression \"%s\" ", impID),
Message: fmt.Sprintf("Failed to find impression \"%s\"", impID),
}
}
2 changes: 1 addition & 1 deletion adapters/mobfoxpb/mobfoxpb_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ import (

func TestJsonSamples(t *testing.T) {
bidder, buildErr := Builder(openrtb_ext.BidderMobfoxpb, config.Adapter{
Endpoint: "http://example.com/?c=o&m=ortb"})
Endpoint: "http://example.com/?c=__route__&m=__method__&key=__key__"})
if buildErr != nil {
t.Fatalf("Builder returned unexpected error %v", buildErr)
}
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,128 @@
{
"mockBidRequest": {
"id": "test-request-id",
"imp": [
{
"id": "test-imp-id",
"banner": {
"format": [
{
"w": 300,
"h": 250
},
{
"w": 300,
"h": 600
}
]
},
"ext": {
"bidder": {
"key": "6"
}
}
}
],
"app": {
"id": "1",
"bundle": "com.wls.testwlsapplication"
},
"device": {
"ip": "123.123.123.123",
"ifa": "zxcjbzxmc-zxcbmz-zxbcz-zxczx"
}
},
"httpCalls": [
{
"expectedRequest": {
"uri": "http://example.com/?c=rtb&m=req&key=6",
"body": {
"id": "test-request-id",
"imp": [
{
"id": "test-imp-id",
"banner": {
"format": [
{
"w": 300,
"h": 250
},
{
"w": 300,
"h": 600
}
]
},
"ext": {
"bidder": {
"key": "6"
}
}
}
],
"app": {
"id": "1",
"bundle": "com.wls.testwlsapplication"
},
"device": {
"ip": "123.123.123.123",
"ifa": "zxcjbzxmc-zxcbmz-zxbcz-zxczx"
}
}
},
"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=\"https://bes.mobfox.com/?c=o&m=adm&k=882b2510ed6d6c94fa69c99aa522a708\"></iframe>",
"cid": "test_cid",
"crid": "test_crid",
"dealid": "test_dealid",
"w": 300,
"h": 250,
"ext": {
"prebid": {
"type": "banner"
}
}
}
]
}
]
}
}
}
],
"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=\"https://bes.mobfox.com/?c=o&m=adm&k=882b2510ed6d6c94fa69c99aa522a708\"></iframe>",
"cid": "test_cid",
"crid": "test_crid",
"dealid": "test_dealid",
"w": 300,
"h": 250,
"ext": {
"prebid": {
"type": "banner"
}
}
},
"type": "banner"
}
]
}
]
}
128 changes: 128 additions & 0 deletions adapters/mobfoxpb/mobfoxpbtest/exemplary/simple-banner-rtb-route.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,128 @@
{
"mockBidRequest": {
"id": "test-request-id",
"imp": [
{
"id": "test-imp-id",
"banner": {
"format": [
{
"w": 300,
"h": 250
},
{
"w": 300,
"h": 600
}
]
},
"ext": {
"bidder": {
"TagID": "6"
}
}
}
],
"app": {
"id": "1",
"bundle": "com.wls.testwlsapplication"
},
"device": {
"ip": "123.123.123.123",
"ifa": "zxcjbzxmc-zxcbmz-zxbcz-zxczx"
}
},
"httpCalls": [
{
"expectedRequest": {
"uri": "http://example.com/?c=o&m=ortb&key=__key__",
"body": {
"id": "test-request-id",
"imp": [
{
"id": "test-imp-id",
"banner": {
"format": [
{
"w": 300,
"h": 250
},
{
"w": 300,
"h": 600
}
]
},
"ext": {
"bidder": {
"TagID": "6"
}
}
}
],
"app": {
"id": "1",
"bundle": "com.wls.testwlsapplication"
},
"device": {
"ip": "123.123.123.123",
"ifa": "zxcjbzxmc-zxcbmz-zxbcz-zxczx"
}
}
},
"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=\"https://bes.mobfox.com/?c=o&m=adm&k=882b2510ed6d6c94fa69c99aa522a708\"></iframe>",
"cid": "test_cid",
"crid": "test_crid",
"dealid": "test_dealid",
"w": 300,
"h": 250,
"ext": {
"prebid": {
"type": "banner"
}
}
}
]
}
]
}
}
}
],
"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=\"https://bes.mobfox.com/?c=o&m=adm&k=882b2510ed6d6c94fa69c99aa522a708\"></iframe>",
"cid": "test_cid",
"crid": "test_crid",
"dealid": "test_dealid",
"w": 300,
"h": 250,
"ext": {
"prebid": {
"type": "banner"
}
}
},
"type": "banner"
}
]
}
]
}
Loading