From 808f111a336569c7ff83cac5e257040edf6cd9d9 Mon Sep 17 00:00:00 2001 From: Arsentiy Milchakov Date: Mon, 23 Oct 2017 14:37:28 +0300 Subject: [partners_api] booking review fixes --- platform/http_client.cpp | 19 +++++++++++++++++++ platform/http_client.hpp | 5 +++++ 2 files changed, 24 insertions(+) (limited to 'platform') 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; + // 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); -- cgit v1.2.3