diff options
author | Arsentiy Milchakov <milcars@mapswithme.com> | 2017-10-23 14:37:28 +0300 |
---|---|---|
committer | Yuri Gorshenin <mipt.vi002@gmail.com> | 2017-10-23 16:03:33 +0300 |
commit | 808f111a336569c7ff83cac5e257040edf6cd9d9 (patch) | |
tree | 560e1af9664f73bdf5449fe569de9eba4e1b51b9 /platform | |
parent | 3142fb96b9c308cddb108d75c4b9b516a67559a2 (diff) |
[partners_api] booking review fixes
Diffstat (limited to 'platform')
-rw-r--r-- | platform/http_client.cpp | 19 | ||||
-rw-r--r-- | platform/http_client.hpp | 5 |
2 files changed, 24 insertions, 0 deletions
diff --git a/platform/http_client.cpp b/platform/http_client.cpp index 7688a7438c..a7b3a03641 100644 --- a/platform/http_client.cpp +++ b/platform/http_client.cpp @@ -17,6 +17,25 @@ HttpClient::HttpClient(string const & url) : m_urlRequested(url) #endif } +bool HttpClient::RunHttpRequest(string & response, SuccessChecker checker /* = nullptr */) +{ + static auto const simpleChecker = [](HttpClient const & request) + { + return request.ErrorCode() == 200; + }; + + if (checker == nullptr) + checker = simpleChecker; + + if (RunHttpRequest() && checker(*this)) + { + response = ServerResponse(); + return true; + } + + return false; +} + HttpClient & HttpClient::SetUrlRequested(string const & url) { m_urlRequested = url; diff --git a/platform/http_client.hpp b/platform/http_client.hpp index d21ef6a880..37f6096d90 100644 --- a/platform/http_client.hpp +++ b/platform/http_client.hpp @@ -44,6 +44,11 @@ public: // @note Implementations should transparently support all needed HTTP redirects. // Implemented for each platform. bool RunHttpRequest(); + using SuccessChecker = std::function<bool(HttpClient const & request)>; + // Returns true and copy of server response into [response] in case when RunHttpRequest() and + // [checker] return true. When [checker] is equal to nullptr then default checker will be used. + // Check by default: ErrorCode() == 200 + bool RunHttpRequest(string & response, SuccessChecker checker = nullptr); // Shared methods for all platforms, implemented at http_client.cpp HttpClient & SetDebugMode(bool debug_mode); |