Skip to content

Commit

Permalink
Merge branch 'master' into PBS-938
Browse files Browse the repository at this point in the history
  • Loading branch information
bsardo committed Jun 11, 2021
2 parents 957ba17 + ccb56ef commit 7cb6119
Show file tree
Hide file tree
Showing 196 changed files with 8,190 additions and 2,504 deletions.
8 changes: 5 additions & 3 deletions .github/workflows/release.yml
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ name: Release
on:
push:
tags:
- '[0-9]+.[0-9]+.[0-9]+'
- 'v[0-9]+.[0-9]+.[0-9]+'

jobs:
release:
Expand All @@ -13,13 +13,15 @@ jobs:
steps:
- name: Get Version
id: get_version
run: echo ::set-output name=version::${GITHUB_REF/refs\/tags\//}
run: |
echo ::set-output name=tag::${GITHUB_REF/refs\/tags\/}
echo ::set-output name=version::${GITHUB_REF/refs\/tags\/v}
- name: Create & Publish Release
uses: release-drafter/release-drafter@v5.12.1
with:
name: ${{ steps.get_version.outputs.version }}
tag: ${{ steps.get_version.outputs.version }}
tag: ${{ steps.get_version.outputs.tag }}
version: ${{ steps.get_version.outputs.version }}
publish: true
env:
Expand Down
11 changes: 8 additions & 3 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -50,6 +50,11 @@ go build .
Load the landing page in your browser at `http://localhost:8000/`.
For the full API reference, see [the endpoint documentation](https://docs.prebid.org/prebid-server/endpoints/pbs-endpoint-overview.html)

## Go Modules

The packages within this repository are intended to be used as part of the Prebid Server compiled binary. If you
choose to import Prebid Server packages in other projects, please understand we make no promises on the stability
of exported types.

## Contributing

Expand All @@ -59,7 +64,7 @@ Report bugs, request features, and suggest improvements [on Github](https://gith

Or better yet, [open a pull request](https://github.com/prebid/prebid-server/compare) with the changes you'd like to see.

## IDE Setup for PBS-Go development
## IDE Recommendations

The quickest way to start developing PBS-Go in a reproducible environment isolated from your host OS
is by using this [VScode Remote Container Setup](devcontainer.md)
The quickest way to start developing Prebid Server in a reproducible environment isolated from your host OS
is by using Visual Studio Code with [Remote Container Setup](devcontainer.md).
1 change: 1 addition & 0 deletions adapters/adapterstest/test_json.go
Original file line number Diff line number Diff line change
Expand Up @@ -57,6 +57,7 @@ func RunJSONBidderTest(t *testing.T, rootDir string, bidder adapters.Bidder) {
runTests(t, fmt.Sprintf("%s/supplemental", rootDir), bidder, true, false, false)
runTests(t, fmt.Sprintf("%s/amp", rootDir), bidder, true, true, false)
runTests(t, fmt.Sprintf("%s/video", rootDir), bidder, false, false, true)
runTests(t, fmt.Sprintf("%s/videosupplemental", rootDir), bidder, true, false, true)
}

// runTests runs all the *.json files in a directory. If allowErrors is false, and one of the test files
Expand Down
166 changes: 166 additions & 0 deletions adapters/algorix/algorix.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,166 @@
package algorix

import (
"encoding/json"
"fmt"
"net/http"
"net/url"
"text/template"

"github.com/mxmCherry/openrtb/v15/openrtb2"
"github.com/prebid/prebid-server/adapters"
"github.com/prebid/prebid-server/config"
"github.com/prebid/prebid-server/errortypes"
"github.com/prebid/prebid-server/macros"
"github.com/prebid/prebid-server/openrtb_ext"
)

type adapter struct {
EndpointTemplate template.Template
}

// Builder builds a new instance of the AlgoriX adapter for the given bidder with the given config.
func Builder(bidderName openrtb_ext.BidderName, config config.Adapter) (adapters.Bidder, error) {
endpoint, err := template.New("endpointTemplate").Parse(config.Endpoint)
if err != nil {
return nil, fmt.Errorf("unable to parse endpoint url template: %v", err)
}
bidder := &adapter{
EndpointTemplate: *endpoint,
}
return bidder, nil
}

func (a *adapter) MakeRequests(request *openrtb2.BidRequest, requestInfo *adapters.ExtraRequestInfo) ([]*adapters.RequestData, []error) {
var adapterRequests []*adapters.RequestData
var errs []error

adapterRequest, err := a.makeRequest(request)
if err == nil {
adapterRequests = append(adapterRequests, adapterRequest)
} else {
errs = append(errs, err)
}
return adapterRequests, errs
}

func (a *adapter) makeRequest(request *openrtb2.BidRequest) (*adapters.RequestData, error) {
algorixExt, err := getImpAlgoriXExt(&request.Imp[0])

if err != nil {
return nil, &errortypes.BadInput{Message: "Invalid ExtImpAlgoriX value"}
}

endPoint, err := a.getEndPoint(algorixExt)
if err != nil {
return nil, err
}

preProcess(request)
reqBody, err := json.Marshal(request)
if err != nil {
return nil, err
}

headers := http.Header{}
headers.Add("Content-Type", "application/json;charset=utf-8")
headers.Add("Accept", "application/json")
headers.Add("x-openrtb-version", "2.5")

return &adapters.RequestData{
Method: "POST",
Uri: endPoint,
Body: reqBody,
Headers: headers,
}, nil
}

// get ImpAlgoriXExt From First Imp. Only check and get first Imp.Ext.Bidder to ExtImpAlgorix
func getImpAlgoriXExt(imp *openrtb2.Imp) (*openrtb_ext.ExtImpAlgorix, error) {
var extImpAlgoriX openrtb_ext.ExtImpAlgorix
var extBidder adapters.ExtImpBidder
err := json.Unmarshal(imp.Ext, &extBidder)
if err != nil {
return nil, err
}
err = json.Unmarshal(extBidder.Bidder, &extImpAlgoriX)
if err != nil {
return nil, err
}
return &extImpAlgoriX, nil
}

func (a *adapter) getEndPoint(ext *openrtb_ext.ExtImpAlgorix) (string, error) {
endPointParams := macros.EndpointTemplateParams{
SourceId: url.PathEscape(ext.Sid),
AccountID: url.PathEscape(ext.Token),
}
return macros.ResolveMacros(a.EndpointTemplate, endPointParams)
}

func preProcess(request *openrtb2.BidRequest) {
for i := range request.Imp {
if request.Imp[i].Banner != nil {
banner := *request.Imp[i].Banner
if (banner.W == nil || banner.H == nil || *banner.W == 0 || *banner.H == 0) && len(banner.Format) > 0 {
firstFormat := banner.Format[0]
banner.W = &firstFormat.W
banner.H = &firstFormat.H
request.Imp[i].Banner = &banner
}
}
}
}

func (a *adapter) MakeBids(internalRequest *openrtb2.BidRequest, externalRequest *adapters.RequestData, response *adapters.ResponseData) (*adapters.BidderResponse, []error) {
if response.StatusCode == http.StatusNoContent {
return nil, nil
}

if response.StatusCode == http.StatusBadRequest {
return nil, []error{&errortypes.BadInput{
Message: fmt.Sprintf("Unexpected status code: %d.", response.StatusCode),
}}
}

if response.StatusCode != http.StatusOK {
return nil, []error{&errortypes.BadServerResponse{
Message: fmt.Sprintf("Unexpected status code: %d.", response.StatusCode),
}}
}

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

bidResponse := adapters.NewBidderResponseWithBidsCapacity(1)

for _, seatBid := range bidResp.SeatBid {
for idx := range seatBid.Bid {
mediaType := getBidType(seatBid.Bid[idx].ImpID, internalRequest.Imp)
bidResponse.Bids = append(bidResponse.Bids, &adapters.TypedBid{
Bid: &seatBid.Bid[idx],
BidType: mediaType,
})
}
}
return bidResponse, nil
}

func getBidType(impId string, imps []openrtb2.Imp) openrtb_ext.BidType {
for _, imp := range imps {
if imp.ID == impId {
if imp.Banner != nil {
break
}
if imp.Native != nil {
return openrtb_ext.BidTypeNative
}
if imp.Video != nil {
return openrtb_ext.BidTypeVideo
}
}
}
return openrtb_ext.BidTypeBanner
}
27 changes: 27 additions & 0 deletions adapters/algorix/algorix_test.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
package algorix

import (
"github.com/stretchr/testify/assert"
"testing"

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

func TestJsonSamples(t *testing.T) {
bidder, buildErr := Builder(openrtb_ext.BidderAlgorix, config.Adapter{
Endpoint: "https://test.com?sid={{.SourceId}}&token={{.AccountID}}"})

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

adapterstest.RunJSONBidderTest(t, "algorixtest", bidder)
}

func TestEndpointTemplateMalformed(t *testing.T) {
_, buildErr := Builder(openrtb_ext.BidderAlgorix, config.Adapter{Endpoint: "{{Malformed}}"})

assert.Error(t, buildErr)
}
83 changes: 83 additions & 0 deletions adapters/algorix/algorixtest/exemplary/sample-banner.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,83 @@
{
"mockBidRequest": {
"id": "test-request-id",
"imp": [
{
"id": "test-imp-id",
"banner": {
"format": [{"w": 320, "h": 50}]
},
"ext": {
"bidder": {
"sid": "testSid",
"token": "testToken"
}
}
}
]
},

"httpCalls": [
{
"expectedRequest": {
"uri": "https://test.com?sid=testSid&token=testToken",
"body": {
"id": "test-request-id",
"imp": [
{
"id":"test-imp-id",
"banner": {
"format": [{"w": 320, "h": 50}],
"w": 320,
"h": 50
},
"ext": {
"bidder": {
"sid": "testSid",
"token": "testToken"
}
}
}
]
}
},
"mockResponse": {
"status": 200,
"body": {
"id": "test-request-id",
"seatbid": [
{
"seat": "ttx",
"bid": [{
"id": "8ee514f1-b2b8-4abb-89fd-084437d1e800",
"impid": "test-imp-id",
"price": 0.5,
"adm": "some-ads",
"crid": "crid_testid"
}]
}
],
"cur": "USD"
}
}
}
],

"expectedBidResponses": [
{
"currency": "USD",
"bids": [
{
"bid": {
"id": "8ee514f1-b2b8-4abb-89fd-084437d1e800",
"impid": "test-imp-id",
"price": 0.5,
"adm": "some-ads",
"crid": "crid_testid"
},
"type": "banner"
}
]
}
]
}
Loading

0 comments on commit 7cb6119

Please sign in to comment.