[partners_api] cian review fixes

This commit is contained in:
Arsentiy Milchakov 2017-07-11 18:34:04 +03:00 committed by Roman Kuznetsov
parent 0cfb088c53
commit d740f9eef6
10 changed files with 48 additions and 42 deletions

View file

@ -31,6 +31,7 @@ set(
taxi_provider.hpp
uber_api.cpp
uber_api.hpp
utils.hpp
viator_api.cpp
viator_api.hpp
yandex_api.cpp

View file

@ -1,6 +1,6 @@
#include "partners_api/cian_api.hpp"
#include "partners_api/utils.hpp"
#include "platform/http_client.hpp"
#include "platform/platform.hpp"
#include "geometry/rect2d.hpp"
@ -15,17 +15,6 @@ using namespace platform;
namespace
{
bool RunSimpleHttpRequest(string const & url, string & result)
{
HttpClient request(url);
if (request.RunHttpRequest() && !request.WasRedirected() && request.ErrorCode() == 200)
{
result = request.ServerResponse();
return true;
}
return false;
}
void MakeResult(std::string const & src, std::vector<cian::RentPlace> & result)
{
my::Json root(src.c_str());
@ -39,9 +28,6 @@ void MakeResult(std::string const & src, std::vector<cian::RentPlace> & result)
size_t const clustersSize = json_array_size(clusters);
if (clustersSize == 0)
return;
for (size_t i = 0; i < clustersSize; ++i)
{
auto cluster = json_array_get(clusters, i);
@ -52,12 +38,12 @@ void MakeResult(std::string const & src, std::vector<cian::RentPlace> & result)
json_t * offers = json_object_get(cluster, "offers");
if (offers == nullptr)
return;
continue;
size_t const offersSize = json_array_size(offers);
if (offersSize == 0)
return;
continue;
for (size_t i = 0; i < offersSize; ++i)
{
@ -83,15 +69,17 @@ void MakeResult(std::string const & src, std::vector<cian::RentPlace> & result)
namespace cian
{
std::string const kBaseUrl = "https://api.cian.ru/rent-nearby/v1";
// static
bool RawApi::GetRentNearby(m2::RectD const & rect, std::string & result,
std::string const & baseUrl /* = kBaseUrl */)
{
ostringstream url;
std::ostringstream url;
url << baseUrl << "/get-offers-in-bbox/?bbox=" << rect.minX() << ',' << rect.maxY() << '~'
<< rect.maxX() << ',' << rect.minY();
return RunSimpleHttpRequest(url.str(), result);
return partners_api_utils::RunSimpleHttpRequest(url.str(), result);
}
Api::Api(std::string const & baseUrl /* = kBaseUrl */) : m_baseUrl(baseUrl) {}

View file

@ -12,7 +12,7 @@
namespace cian
{
std::string const kBaseUrl = "https://api.cian.ru/rent-nearby/v1";
extern std::string const kBaseUrl;
class RawApi
{
@ -38,12 +38,12 @@ struct RentPlace
std::vector<RentOffer> m_offers;
};
using RentNearbyCallback =
std::function<void(std::vector<RentPlace> const & places, uint64_t const requestId)>;
class Api
{
public:
using RentNearbyCallback =
std::function<void(std::vector<RentPlace> const & places, uint64_t const requestId)>;
explicit Api(std::string const & baseUrl = kBaseUrl);
virtual ~Api();

View file

@ -40,5 +40,6 @@ HEADERS += \
taxi_places.hpp \
taxi_provider.hpp \
uber_api.hpp \
utils.hpp \
viator_api.cpp \
yandex_api.hpp \

View file

@ -1,6 +1,5 @@
#include "partners_api/uber_api.hpp"
#include "platform/http_client.hpp"
#include "partners_api/utils.hpp"
#include "geometry/latlon.hpp"
@ -18,17 +17,6 @@ using namespace platform;
namespace
{
bool RunSimpleHttpRequest(string const & url, string & result)
{
HttpClient request(url);
if (request.RunHttpRequest() && !request.WasRedirected() && request.ErrorCode() == 200)
{
result = request.ServerResponse();
return true;
}
return false;
}
bool CheckUberResponse(json_t const * answer)
{
if (answer == nullptr)
@ -118,6 +106,9 @@ namespace taxi
{
namespace uber
{
string const kEstimatesUrl = "https://api.uber.com/v1/estimates";
string const kProductsUrl = "https://api.uber.com/v1/products";
// static
bool RawApi::GetProducts(ms::LatLon const & pos, string & result,
std::string const & baseUrl /* = kProductsUrl */)
@ -126,7 +117,7 @@ bool RawApi::GetProducts(ms::LatLon const & pos, string & result,
url << fixed << setprecision(6) << baseUrl << "?server_token=" << UBER_SERVER_TOKEN
<< "&latitude=" << pos.lat << "&longitude=" << pos.lon;
return RunSimpleHttpRequest(url.str(), result);
return partners_api_utils::RunSimpleHttpRequest(url.str(), result);
}
// static
@ -137,7 +128,7 @@ bool RawApi::GetEstimatedTime(ms::LatLon const & pos, string & result,
url << fixed << setprecision(6) << baseUrl << "/time?server_token=" << UBER_SERVER_TOKEN
<< "&start_latitude=" << pos.lat << "&start_longitude=" << pos.lon;
return RunSimpleHttpRequest(url.str(), result);
return partners_api_utils::RunSimpleHttpRequest(url.str(), result);
}
// static
@ -149,7 +140,7 @@ bool RawApi::GetEstimatedPrice(ms::LatLon const & from, ms::LatLon const & to, s
<< "&start_latitude=" << from.lat << "&start_longitude=" << from.lon
<< "&end_latitude=" << to.lat << "&end_longitude=" << to.lon;
return RunSimpleHttpRequest(url.str(), result);
return partners_api_utils::RunSimpleHttpRequest(url.str(), result);
}
void ProductMaker::Reset(uint64_t const requestId)

View file

@ -23,8 +23,8 @@ namespace taxi
{
namespace uber
{
string const kEstimatesUrl = "https://api.uber.com/v1/estimates";
string const kProductsUrl = "https://api.uber.com/v1/products";
extern string const kEstimatesUrl;
extern string const kProductsUrl;
/// Uber api wrapper based on synchronous http requests.
class RawApi
{

19
partners_api/utils.hpp Normal file
View file

@ -0,0 +1,19 @@
#pragma once
#include "platform/http_client.hpp"
#include <string>
namespace partners_api_utils
{
inline bool RunSimpleHttpRequest(std::string const & url, std::string & result)
{
platform::HttpClient request(url);
if (request.RunHttpRequest() && !request.WasRedirected() && request.ErrorCode() == 200)
{
result = request.ServerResponse();
return true;
}
return false;
}
} // namespace partners_api_utils

View file

@ -51,6 +51,8 @@ namespace taxi
{
namespace yandex
{
std::string const kTaxiInfoUrl = "https://taxi-routeinfo.taxi.yandex.net";
Countries const kEnabledCountries = {{{}}};
bool RawApi::GetTaxiInfo(ms::LatLon const & from, ms::LatLon const & to, std::string & result,

View file

@ -13,7 +13,7 @@ namespace taxi
{
namespace yandex
{
std::string const kTaxiInfoUrl = "https://taxi-routeinfo.taxi.yandex.net";
extern std::string const kTaxiInfoUrl;
/// Yandex api wrapper based on synchronous http requests.
class RawApi
{

View file

@ -27,6 +27,7 @@
3D47B2AC1F14BE89000828D2 /* cian_api.cpp in Sources */ = {isa = PBXBuildFile; fileRef = 3D47B2AA1F14BE89000828D2 /* cian_api.cpp */; };
3D47B2AD1F14BE89000828D2 /* cian_api.hpp in Headers */ = {isa = PBXBuildFile; fileRef = 3D47B2AB1F14BE89000828D2 /* cian_api.hpp */; };
3D47B2AF1F14BE94000828D2 /* cian_tests.cpp in Sources */ = {isa = PBXBuildFile; fileRef = 3D47B2AE1F14BE94000828D2 /* cian_tests.cpp */; };
3D47B2B11F14FA14000828D2 /* utils.hpp in Headers */ = {isa = PBXBuildFile; fileRef = 3D47B2B01F14FA14000828D2 /* utils.hpp */; };
3DBC1C541E4B14920016897F /* facebook_ads.cpp in Sources */ = {isa = PBXBuildFile; fileRef = 3DBC1C521E4B14920016897F /* facebook_ads.cpp */; };
3DBC1C551E4B14920016897F /* facebook_ads.hpp in Headers */ = {isa = PBXBuildFile; fileRef = 3DBC1C531E4B14920016897F /* facebook_ads.hpp */; };
3DFEBF851EF82BEA00317D5C /* viator_api.cpp in Sources */ = {isa = PBXBuildFile; fileRef = 3DFEBF831EF82BEA00317D5C /* viator_api.cpp */; };
@ -81,6 +82,7 @@
3D47B2AA1F14BE89000828D2 /* cian_api.cpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.cpp; path = cian_api.cpp; sourceTree = "<group>"; };
3D47B2AB1F14BE89000828D2 /* cian_api.hpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.h; path = cian_api.hpp; sourceTree = "<group>"; };
3D47B2AE1F14BE94000828D2 /* cian_tests.cpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.cpp; path = cian_tests.cpp; sourceTree = "<group>"; };
3D47B2B01F14FA14000828D2 /* utils.hpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.h; path = utils.hpp; sourceTree = "<group>"; };
3DBC1C501E4B14810016897F /* facebook_tests.cpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.cpp; path = facebook_tests.cpp; sourceTree = "<group>"; };
3DBC1C521E4B14920016897F /* facebook_ads.cpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.cpp; path = facebook_ads.cpp; sourceTree = "<group>"; };
3DBC1C531E4B14920016897F /* facebook_ads.hpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.h; path = facebook_ads.hpp; sourceTree = "<group>"; };
@ -166,6 +168,7 @@
F6B5363B1DA520B20067EEA5 /* partners_api */ = {
isa = PBXGroup;
children = (
3D47B2B01F14FA14000828D2 /* utils.hpp */,
3D47B2AA1F14BE89000828D2 /* cian_api.cpp */,
3D47B2AB1F14BE89000828D2 /* cian_api.hpp */,
3D47B2961F054C89000828D2 /* taxi_base.cpp */,
@ -256,6 +259,7 @@
F67E75261DB8F06F00D6741F /* opentable_api.hpp in Headers */,
F6B536411DA520E40067EEA5 /* booking_api.hpp in Headers */,
3430643D1E9FBCF500DC7665 /* mopub_ads.hpp in Headers */,
3D47B2B11F14FA14000828D2 /* utils.hpp in Headers */,
3DFEBF861EF82BEA00317D5C /* viator_api.hpp in Headers */,
346E889C1E9D087400D4CE9B /* rb_ads.hpp in Headers */,
3DFEBF9A1EFBFC1500317D5C /* taxi_base.hpp in Headers */,