Welcome to mirror list, hosted at ThFree Co, Russian Federation.

booking_api.hpp « partners_api - github.com/mapsme/omim.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
blob: f70577a6648f7ce1945587a47ed95838ef72e5e3 (plain)
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
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
#pragma once

#include "partners_api/booking_availability_params.hpp"
#include "partners_api/booking_block_params.hpp"

#include "platform/safe_callback.hpp"

#include <chrono>
#include <functional>
#include <string>
#include <vector>

namespace booking
{
struct HotelPhotoUrls
{
  std::string m_small;
  std::string m_original;
};

struct HotelReview
{
  /// An issue date.
  std::chrono::time_point<std::chrono::system_clock> m_date;
  /// Author's hotel evaluation.
  float m_score = 0.0;
  /// Review author name.
  std::string m_author;
  /// Review text. There can be either one or both positive/negative review.
  std::string m_pros;
  std::string m_cons;
};

struct HotelFacility
{
  std::string m_type;
  std::string m_name;
};

struct HotelInfo
{
  std::string m_hotelId;

  std::string m_description;
  std::vector<HotelPhotoUrls> m_photos;
  std::vector<HotelFacility> m_facilities;
  std::vector<HotelReview> m_reviews;
  float m_score = 0.0;
  uint32_t m_scoreCount = 0;
};

struct Deals
{
  enum class Type
  {
    /// Good price.
    Smart,
    /// Sale with discount in percent from base price.
    LastMinute
  };

  std::vector<Type> m_types;
  uint8_t m_discount = 0;
};

struct BlockInfo
{
  static double constexpr kIncorrectPrice = std::numeric_limits<double>::max();
  std::string m_blockId;
  std::string m_name;
  std::string m_description;
  uint8_t m_maxOccupancy = 0;
  double m_minPrice = kIncorrectPrice;
  std::string m_currency;
  std::vector<std::string> m_photos;
  Deals m_deals;
  std::chrono::time_point<std::chrono::system_clock> m_refundableUntil;
  bool m_breakfastIncluded = false;
  bool m_depositRequired = false;
};

struct Blocks
{
  void Add(BlockInfo && block)
  {
    if (block.m_minPrice < m_totalMinPrice)
    {
      m_totalMinPrice = block.m_minPrice;
      m_currency = block.m_currency;
    }
    if (!m_hasSmartDeal)
    {
      auto const & types = block.m_deals.m_types;
      m_hasSmartDeal = std::find(types.cbegin(), types.cend(), Deals::Type::Smart) != types.cend();
    }
    if (block.m_deals.m_discount > m_maxDiscount)
      m_maxDiscount = block.m_deals.m_discount;

    m_blocks.emplace_back(block);
  }

  double m_totalMinPrice = BlockInfo::kIncorrectPrice;
  std::string m_currency;

  uint8_t m_maxDiscount = 0;
  bool m_hasSmartDeal = false;

  std::vector<BlockInfo> m_blocks;
};

class RawApi
{
public:
  // Booking Api v1 methods:
  static bool GetHotelAvailability(std::string const & hotelId, std::string const & currency, std::string & result);
  static bool GetExtendedInfo(std::string const & hotelId, std::string const & lang, std::string & result);
  // Booking Api v2 methods:
  static bool HotelAvailability(AvailabilityParams const & params, std::string & result);
  static bool BlockAvailability(BlockParams const & params, string & result);
  static size_t constexpr GetMaxHotelsInAvailabilityRequest() { return 300; };
};

using BlockAvailabilityCallback =
    platform::SafeCallback<void(std::string const & hotelId, Blocks const & blocks)>;
using GetHotelInfoCallback = platform::SafeCallback<void(HotelInfo const & hotelInfo)>;
// NOTE: this callback will be called on the network thread.
using GetHotelAvailabilityCallback = std::function<void(std::vector<std::string> hotelIds)>;

/// This is a lightweight class but methods are non-static in order to support the NetworkPolicy
/// restrictions.
/// Callbacks will be called in the same order as methods are called.
class Api
{
public:
  std::string GetBookHotelUrl(std::string const & baseUrl) const;
  std::string GetDeepLink(std::string const & hotelId) const;
  std::string GetDescriptionUrl(std::string const & baseUrl) const;
  std::string GetMoreUrl(string const & baseUrl) const;
  std::string GetHotelReviewsUrl(std::string const & hotelId, std::string const & baseUrl) const;
  std::string GetSearchUrl(std::string const & city, std::string const & name) const;
  std::string ApplyAvailabilityParams(std::string const & url,
                                      AvailabilityParams const & params) const;

  /// Real-time information methods (used for retrieving rapidly changing information).
  /// These methods send requests directly to Booking.
  void GetBlockAvailability(BlockParams && params, BlockAvailabilityCallback const & fn) const;

  /// NOTE: callback will be called on the network thread.
  void GetHotelAvailability(AvailabilityParams const & params,
                            GetHotelAvailabilityCallback const & fn) const;

  /// Static information methods (use for information that can be cached).
  /// These methods use caching server to prevent Booking from being ddossed.
  void GetHotelInfo(std::string const & hotelId, std::string const & lang,
                    GetHotelInfoCallback const & fn) const;
};

void SetBookingUrlForTesting(std::string const & url);
}  // namespace booking