Skip to content

Commit

Permalink
Merge branch 'prebid:master' into master
Browse files Browse the repository at this point in the history
  • Loading branch information
bakicam authored Feb 13, 2025
2 parents d2cf161 + 2b23016 commit fc724c3
Show file tree
Hide file tree
Showing 28 changed files with 2,366 additions and 0 deletions.
3 changes: 3 additions & 0 deletions .github/workflows/code-path-changes.yml
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,9 @@ env:
GITHUB_PR_NUMBER: ${{ github.event.pull_request.number }}
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}

permissions:
contents: read

jobs:
notify:
runs-on: ubuntu-latest
Expand Down
116 changes: 116 additions & 0 deletions adapters/loopme/loopme.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,116 @@
package loopme

import (
"encoding/json"
"fmt"
"net/http"

"github.com/prebid/openrtb/v20/openrtb2"
"github.com/prebid/prebid-server/v3/adapters"
"github.com/prebid/prebid-server/v3/config"
"github.com/prebid/prebid-server/v3/errortypes"
"github.com/prebid/prebid-server/v3/openrtb_ext"
)

type adapter struct {
endpoint string
}

func (a *adapter) MakeRequests(request *openrtb2.BidRequest, reqInfo *adapters.ExtraRequestInfo) ([]*adapters.RequestData, []error) {
errs := make([]error, 0, len(request.Imp))

reqDatas := make([]*adapters.RequestData, 0, len(request.Imp))

for _, imp := range request.Imp {
requestCopy := *request
requestCopy.Imp = []openrtb2.Imp{imp}
reqJSON, err := json.Marshal(requestCopy)
if err != nil {
errs = append(errs, err)
continue
}

headers := http.Header{}
headers.Add("Content-Type", "application/json;charset=utf-8")
headers.Add("Accept", "application/json")
reqDatas = append(reqDatas, &adapters.RequestData{
Method: http.MethodPost,
Uri: a.endpoint,
Body: reqJSON,
Headers: headers,
ImpIDs: openrtb_ext.GetImpIDs(requestCopy.Imp),
})

}
return reqDatas, errs
}

func (a *adapter) MakeBids(bidReq *openrtb2.BidRequest, reqData *adapters.RequestData, respData *adapters.ResponseData) (*adapters.BidderResponse, []error) {
if adapters.IsResponseStatusCodeNoContent(respData) {
return nil, nil
}

if err := adapters.CheckResponseStatusCodeForErrors(respData); err != nil {
return nil, []error{err}
}

var bidResp openrtb2.BidResponse
if err := json.Unmarshal(respData.Body, &bidResp); err != nil {
return nil, []error{err}
}

if len(bidResp.SeatBid) == 0 || len(bidResp.SeatBid[0].Bid) == 0 {
return nil, nil
}

errs := make([]error, 0, len(bidResp.SeatBid[0].Bid))
resp := adapters.NewBidderResponseWithBidsCapacity(len(bidResp.SeatBid[0].Bid))

for _, sb := range bidResp.SeatBid {
for i := range sb.Bid {
bid := &sb.Bid[i]
bidType, err := getBidType(bid)
if err != nil {
errs = append(errs, err)
continue
}
resp.Bids = append(resp.Bids, &adapters.TypedBid{
Bid: bid,
BidType: bidType,
})
}
}

if len(resp.Bids) == 0 {
return nil, errs
}
if len(bidResp.Cur) != 0 {
resp.Currency = bidResp.Cur
}
return resp, errs
}

func getBidType(bid *openrtb2.Bid) (openrtb_ext.BidType, error) {
switch bid.MType {
case openrtb2.MarkupBanner:
return openrtb_ext.BidTypeBanner, nil
case openrtb2.MarkupVideo:
return openrtb_ext.BidTypeVideo, nil
case openrtb2.MarkupNative:
return openrtb_ext.BidTypeNative, nil
case openrtb2.MarkupAudio:
return openrtb_ext.BidTypeAudio, nil
default:
return "", &errortypes.BadServerResponse{
Message: fmt.Sprintf("Unsupported MType %d", bid.MType),
}
}
}

