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: db9b9c41c4fe522fbe89976e024719c02602218e (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
#pragma once

#include "platform/http_request.hpp"

#include "std/chrono.hpp"
#include "std/function.hpp"
#include "std/initializer_list.hpp"
#include "std/limits.hpp"
#include "std/string.hpp"
#include "std/unique_ptr.hpp"
#include "std/utility.hpp"

class BookingApi
{
  string m_affiliateId;
  string m_apiUrl;

public:
  struct HotelPhotoUrls
  {
    string m_small;
    string m_original;
  };

  struct HotelReview
  {
    HotelReview() = default;
    // C++11 doesn't allow aggragate initialization for structs with default member initializer.
    // But C++14 does.
    HotelReview(string const & reviewPositive,
                string const & reviewNegative,
                string const & reviewNeutral,
                string const & author,
                string const & authorPictUrl,
                float const rating,
                time_point<system_clock> const date)
      : m_reviewPositive(reviewPositive)
      , m_reviewNegative(reviewNegative)
      , m_reviewNeutral(reviewNeutral)
      , m_author(author)
      , m_authorPictUrl(authorPictUrl)
      , m_rating(rating)
      , m_date(date)
    {
    }


    static HotelReview CriticReview(string const & reviewPositive,
                                    string const & reviewNegative,
                                    string const & author,
                                    string const & authorPictUrl,
                                    float const rating,
                                    time_point<system_clock> const date)
    {
      return {
        reviewPositive,
        reviewNegative,
        "",
        author,
        authorPictUrl,
        rating,
        date
     };
    }

    static HotelReview NeutralReview(string const & reviewNeutral,
                                     string const & author,
                                     string const & authorPictUrl,
                                     float const rating,
                                     time_point<system_clock> const date)
    {
      return {
        "",
        "",
        reviewNeutral,
        author,
        authorPictUrl,
        rating,
        date
     };
    }

    static auto constexpr kInvalidRating = numeric_limits<float>::max();

    /// Review text. There can be either one or both positive/negative review or
    /// a neutral one.
    string m_reviewPositive;
    string m_reviewNegative;
    string m_reviewNeutral;
    /// Review author name.
    string m_author;
    /// Url to a author's picture.
    string m_authorPictUrl;
    /// Author's hotel evaluation.
    float m_rating = kInvalidRating;
    /// An issue date.
    time_point<system_clock> m_date;
  };

  struct Facility
  {
    string m_id;
    string m_localizedName;
  };

  struct HotelInfo
  {
    string m_hotelId;

    string m_description;
    vector<HotelPhotoUrls> m_photos;
    vector<Facility> m_facilities;
    vector<HotelReview> m_reviews;
  };

  static constexpr const char kDefaultCurrency[1] = {0};

  BookingApi();
  string GetBookingUrl(string const & baseUrl, string const & lang = string()) const;
  string GetDescriptionUrl(string const & baseUrl, string const & lang = string()) const;

  // Real-time information methods (used for retriving rapidly changing information).
  // These methods send requests directly to Booking.
  void GetMinPrice(string const & hotelId, string const & currency,
                   function<void(string const &, string const &)> const & fn);


  // Static information methods (use for information that can be cached).
  // These methods use caching server to prevent Booking from being ddossed.
  void GetHotelInfo(string const & hotelId, string const & lang,
                    function<void(HotelInfo const & hotelInfo)> const & fn);

protected:
  unique_ptr<downloader::HttpRequest> m_request;
  string MakeApiUrl(string const & func, initializer_list<pair<string, string>> const & params);
};