calendar_api_response_types.h 5.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184
  1. // Copyright 2021 The Chromium Authors. All rights reserved.
  2. // Use of this source code is governed by a BSD-style license that can be
  3. // found in the LICENSE file.
  4. #ifndef GOOGLE_APIS_CALENDAR_CALENDAR_API_RESPONSE_TYPES_H_
  5. #define GOOGLE_APIS_CALENDAR_CALENDAR_API_RESPONSE_TYPES_H_
  6. #include <stdint.h>
  7. #include <memory>
  8. #include <string>
  9. #include <utility>
  10. #include <vector>
  11. #include "base/compiler_specific.h"
  12. #include "base/gtest_prod_util.h"
  13. #include "base/strings/string_piece.h"
  14. #include "base/time/time.h"
  15. #include "url/gurl.h"
  16. namespace base {
  17. class Value;
  18. template <class StructType>
  19. class JSONValueConverter;
  20. } // namespace base
  21. namespace google_apis {
  22. namespace calendar {
  23. // Parses the time field in the calendar Events.list response.
  24. class DateTime {
  25. public:
  26. DateTime();
  27. DateTime(const DateTime&);
  28. DateTime& operator=(const DateTime& src);
  29. ~DateTime();
  30. // Registers the mapping between JSON field names and the members in this
  31. // class.
  32. static void RegisterJSONConverter(
  33. base::JSONValueConverter<DateTime>* converter);
  34. // Creates DateTime from parsed JSON.
  35. static bool CreateDateTimeFromValue(const base::Value* value, DateTime* time);
  36. const base::Time& date_time() const { return date_time_; }
  37. void set_date_time(const base::Time& date_time) { date_time_ = date_time; }
  38. private:
  39. base::Time date_time_;
  40. };
  41. // Parses the event item from the response. Not every field is parsed. If you
  42. // find the field you want to use is not parsed here, you will need to add it.
  43. class CalendarEvent {
  44. public:
  45. CalendarEvent();
  46. CalendarEvent(const CalendarEvent&);
  47. CalendarEvent& operator=(const CalendarEvent&);
  48. ~CalendarEvent();
  49. // Status of the event.
  50. enum class EventStatus {
  51. kUnknown,
  52. kCancelled,
  53. kConfirmed,
  54. kTentative,
  55. };
  56. // The attendee's response status.
  57. enum class ResponseStatus {
  58. kUnknown,
  59. kAccepted,
  60. kDeclined,
  61. kNeedsAction,
  62. kTentative,
  63. };
  64. // Registers the mapping between JSON field names and the members in this
  65. // class.
  66. static void RegisterJSONConverter(
  67. base::JSONValueConverter<CalendarEvent>* converter);
  68. // Creates CalendarEvent from parsed JSON.
  69. static std::unique_ptr<CalendarEvent> CreateFrom(const base::Value& value);
  70. // The ID of this Calendar Event.
  71. const std::string& id() const { return id_; }
  72. void set_id(const std::string& id) { id_ = id; }
  73. // The title of the event (meeting's name).
  74. const std::string& summary() const { return summary_; }
  75. void set_summary(const std::string& summary) { summary_ = summary; }
  76. // An absolute link to this event in the Google Calendar Web UI.
  77. const std::string& html_link() const { return html_link_; }
  78. void set_html_link(const std::string& link) { html_link_ = link; }
  79. // The color id of the event.
  80. const std::string& color_id() const { return color_id_; }
  81. void set_color_id(const std::string& color_id) { color_id_ = color_id; }
  82. // The status of the event.
  83. EventStatus status() const { return status_; }
  84. void set_status(EventStatus status) { status_ = status; }
  85. // The self attendency response status of the event.
  86. ResponseStatus self_response_status() const { return self_response_status_; }
  87. void set_self_response_status(ResponseStatus self_response_status) {
  88. self_response_status_ = self_response_status;
  89. }
  90. const DateTime& start_time() const { return start_time_; }
  91. void set_start_time(const DateTime& start_time) { start_time_ = start_time; }
  92. const DateTime& end_time() const { return end_time_; }
  93. void set_end_time(const DateTime& end_time) { end_time_ = end_time; }
  94. // Return the approximate size of this event, in bytes.
  95. int GetApproximateSizeInBytes() const;
  96. private:
  97. std::string id_;
  98. std::string summary_;
  99. std::string html_link_;
  100. std::string color_id_;
  101. EventStatus status_ = EventStatus::kUnknown;
  102. ResponseStatus self_response_status_ = ResponseStatus::kUnknown;
  103. DateTime start_time_;
  104. DateTime end_time_;
  105. };
  106. // Parses a list of calendar events.
  107. class EventList {
  108. public:
  109. EventList();
  110. EventList(const EventList&) = delete;
  111. EventList& operator=(const EventList&) = delete;
  112. ~EventList();
  113. // Registers the mapping between JSON field names and the members in this
  114. // class.
  115. static void RegisterJSONConverter(
  116. base::JSONValueConverter<EventList>* converter);
  117. // Creates EventList from parsed JSON.
  118. static std::unique_ptr<EventList> CreateFrom(const base::Value& value);
  119. // Returns time zone.
  120. const std::string& time_zone() const { return time_zone_; }
  121. // Returns ETag for this calendar.
  122. const std::string& etag() const { return etag_; }
  123. // Returns the kind.
  124. const std::string& kind() const { return kind_; }
  125. void set_time_zone(const std::string& time_zone) { time_zone_ = time_zone; }
  126. void set_etag(const std::string& etag) { etag_ = etag; }
  127. void set_kind(const std::string& kind) { kind_ = kind; }
  128. // Returns a set of events in this calendar.
  129. const std::vector<std::unique_ptr<CalendarEvent>>& items() const {
  130. return items_;
  131. }
  132. std::vector<std::unique_ptr<CalendarEvent>>* mutable_items() {
  133. return &items_;
  134. }
  135. void InjectItemForTesting(std::unique_ptr<CalendarEvent> item);
  136. private:
  137. std::string time_zone_;
  138. std::string etag_;
  139. std::string kind_;
  140. std::vector<std::unique_ptr<CalendarEvent>> items_;
  141. };
  142. } // namespace calendar
  143. } // namespace google_apis
  144. #endif // GOOGLE_APIS_CALENDAR_CALENDAR_API_RESPONSE_TYPES_H_