1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
|
#pragma once
#include "partners_api/taxi_base.hpp"
#include "partners_api/taxi_delegate.hpp"
#include "base/visitor.hpp"
#include <string>
#include <unordered_map>
namespace ms
{
class LatLon;
}
namespace taxi
{
namespace rutaxi
{
struct City
{
std::string m_id;
std::string m_currency;
};
using CityMapping = std::unordered_map<std::string, City>;
struct Object
{
std::string m_id;
std::string m_house;
std::string m_title;
};
struct OsmToId
{
std::string m_osmName;
std::string m_id;
};
extern std::string const kTaxiInfoUrl;
/// RuTaxi api wrapper is based on synchronous http requests.
class RawApi
{
public:
static bool GetNearObject(ms::LatLon const & pos, std::string const & city, std::string & result,
std::string const & baseUrl = kTaxiInfoUrl);
static bool GetCost(Object const & from, Object const & to, std::string const & city,
std::string & result, std::string const & baseUrl = kTaxiInfoUrl);
};
/// Class which is used for making products from http requests results.
class Api : public ApiBase
{
public:
explicit Api(std::string const & baseUrl = kTaxiInfoUrl);
void SetDelegate(Delegate * delegate);
// ApiBase overrides:
/// Requests list of available products from RuTaxi.
void GetAvailableProducts(ms::LatLon const & from, ms::LatLon const & to,
ProductsCallback const & successFn,
ErrorProviderCallback const & errorFn) override;
/// Returns link which allows you to launch the RuTaxi app.
RideRequestLinks GetRideRequestLinks(std::string const & productId, ms::LatLon const & from,
ms::LatLon const & to) const override;
private:
// Non-owning delegate pointer
Delegate * m_delegate = nullptr;
CityMapping m_cityMapping;
};
void MakeNearObject(std::string const & src, Object & dst);
void MakeProducts(std::string const & src, Object const & from, Object const & to,
City const & city, std::vector<taxi::Product> & products);
CityMapping LoadCityMapping();
} // namespace rutaxi
} // namespace taxi
|