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

Sharethrough: Change to using a closure for the callback from ajax to preserve bidObj #1108

Merged
merged 9 commits into from
May 5, 2017

Conversation

rizhang
Copy link
Contributor

@rizhang rizhang commented Apr 6, 2017

Type of change

  • Bugfix
  • Feature
  • New bidder adapter
  • Code style update (formatting, local variables)
  • Refactoring (no functional changes, no api changes)
  • Build related changes
  • CI related changes
  • Other

Description of change

Passing the bid request object inside the callback function, instead of relying on fetching it with a bid Id. When multiple auctions are ran, old bid requests will be deleted, which causes the adapter to error out.

  • contact email of the adapter’s maintainer
    [email protected]
  • official adapter submission

Other information

@rizhang rizhang changed the title Change to using a closure for the callback from ajax to preserve bidObj Sharethrough: Change to using a closure for the callback from ajax to preserve bidObj Apr 6, 2017
bidResponse = JSON.parse(bidResponse);
const bidId = bidResponse.bidId;
const bidObj = utils.getBidRequest(bidId);
try {
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

this wasn't a change in this PR, but I'd suggest moving the try { above the JSON.parse() so any errors parsing the JSON are caught so the bids are added to the bidManager as errors.

@@ -117,8 +108,8 @@ describe('sharethrough adapter', () => {
"stxUserId": ""
};

pbjs.strcallback(JSON.stringify(bidderReponse1));
pbjs.strcallback(JSON.stringify(bidderReponse2));
adapter.callback(bidderRequest.bids[0], JSON.stringify(bidderReponse1));
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

rather than exposing the callback just for testing, it's preferred that you test using the sinon.fakeServer with a mock response and calling adapter.callBids(). You can see an example in here.

@@ -39,10 +45,9 @@ var SharethroughAdapter = function SharethroughAdapter() {
return url;
}

$$PREBID_GLOBAL$$.strcallback = function(bidResponse) {
function _strcallback(bidObj, bidResponse) {
bidResponse = JSON.parse(bidResponse);
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I see there was another change (causing a conflict) where you wrapped this in a separate try/catch. I'd still recommend wrapping it in the try block below so that the bid is added to the bidManager (in your _handleInvalidBid() function) so it can still be tracked.

@rizhang
Copy link
Contributor Author

rizhang commented Apr 26, 2017

Made the changes!

@@ -102,6 +101,7 @@ var SharethroughAdapter = function SharethroughAdapter() {
return {
callBids: _callBids,
str : str,
callback: _strcallback
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

no need to expose callback any longer

@harpere
Copy link
Collaborator

harpere commented Apr 27, 2017

thanks @rizhang! made one more minor comment.

@rizhang
Copy link
Contributor Author

rizhang commented May 3, 2017

Made the change!

@harpere harpere added LGTM and removed needs update labels May 3, 2017
Copy link
Collaborator

@harpere harpere left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

looks like the travis-ci tests failed, but the errors are unrelated to these changes, and the tests pass locally for me

@mkendall07 mkendall07 merged commit 38d6d3a into prebid:master May 5, 2017
outoftime pushed a commit to Genius/Prebid.js that referenced this pull request May 12, 2017
…built

* 'master' of https://github.com/prebid/Prebid.js:
  inclusion of popular Nordic ad sizes to default size list (prebid#1168)
  pre release version bump
  Prebid 0.23.1 Release
  Add trafficSourceCode + test (prebid#1184)
  Clear cookie sync to prevent multiple calls (prebid#1181)
  change s2s adapter to filter out units with empty sizes array (prebid#1179)
  Sharethrough: Change to using a closure for the callback from ajax to preserve bidObj (prebid#1108)
  check array length when mapping sizes (prebid#1180)
  Bugfix/encoding url (prebid#1178)
vzhukovsky added a commit to aol/Prebid.js that referenced this pull request May 25, 2017
…21.0 to aolgithub-master

* commit '4d573b42c5fbbabf23fed48fa042b75a72dd16b2': (31 commits)
  Added prebidServer in aolPartnersIds.json.
  Added adapters in aolPartnersIds.json.
  Added changelog entry.
  Prebid 0.23.1 Release
  Add trafficSourceCode + test (prebid#1184)
  Clear cookie sync to prevent multiple calls (prebid#1181)
  change s2s adapter to filter out units with empty sizes array (prebid#1179)
  Sharethrough: Change to using a closure for the callback from ajax to preserve bidObj (prebid#1108)
  check array length when mapping sizes (prebid#1180)
  Bugfix/encoding url (prebid#1178)
  add lodash as dependency (prebid#1174)
  fix size mapping for s2s (prebid#1175)
  Improve footer styling (prebid#1171)
  Bugfix: internal bids requested overwritten (prebid#1173)
  pre-release version bump
  Prebid 0.23.0 Release
  Yieldbot adapter - multiple requestBids per pageview (prebid#1146)
  Widespace adapter validate size fix (prebid#1140)
  Audience Network: bid when at least one valid slot size (prebid#1148)
  Quantcast adaptor (prebid#1063)
  ...
@jchau87 jchau87 deleted the callback_closure branch June 21, 2018 20:50
dluxemburg pushed a commit to Genius/Prebid.js that referenced this pull request Jul 17, 2018
… preserve bidObj (prebid#1108)

* Change to using a closure for the callback from ajax to preserve bidObj

* fix jslint errors

* update version

* fix specs

* put entire callback inside try catch

* tests uses fake server

* removed exposing callback
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

Successfully merging this pull request may close these issues.

7 participants