// Builder builds a new instance of the Loopme adapter for the given bidder with the given config.
func Builder(bidderName openrtb_ext.BidderName, cfg config.Adapter, serverCfg config.Server) (adapters.Bidder, error) {
bidder := &adapter{
endpoint: cfg.Endpoint,
}
return bidder, nil
}
29 changes: 29 additions & 0 deletions adapters/loopme/loopme_test.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
package loopme

import (
"testing"

"github.com/prebid/prebid-server/v3/adapters/adapterstest"
"github.com/prebid/prebid-server/v3/config"
"github.com/prebid/prebid-server/v3/openrtb_ext"
)

func TestJsonSamples(t *testing.T) {
bidder, buildErr := Builder(
openrtb_ext.BidderLoopme,
config.Adapter{
Endpoint: "http://loopme.example.com",
},
config.Server{
ExternalUrl: "http://hosturl.com",
GvlID: 109,
DataCenter: "2",
},
)

if buildErr != nil {
t.Fatalf("Builder returned unexpected error %v", buildErr)
}

adapterstest.RunJSONBidderTest(t, "loopmetest", bidder)
}
152 changes: 152 additions & 0 deletions adapters/loopme/loopmetest/exemplary/app-formats.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,152 @@
{
"mockBidRequest": {
"id": "test-request-id",
"app": {
"bundle": "com.prebid"
},
"device": {
"ifa": "ec943cb9-61ec-460f-a925-6489c3fcc4e3"
},
"imp": [
{
"id": "test-imp-id",
"banner": {
"format": [
{
"w": 728,
"h": 90
}
]
},
"video": {
"mimes": [
"video/mp4"
],
"protocols": [
2,
3,
5,
6
],
"w": 1024,
"h": 576
},
"native": {
"request": "{json string 1}",
"ver": "1.2"
},
"ext": {
"bidder": {
"publisherId": "10000000"
}
}
}
]
},
"httpCalls": [
{
"expectedRequest": {
"uri": "http://loopme.example.com",
"body": {
"id": "test-request-id",
"app": {
"bundle": "com.prebid"
},
"device": {
"ifa": "ec943cb9-61ec-460f-a925-6489c3fcc4e3"
},
"imp": [
{
"id": "test-imp-id",
"banner": {
"format": [
{
"w": 728,
"h": 90
}
]
},
"video": {
"mimes": [
"video/mp4"
],
"protocols": [
2,
3,
5,
6
],
"w": 1024,
"h": 576
},
"native": {
"request": "{json string 1}",
"ver": "1.2"
},
"ext": {
"bidder": {
"publisherId": "10000000"
}
}
}
]
},
"impIDs": [
"test-imp-id"
]
},
"mockResponse": {
"status": 200,
"headers": {
"Accept": [
"application/json"
],
"Content-Type": [
"application/json;charset=utf-8"
]
},
"body": {
"id": "test-request-id",
"seatbid": [
{
"seat": "loopme",
"bid": [
{
"id": "8ee514f1-b2b8-4abb-89fd-084437d1e800",
"impid": "test-imp-id",
"price": 0.500000,
"adm": "some-test-ad",
"crid": "test-crid",
"w": 728,
"h": 90,
"mtype": 1
}
]
}
],
"cur": "USD"
}
}
}
],
"expectedBidResponses": [
{
"currency": "USD",
"bids": [
{
"bid": {
"id": "8ee514f1-b2b8-4abb-89fd-084437d1e800",
"impid": "test-imp-id",
"price": 0.5,
"adm": "some-test-ad",
"crid": "test-crid",
"w": 728,
"h": 90,
"mtype": 1
},
"type": "banner"
}
]
}
]
}
Loading

0 comments on commit fc724c3

Please sign in to comment.