1 // Copyright 2018 Google LLC
2 //
3 // Licensed under the Apache License, Version 2.0 (the "License");
4 // you may not use this file except in compliance with the License.
5 // You may obtain a copy of the License at
6 //
7 //     http://www.apache.org/licenses/LICENSE-2.0
8 //
9 // Unless required by applicable law or agreed to in writing, software
10 // distributed under the License is distributed on an "AS IS" BASIS,
11 // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12 // See the License for the specific language governing permissions and
13 // limitations under the License.
14 
15 #ifndef GOOGLE_CLOUD_CPP_GOOGLE_CLOUD_STORAGE_INTERNAL_NOTIFICATION_REQUESTS_H
16 #define GOOGLE_CLOUD_CPP_GOOGLE_CLOUD_STORAGE_INTERNAL_NOTIFICATION_REQUESTS_H
17 
18 #include "google/cloud/storage/internal/generic_request.h"
19 #include "google/cloud/storage/internal/http_response.h"
20 #include "google/cloud/storage/notification_metadata.h"
21 #include "google/cloud/storage/version.h"
22 #include "google/cloud/storage/well_known_parameters.h"
23 #include <iosfwd>
24 
25 namespace google {
26 namespace cloud {
27 namespace storage {
28 inline namespace STORAGE_CLIENT_NS {
29 namespace internal {
30 /// Represents a request to call the `BucketAccessControls: list` API.
31 class ListNotificationsRequest
32     : public GenericRequest<ListNotificationsRequest, UserProject> {
33  public:
34   ListNotificationsRequest() = default;
ListNotificationsRequest(std::string bucket)35   explicit ListNotificationsRequest(std::string bucket)
36       : bucket_name_(std::move(bucket)) {}
37 
bucket_name()38   std::string const& bucket_name() const { return bucket_name_; }
39 
40  private:
41   std::string bucket_name_;
42 };
43 
44 std::ostream& operator<<(std::ostream& os, ListNotificationsRequest const& r);
45 
46 /// Represents a response to the `Notification: list` API.
47 struct ListNotificationsResponse {
48   static StatusOr<ListNotificationsResponse> FromHttpResponse(
49       std::string const& payload);
50 
51   std::vector<NotificationMetadata> items;
52 };
53 
54 std::ostream& operator<<(std::ostream& os, ListNotificationsResponse const& r);
55 
56 /**
57  * Represents a request to call the `Notifications: insert` API.
58  */
59 class CreateNotificationRequest
60     : public GenericRequest<CreateNotificationRequest, UserProject> {
61  public:
62   CreateNotificationRequest() = default;
CreateNotificationRequest(std::string bucket,NotificationMetadata const & notification)63   CreateNotificationRequest(std::string bucket,
64                             NotificationMetadata const& notification)
65       : bucket_name_(std::move(bucket)),
66         json_payload_(notification.JsonPayloadForInsert()) {}
67 
bucket_name()68   std::string const& bucket_name() const { return bucket_name_; }
json_payload()69   std::string const& json_payload() const { return json_payload_; }
70 
71  private:
72   std::string bucket_name_;
73   std::string json_payload_;
74 };
75 
76 std::ostream& operator<<(std::ostream& os, CreateNotificationRequest const& r);
77 
78 /**
79  * Represents common attributes to multiple `Notifications` request
80  * types.
81  *
82  * The classes to represent requests for the `Notifications: create`,
83  * `get`, `delete`, `patch`, and `update` APIs have a lot of commonality. This
84  * template class refactors that code.
85  */
86 template <typename Derived>
87 class GenericNotificationRequest : public GenericRequest<Derived, UserProject> {
88  public:
89   GenericNotificationRequest() = default;
GenericNotificationRequest(std::string bucket,std::string notification_id)90   GenericNotificationRequest(std::string bucket, std::string notification_id)
91       : bucket_name_(std::move(bucket)),
92         notification_id_(std::move(notification_id)) {}
93 
bucket_name()94   std::string const& bucket_name() const { return bucket_name_; }
notification_id()95   std::string const& notification_id() const { return notification_id_; }
96 
97  private:
98   std::string bucket_name_;
99   std::string notification_id_;
100 };
101 
102 /**
103  * Represents a request to call the `Notifications: get` API.
104  */
105 class GetNotificationRequest
106     : public GenericNotificationRequest<GetNotificationRequest> {
107   using GenericNotificationRequest::GenericNotificationRequest;
108 };
109 
110 std::ostream& operator<<(std::ostream& os, GetNotificationRequest const& r);
111 
112 /**
113  * Represents a request to call the `Notifications: delete` API.
114  */
115 class DeleteNotificationRequest
116     : public GenericNotificationRequest<DeleteNotificationRequest> {
117   using GenericNotificationRequest::GenericNotificationRequest;
118 };
119 
120 std::ostream& operator<<(std::ostream& os, DeleteNotificationRequest const& r);
121 
122 }  // namespace internal
123 }  // namespace STORAGE_CLIENT_NS
124 }  // namespace storage
125 }  // namespace cloud
126 }  // namespace google
127 
128 #endif  // GOOGLE_CLOUD_CPP_GOOGLE_CLOUD_STORAGE_INTERNAL_NOTIFICATION_REQUESTS_H
129