From 84f063374912a73145cbb0b45d875e1f557e88de Mon Sep 17 00:00:00 2001 From: kraxarn Date: Sat, 9 Mar 2024 15:20:14 +0000 Subject: [PATCH] deploy: edce0eb6c9e395db39c38a5e6b3898e554e0c016 --- classlib_1_1spt_1_1api-members.html | 2 +- classlib_1_1spt_1_1api.html | 6 +- request_8hpp_source.html | 318 ++++++++++++++-------------- spotify_2api_8hpp_source.html | 4 +- 4 files changed, 164 insertions(+), 166 deletions(-) diff --git a/classlib_1_1spt_1_1api-members.html b/classlib_1_1spt_1_1api-members.html index 51b0c385..77fea2d4 100644 --- a/classlib_1_1spt_1_1api-members.html +++ b/classlib_1_1spt_1_1api-members.html @@ -85,7 +85,7 @@ add_to_playlist(const std::string &playlist_id, const std::vector< std::string > &track_uris, lib::callback< std::string > &callback) (defined in lib::spt::api)lib::spt::api add_to_queue(const std::string &uri, lib::callback< lib::result< void * > > &callback)lib::spt::api album(const std::string &id, lib::callback< lib::spt::album > &callback) (defined in lib::spt::api)lib::spt::api - album_tracks(const lib::spt::album &album, lib::callback< std::vector< lib::spt::track > > &callback) (defined in lib::spt::api)lib::spt::api + album_tracks(const spt::album &album, const paged_callback< spt::track > &callback) const (defined in lib::spt::api)lib::spt::api albums(const spt::artist &artist, const std::vector< album_group > &groups, const paged_callback< spt::album > &callback) const (defined in lib::spt::api)lib::spt::api api(lib::settings &settings, const lib::http_client &http_client, lib::spt::request &request)lib::spt::api artist(const std::string &id, lib::callback< lib::spt::artist > &callback) (defined in lib::spt::api)lib::spt::api diff --git a/classlib_1_1spt_1_1api.html b/classlib_1_1spt_1_1api.html index 448227b8..fdaa0c76 100644 --- a/classlib_1_1spt_1_1api.html +++ b/classlib_1_1spt_1_1api.html @@ -94,9 +94,9 @@ void album (const std::string &id, lib::callback< lib::spt::album > &callback)   - -void album_tracks (const lib::spt::album &album, lib::callback< std::vector< lib::spt::track > > &callback) -  + +void album_tracks (const spt::album &album, const paged_callback< spt::track > &callback) const void artist (const std::string &id, lib::callback< lib::spt::artist > &callback)   diff --git a/request_8hpp_source.html b/request_8hpp_source.html index 0175b55a..00ae58be 100644 --- a/request_8hpp_source.html +++ b/request_8hpp_source.html @@ -134,169 +134,167 @@
63 ? lib::spt::to_relative_url(url)
64 : url;
65
-
66 lib::log::debug("GET: {}", api_url);
-
67
-
68 get<nlohmann::json>(api_url, [this, key, callback](const lib::result<nlohmann::json> &result)
-
69 {
-
70 if (!result.success())
-
71 {
-
72 const auto message = parse_error_message(result.message());
-
73 callback(lib::result<lib::spt::page<T>>::fail(message));
-
74 return;
-
75 }
-
76
-
77 const auto &json = result.value();
-
78 if (!key.empty() && !json.contains(key))
-
79 {
-
80 const auto message = lib::fmt::format("No such key: {}", key);
-
81 callback(lib::result<lib::spt::page<T>>::fail(message));
-
82 return;
-
83 }
-
84
-
85 lib::spt::page<T> page;
-
86 try
-
87 {
-
88 page = key.empty() ? json : json.at(key);
-
89 }
-
90 catch (const std::exception &exception)
-
91 {
-
92 const std::string message = exception.what();
-
93 callback(lib::result<lib::spt::page<T>>::fail(message));
-
94 return;
-
95 }
-
96
-
97 if (!callback(lib::result<lib::spt::page<T>>::ok(page))
-
98 || !page.has_next())
-
99 {
-
100 return;
-
101 }
-
102
-
103 get_page(page.next, key, callback);
-
104 });
-
105 }
+
66 get<nlohmann::json>(api_url, [this, key, callback](const lib::result<nlohmann::json> &result)
+
67 {
+
68 if (!result.success())
+
69 {
+
70 const auto message = parse_error_message(result.message());
+
71 callback(lib::result<lib::spt::page<T>>::fail(message));
+
72 return;
+
73 }
+
74
+
75 const auto &json = result.value();
+
76 if (!key.empty() && !json.contains(key))
+
77 {
+
78 const auto message = lib::fmt::format("No such key: {}", key);
+
79 callback(lib::result<lib::spt::page<T>>::fail(message));
+
80 return;
+
81 }
+
82
+
83 lib::spt::page<T> page;
+
84 try
+
85 {
+
86 page = key.empty() ? json : json.at(key);
+
87 }
+
88 catch (const std::exception &exception)
+
89 {
+
90 const std::string message = exception.what();
+
91 callback(lib::result<lib::spt::page<T>>::fail(message));
+
92 return;
+
93 }
+
94
+
95 if (!callback(lib::result<lib::spt::page<T>>::ok(page))
+
96 || !page.has_next())
+
97 {
+
98 return;
+
99 }
+
100
+
101 get_page(page.next, key, callback);
+
102 });
+
103 }
-
106
-
-
110 void post(const std::string &url, lib::callback<lib::result<void *>> &callback)
-
111 {
-
112 auto headers = auth_headers();
-
113 headers["Content-Type"] = "application/x-www-form-urlencoded";
-
114
-
115 http.post(lib::spt::to_full_url(url), headers,
-
116 [callback](const lib::result<std::string> &response)
-
117 {
-
118 if (!response.success())
-
119 {
-
120 const auto message = parse_error_message(response.message());
-
121 callback(lib::result<void *>::fail(message));
-
122 return;
-
123 }
-
124 callback(parse_json(response.value()));
-
125 });
-
126 }
+
104
+
+
108 void post(const std::string &url, lib::callback<lib::result<void *>> &callback)
+
109 {
+
110 auto headers = auth_headers();
+
111 headers["Content-Type"] = "application/x-www-form-urlencoded";
+
112
+
113 http.post(lib::spt::to_full_url(url), headers,
+
114 [callback](const lib::result<std::string> &response)
+
115 {
+
116 if (!response.success())
+
117 {
+
118 const auto message = parse_error_message(response.message());
+
119 callback(lib::result<void *>::fail(message));
+
120 return;
+
121 }
+
122 callback(parse_json(response.value()));
+
123 });
+
124 }
+
125
+
126 //endregion
127
-
128 //endregion
-
129
-
130 private:
-
134 static constexpr long secs_in_hour = 60L * 60L;
-
135
- -
137 const lib::http_client &http;
- -
139
-
143 unsigned long last_auth = 0;
-
144
-
148 auto auth_headers() -> lib::headers;
-
149
-
156 auto request_refresh(const std::string &post_data,
-
157 const std::string &authorization) -> std::string;
-
158
-
162 auto get_current_device() const -> const std::string &;
-
163
-
168 void set_current_device(const std::string &device_id);
-
169
- -
177 static auto parse_json(const std::string &data) -> lib::result<T>
-
178 {
-
179 if (data.empty())
-
180 {
-
181 return lib::result<T>::ok({});
-
182 }
-
183
-
184 try
-
185 {
-
186 const auto json = nlohmann::json::parse(data);
-
187 if (!lib::spt::error::is(json))
-
188 {
-
189 return lib::result<T>::ok(json);
-
190 }
-
191
-
192 const auto message = lib::spt::error::error_message(json);
-
193 return lib::result<T>::fail(message);
-
194 }
-
195 catch (const nlohmann::json::parse_error &e)
-
196 {
-
197 lib::log::debug("JSON: {}", data);
-
198 return lib::result<T>::fail(e.what());
-
199 }
-
200 catch (const std::exception &e)
-
201 {
-
202 return lib::result<T>::fail(e.what());
-
203 }
-
204 }
-
205
-
209 static auto parse_json(const std::string &data) -> lib::result<void *>
-
210 {
-
211 if (data.empty())
-
212 {
-
213 return lib::result<void *>::ok(nullptr);
-
214 }
-
215
-
216 try
-
217 {
-
218 const nlohmann::json json = nlohmann::json::parse(data);
-
219 if (!lib::spt::error::is(json))
-
220 {
-
221 return lib::result<void *>::ok(nullptr);
-
222 }
-
223
-
224 const auto message = lib::spt::error::error_message(json);
-
225 return lib::result<void *>::fail(message);
-
226 }
-
227 catch (const nlohmann::json::parse_error &e)
-
228 {
-
229 lib::log::debug("JSON: {}", data);
-
230 return lib::result<void *>::fail(e.what());
-
231 }
-
232 catch (const std::exception &e)
-
233 {
-
234 return lib::result<void *>::fail(e.what());
-
235 }
-
236 }
-
237
-
238 static auto parse_error_message(const std::string &data) -> std::string
-
239 {
-
240 try
-
241 {
-
242 const nlohmann::json json = nlohmann::json::parse(data);
-
243 return lib::spt::error::is(json)
- -
245 : data;
-
246 }
-
247 catch (const std::exception &e)
-
248 {
-
249 lib::log::error("Failed to parse error message: {}", e.what());
-
250 return data;
-
251 }
-
252 }
-
253
-
254 // Until all requests are moved to here
-
255 friend class api;
-
256 };
+
128 private:
+
132 static constexpr long secs_in_hour = 60L * 60L;
+
133
+ +
135 const lib::http_client &http;
+ +
137
+
141 unsigned long last_auth = 0;
+
142
+
146 auto auth_headers() -> lib::headers;
+
147
+
154 auto request_refresh(const std::string &post_data,
+
155 const std::string &authorization) -> std::string;
+
156
+
160 auto get_current_device() const -> const std::string &;
+
161
+
166 void set_current_device(const std::string &device_id);
+
167
+ +
175 static auto parse_json(const std::string &data) -> lib::result<T>
+
176 {
+
177 if (data.empty())
+
178 {
+
179 return lib::result<T>::ok({});
+
180 }
+
181
+
182 try
+
183 {
+
184 const auto json = nlohmann::json::parse(data);
+
185 if (!lib::spt::error::is(json))
+
186 {
+
187 return lib::result<T>::ok(json);
+
188 }
+
189
+
190 const auto message = lib::spt::error::error_message(json);
+
191 return lib::result<T>::fail(message);
+
192 }
+
193 catch (const nlohmann::json::parse_error &e)
+
194 {
+
195 lib::log::debug("JSON: {}", data);
+
196 return lib::result<T>::fail(e.what());
+
197 }
+
198 catch (const std::exception &e)
+
199 {
+
200 return lib::result<T>::fail(e.what());
+
201 }
+
202 }
+
203
+
207 static auto parse_json(const std::string &data) -> lib::result<void *>
+
208 {
+
209 if (data.empty())
+
210 {
+
211 return lib::result<void *>::ok(nullptr);
+
212 }
+
213
+
214 try
+
215 {
+
216 const nlohmann::json json = nlohmann::json::parse(data);
+
217 if (!lib::spt::error::is(json))
+
218 {
+
219 return lib::result<void *>::ok(nullptr);
+
220 }
+
221
+
222 const auto message = lib::spt::error::error_message(json);
+
223 return lib::result<void *>::fail(message);
+
224 }
+
225 catch (const nlohmann::json::parse_error &e)
+
226 {
+
227 lib::log::debug("JSON: {}", data);
+
228 return lib::result<void *>::fail(e.what());
+
229 }
+
230 catch (const std::exception &e)
+
231 {
+
232 return lib::result<void *>::fail(e.what());
+
233 }
+
234 }
+
235
+
236 static auto parse_error_message(const std::string &data) -> std::string
+
237 {
+
238 try
+
239 {
+
240 const nlohmann::json json = nlohmann::json::parse(data);
+
241 return lib::spt::error::is(json)
+ +
243 : data;
+
244 }
+
245 catch (const std::exception &e)
+
246 {
+
247 lib::log::error("Failed to parse error message: {}", e.what());
+
248 return data;
+
249 }
+
250 }
+
251
+
252 // Until all requests are moved to here
+
253 friend class api;
+
254 };
-
257 }
-
258}
+
255 }
+
256}
Definition httpclient.hpp:21
Definition json.hpp:17
static void debug(const Format &fmt, const Arg &arg, Args &&... args)
Definition log.hpp:78
@@ -315,7 +313,7 @@
Definition request.hpp:18
void refresh(bool force=false)
void get_page(const std::string &url, const std::string &key, const std::function< bool(const lib::result< lib::spt::page< T > > &)> &callback)
Definition request.hpp:59
-
void post(const std::string &url, lib::callback< lib::result< void * > > &callback)
Definition request.hpp:110
+
void post(const std::string &url, lib::callback< lib::result< void * > > &callback)
Definition request.hpp:108
void get(const std::string &url, lib::callback< lib::result< T > > &callback)
Definition request.hpp:36
static auto starts_with(const std::string &str, const std::string &start) -> bool
Definition vector.hpp:10
diff --git a/spotify_2api_8hpp_source.html b/spotify_2api_8hpp_source.html index b6e8b7f6..b2fa50cf 100644 --- a/spotify_2api_8hpp_source.html +++ b/spotify_2api_8hpp_source.html @@ -128,8 +128,8 @@
51 void album(const std::string &id,
52 lib::callback<lib::spt::album> &callback);
53
-
54 void album_tracks(const lib::spt::album &album,
-
55 lib::callback<std::vector<lib::spt::track>> &callback);
+
54 void album_tracks(const spt::album &album,
+
55 const paged_callback<spt::track> &callback) const;
56
57 //endregion
58