This repository has been archived by the owner on Dec 22, 2022. It is now read-only.
forked from prebid/prebid-server
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Formalizing support for
site.ext.amp
(prebid#711)
* Started adding some code to validate the amp ext, and some unit tests which dont pass yet. * Fixed some bugs. Added more tests. * Updated the docs. * Fixed some tests... but not all. * Fixed last remaining bug. * Moved setAmpExt to the amp_auction file.
- Loading branch information
Showing
9 changed files
with
263 additions
and
11 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
47 changes: 47 additions & 0 deletions
47
endpoints/openrtb2/sample-requests/invalid-whole/site-ext-amp.json
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,47 @@ | ||
{ | ||
"message": "Invalid request: request.site.ext.amp must be either 1, 0, or undefined\n", | ||
"requestPayload": { | ||
"id": "some-request-id", | ||
"site": { | ||
"page": "test.somepage.com", | ||
"ext": { | ||
"amp": 2 | ||
} | ||
}, | ||
"imp": [ | ||
{ | ||
"id": "my-imp-id", | ||
"banner": { | ||
"format": [ | ||
{ | ||
"w": 300, | ||
"h": 600 | ||
} | ||
] | ||
}, | ||
"pmp": { | ||
"deals": [ | ||
{ | ||
"id": "some-deal-id" | ||
} | ||
] | ||
}, | ||
"ext": { | ||
"appnexus": { | ||
"placementId": 10433394 | ||
} | ||
} | ||
} | ||
], | ||
"ext": { | ||
"prebid": { | ||
"targeting": { | ||
"pricegranularity": "low" | ||
}, | ||
"cache": { | ||
"bids": {} | ||
} | ||
} | ||
} | ||
} | ||
} |
44 changes: 44 additions & 0 deletions
44
endpoints/openrtb2/sample-requests/valid-whole/supplementary/site-amp.json
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,44 @@ | ||
{ | ||
"id": "some-request-id", | ||
"site": { | ||
"page": "test.somepage.com", | ||
"ext": { | ||
"amp": 1 | ||
} | ||
}, | ||
"imp": [ | ||
{ | ||
"id": "my-imp-id", | ||
"banner": { | ||
"format": [ | ||
{ | ||
"w": 300, | ||
"h": 600 | ||
} | ||
] | ||
}, | ||
"pmp": { | ||
"deals": [ | ||
{ | ||
"id": "some-deal-id" | ||
} | ||
] | ||
}, | ||
"ext": { | ||
"appnexus": { | ||
"placementId": 10433394 | ||
} | ||
} | ||
} | ||
], | ||
"ext": { | ||
"prebid": { | ||
"targeting": { | ||
"pricegranularity": "low" | ||
}, | ||
"cache": { | ||
"bids": {} | ||
} | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,34 @@ | ||
package openrtb_ext | ||
|
||
import ( | ||
"errors" | ||
|
||
"github.com/buger/jsonparser" | ||
) | ||
|
||
// ExtSite defines the contract for bidrequest.site.ext | ||
type ExtSite struct { | ||
// AMP should be 1 if the request comes from an AMP page, and 0 if not. | ||
AMP int8 `json:"amp"` | ||
} | ||
|
||
func (es *ExtSite) UnmarshalJSON(b []byte) error { | ||
if len(b) == 0 { | ||
return errors.New("request.site.ext must have some data in it") | ||
} | ||
if value, dataType, _, _ := jsonparser.Get(b, "amp"); dataType != jsonparser.NotExist && dataType != jsonparser.Number { | ||
return errors.New(`request.site.ext.amp must be either 1, 0, or undefined`) | ||
} else if len(value) != 1 { | ||
return errors.New(`request.site.ext.amp must be either 1, 0, or undefined`) | ||
} else { | ||
switch value[0] { | ||
case byte(48): // 0 | ||
es.AMP = 0 | ||
case byte(49): // 1 | ||
es.AMP = 1 | ||
default: | ||
return errors.New(`request.site.ext.amp must be either 1, 0, or undefined`) | ||
} | ||
} | ||
return nil | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,28 @@ | ||
package openrtb_ext_test | ||
|
||
import ( | ||
"encoding/json" | ||
"testing" | ||
|
||
"github.com/prebid/prebid-server/openrtb_ext" | ||
"github.com/stretchr/testify/assert" | ||
) | ||
|
||
func TestInvalidSiteExt(t *testing.T) { | ||
var s openrtb_ext.ExtSite | ||
assert.EqualError(t, json.Unmarshal([]byte(`{"amp":-1}`), &s), "request.site.ext.amp must be either 1, 0, or undefined") | ||
assert.EqualError(t, json.Unmarshal([]byte(`{"amp":2}`), &s), "request.site.ext.amp must be either 1, 0, or undefined") | ||
assert.EqualError(t, json.Unmarshal([]byte(`{"amp":true}`), &s), "request.site.ext.amp must be either 1, 0, or undefined") | ||
assert.EqualError(t, json.Unmarshal([]byte(`{"amp":null}`), &s), "request.site.ext.amp must be either 1, 0, or undefined") | ||
assert.EqualError(t, json.Unmarshal([]byte(`{"amp":"1"}`), &s), "request.site.ext.amp must be either 1, 0, or undefined") | ||
} | ||
|
||
func TestValidSiteExt(t *testing.T) { | ||
var s openrtb_ext.ExtSite | ||
assert.NoError(t, json.Unmarshal([]byte(`{"amp":0}`), &s)) | ||
assert.EqualValues(t, 0, s.AMP) | ||
assert.NoError(t, json.Unmarshal([]byte(`{"amp":1}`), &s)) | ||
assert.EqualValues(t, 1, s.AMP) | ||
assert.NoError(t, json.Unmarshal([]byte(`{"amp": 1 }`), &s)) | ||
assert.EqualValues(t, 1, s.AMP) | ||
} |