Skip to content

Instantly share code, notes, and snippets.

@Gocrazy
Last active January 2, 2016 09:38
Show Gist options
  • Select an option

  • Save Gocrazy/8284064 to your computer and use it in GitHub Desktop.

Select an option

Save Gocrazy/8284064 to your computer and use it in GitHub Desktop.
#include "smaato_exchange_connector.h"
#include "rtbkit/plugins/bid_request/openrtb_bid_request.h"
#include "rtbkit/plugins/exchange/http_auction_handler.h"
#include "rtbkit/core/agent_configuration/agent_config.h"
#include "openrtb/openrtb_parsing.h"
#include "soa/types/json_printing.h"
#include <boost/any.hpp>
#include <boost/lexical_cast.hpp>
#include "jml/utils/file_functions.h"
using namespace std;
using namespace Datacratic;
namespace RTBKIT {
SmaatoExchangeConnector::SmaatoExchangeConnector(ServiceBase & owner, const std::string & name) : HttpExchangeConnector(name, owner) {
this->auctionResource = "/auctions";
this->auctionVerb = "POST";
}
SmaatoExchangeConnector::SmaatoExchangeConnector(const std::string & name, std::shared_ptr<ServiceProxies> proxies):HttpExchangeConnector(name, proxies) {
this->auctionResource = "/auctions";
this->auctionVerb = "POST";
}
ExchangeConnector::ExchangeCompatibility
SmaatoExchangeConnector::
getCampaignCompatibility(const AgentConfig & config,
bool includeReasons) const {
ExchangeCompatibility result;
result.setCompatible();
return result;
}
ExchangeConnector::ExchangeCompatibility
SmaatoExchangeConnector::
getCreativeCompatibility(const Creative & creative, bool includeReasons) const {
ExchangeCompatibility result;
result.setCompatible();
return result;
}
/*double SmaatoExchangeConnector::getTimeAvailableMs(HttpAuctionHandler & connection,
const HttpHeader & header,
const std::string & payload) {
static const string toFind = "\"tmax\":";
string::size_type pos = payload.find(toFind);
if (pos == string::npos) {
cerr << "tmax not found in request, using default value" << endl;
return 100.0;
}
int tmax = atoi(payload.c_str() + pos + toFind.length());
return tmax;
}*/
std::shared_ptr<BidRequest> SmaatoExchangeConnector::parseBidRequest(HttpAuctionHandler & connection,
const HttpHeader & header,
const std::string & payload) {
std::shared_ptr<BidRequest> res;
// Check json content-type
// Check x-openrtb-version header
cerr << "smaato exchange got request" << endl << header << endl << payload << endl;
// Parse bid request
ML::Parse_Context context("Bid Request", payload.c_str(), payload.size());
res.reset(OpenRtbBidRequestParser::parseBidRequest(context, exchangeName(), exchangeName()));
cerr << res->toJson() << endl;
return res;
}
HttpResponse SmaatoExchangeConnector::getResponse(const HttpAuctionHandler & connection,
const HttpHeader & requestHeader,
const Auction & auction) const
{
// Check Auction Error
cerr << "getResponse..." << endl;
OpenRTB::BidResponse response;
std::ostringstream stream;
return HttpResponse(200, "application/json", stream.str());
}
void
SmaatoExchangeConnector::
setSeatBid(Auction const & auction,
int spotNum,
OpenRTB::BidResponse & response) const {
}
} // namespace RTBKIT
namespace {
using namespace RTBKIT;
struct Init {
Init() {
ExchangeConnector::registerFactory<SmaatoExchangeConnector>();
}
} init;
}
@amimimor
Copy link

Hi Daniel ! did you get to a working connector ? I'm about to start one myself

Thanks,
Amit

@Gocrazy
Copy link
Author

Gocrazy commented May 13, 2014

Almost Done.

Thanks.
Daniel.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment