Skip to content

Commit

Permalink
Merge branch 'prebid:master' into monetixads-adapter
Browse files Browse the repository at this point in the history
  • Loading branch information
farukcam authored Feb 26, 2025
2 parents 80e791f + 17f40d1 commit 3e27013
Show file tree
Hide file tree
Showing 30 changed files with 1,153 additions and 14 deletions.
2 changes: 1 addition & 1 deletion .devcontainer/devcontainer.json
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
"dockerfile": "Dockerfile",
"args": {
// Update the VARIANT arg to pick a version of Go
"VARIANT": "1.23",
"VARIANT": "1.24",
// Options
"INSTALL_NODE": "false",
"NODE_VERSION": "lts/*"
Expand Down
2 changes: 1 addition & 1 deletion .github/workflows/adapter-code-coverage.yml
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ jobs:
- name: Install Go
uses: actions/setup-go@v5
with:
go-version: 1.23.4
go-version: 1.24.0

- name: Checkout Code
uses: actions/checkout@v4
Expand Down
2 changes: 1 addition & 1 deletion .github/workflows/validate-merge.yml
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ jobs:
- name: Install Go
uses: actions/setup-go@v5
with:
go-version: 1.23.4
go-version: 1.24.0

- name: Checkout Merged Branch
uses: actions/checkout@v4
Expand Down
2 changes: 1 addition & 1 deletion .github/workflows/validate.yml
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ jobs:
validate:
strategy:
matrix:
go-version: [1.22.x, 1.23.x]
go-version: [1.23.x, 1.24.x]
os: [ubuntu-20.04]
runs-on: ${{ matrix.os }}

Expand Down
4 changes: 2 additions & 2 deletions Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,8 @@ RUN apt-get update && \
apt-get -y upgrade && \
apt-get install -y wget
WORKDIR /tmp
RUN wget https://dl.google.com/go/go1.23.4.linux-amd64.tar.gz && \
tar -xf go1.23.4.linux-amd64.tar.gz && \
RUN wget https://dl.google.com/go/go1.24.0.linux-amd64.tar.gz && \
tar -xf go1.24.0.linux-amd64.tar.gz && \
mv go /usr/local
RUN mkdir -p /app/prebid-server/
WORKDIR /app/prebid-server/
Expand Down
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,7 @@ Ensure that you deploy the `/static` directory, as Prebid Server requires those

## Developing

Prebid Server requires [Go](https://go.dev) version 1.22 or newer. You can develop on any operating system that Go supports; however, please note that our helper scripts are written in bash.
Prebid Server requires [Go](https://go.dev) version 1.23 or newer. You can develop on any operating system that Go supports; however, please note that our helper scripts are written in bash.

1. Clone The Repository
``` bash
Expand Down
44 changes: 44 additions & 0 deletions adapters/seedtag/params_test.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,44 @@
package seedtag

import (
"encoding/json"
"testing"

"github.com/prebid/prebid-server/v3/openrtb_ext"
)

func TestValidParams(t *testing.T) {
validator, err := openrtb_ext.NewBidderParamsValidator("../../static/bidder-params")
if err != nil {
t.Fatalf("Failed to fetch the json schema. %v", err)
}

for _, p := range validParams {
if err := validator.Validate(openrtb_ext.BidderSeedtag, json.RawMessage(p)); err != nil {
t.Errorf("Schema rejected valid params: %s", p)
}
}
}

func TestInvalidParams(t *testing.T) {
validator, err := openrtb_ext.NewBidderParamsValidator("../../static/bidder-params")
if err != nil {
t.Fatalf("Failed to fetch the json schema. %v", err)
}

for _, p := range invalidParams {
if err := validator.Validate(openrtb_ext.BidderSeedtag, json.RawMessage(p)); err == nil {
t.Errorf("Schema allowed invalid params: %s", p)
}
}
}

var validParams = []string{
`{"adUnitId": "27604970"}`,
}

var invalidParams = []string{
`{"adUnitId": 123}`,
`{"adUnitId": ""}`,
`{}`,
}
120 changes: 120 additions & 0 deletions adapters/seedtag/seedtag.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,120 @@
package seedtag

import (
"errors"
"net/http"
"strings"

"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/openrtb_ext"
"github.com/prebid/prebid-server/v3/util/jsonutil"
)

type adapter struct {
endpoint string
}

// Builder builds a new instance of the Seedtag adapter for the given bidder with the given config.
func Builder(_ openrtb_ext.BidderName, config config.Adapter, server config.Server) (adapters.Bidder, error) {
bidder := &adapter{
endpoint: config.Endpoint,
}
return bidder, nil
}

// MakeRequests makes outgoing HTTP requests to Seedtag endpoint.
func (a *adapter) MakeRequests(request *openrtb2.BidRequest, reqInfo *adapters.ExtraRequestInfo) ([]*adapters.RequestData, []error) {

var errors []error
imps := make([]openrtb2.Imp, 0, len(request.Imp))

for _, imp := range request.Imp {
// Convert Floor into USD
if imp.BidFloor > 0 && imp.BidFloorCur != "" && strings.ToUpper(imp.BidFloorCur) != "USD" {
convertedValue, err := reqInfo.ConvertCurrency(imp.BidFloor, imp.BidFloorCur, "USD")
if err != nil {
errors = append(errors, err)
continue
}

imp.BidFloorCur = "USD"
imp.BidFloor = convertedValue
}

imps = append(imps, imp)
}

if len(imps) < 1 {
return nil, errors
}

requestCopy := *request
requestCopy.Imp = imps
requestJSON, err := jsonutil.Marshal(requestCopy)
if err != nil {
return nil, []error{err}
}

requestData := &adapters.RequestData{
Method: http.MethodPost,
Uri: a.endpoint,
Body: requestJSON,
ImpIDs: openrtb_ext.GetImpIDs(requestCopy.Imp),
}

return []*adapters.RequestData{requestData}, errors
}

// MakeBids unpacks the server's response into Bids.
func (a *adapter) MakeBids(request *openrtb2.BidRequest, requestData *adapters.RequestData, responseData *adapters.ResponseData) (*adapters.BidderResponse, []error) {
if adapters.IsResponseStatusCodeNoContent(responseData) {
return nil, nil
}

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

var response openrtb2.BidResponse
if err := jsonutil.Unmarshal(responseData.Body, &response); err != nil {
return nil, []error{err}
}

bidResponse := adapters.NewBidderResponseWithBidsCapacity(len(requestData.ImpIDs))

var errs []error

for _, seatBid := range response.SeatBid {
for i := range seatBid.Bid {
bid := &seatBid.Bid[i]

bidType, err := getMediaTypeForBid(*bid)
if err != nil {
errs = append(errs, err)
continue
}

bidResponse.Bids = append(bidResponse.Bids, &adapters.TypedBid{
Bid: bid,
BidType: bidType,
})
}
}

return bidResponse, errs
}

func getMediaTypeForBid(bid openrtb2.Bid) (openrtb_ext.BidType, error) {
switch bid.MType {
case 1:
return openrtb_ext.BidTypeBanner, nil
case 2:
return openrtb_ext.BidTypeVideo, nil
default:
return "", errors.New("bid.MType invalid")
}

}
20 changes: 20 additions & 0 deletions adapters/seedtag/seedtag_test.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
package seedtag

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.BidderSeedtag, config.Adapter{
Endpoint: "http://url.seedtag.com"}, config.Server{ExternalUrl: "http://hosturl.com", GvlID: 1, DataCenter: "2"})

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

adapterstest.RunJSONBidderTest(t, "seedtagtest", bidder)
}
129 changes: 129 additions & 0 deletions adapters/seedtag/seedtagtest/exemplary/banner.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,129 @@
{
"mockBidRequest": {
"id": "test-request-id",
"site": {
"publisher": {
"id": "foo",
"name": "foo"
}
},
"imp": [
{
"id": "test-imp-id",
"banner": {
"format": [
{
"w": 300,
"h": 250
},
{
"w": 300,
"h": 600
}
]
},
"ext": {
"bidder": {
"adUnitId": "example-tag-id"
}
}
}
]
},
"httpCalls": [
{
"expectedRequest": {
"uri": "http://url.seedtag.com",
"body": {
"id": "test-request-id",
"imp": [
{
"id": "test-imp-id",
"banner": {
"format": [
{
"w": 300,
"h": 250
},
{
"w": 300,
"h": 600
}
]
},
"ext": {
"bidder": {
"adUnitId": "example-tag-id"
}
}
}
],
"site": {
"publisher": {
"id": "foo",
"name": "foo"
}
}
},
"impIDs":["test-imp-id"]
},
"mockResponse": {
"status": 200,
"body": {
"id": "test-request-id",
"seatbid": [
{
"seat": "123",
"bid": [
{
"id": "7706636740145184841",
"impid": "test-imp-id",
"price": 0.5,
"adid": "12341234",
"adm": "some-test-ad",
"adomain": [
"domain.com"
],
"iurl": "http://abc.com/cr?id=12341234",
"cid": "123",
"crid": "12341234",
"h": 250,
"w": 300,
"mtype": 1
}
]
}
],
"bidid": "5778926625248726496",
"cur": "USD"
}
}
}
],
"expectedBidResponses": [
{
"currency": "USD",
"bids": [
{
"bid": {
"id": "7706636740145184841",
"impid": "test-imp-id",
"price": 0.5,
"adm": "some-test-ad",
"adid": "12341234",
"adomain": [
"domain.com"
],
"iurl": "http://abc.com/cr?id=12341234",
"cid": "123",
"crid": "12341234",
"w": 300,
"h": 250,
"mtype": 1
},
"type": "banner"
}
]
}
]
}
Loading

0 comments on commit 3e27013

Please sign in to comment.