You cannot select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
48 lines
1.0 KiB
C++
48 lines
1.0 KiB
C++
#ifndef BOOK_CLIENT_H_
|
|
#define BOOK_CLIENT_H_
|
|
|
|
#include <list>
|
|
#include <string>
|
|
|
|
#include <json/json.h>
|
|
|
|
#include "webcc/client_session.h"
|
|
#include "webcc/fs.h"
|
|
|
|
#include "book.h"
|
|
|
|
class BookClient {
|
|
public:
|
|
explicit BookClient(const std::string& url, int timeout = 0);
|
|
|
|
~BookClient() = default;
|
|
|
|
bool Query(std::list<Book>* books);
|
|
|
|
bool Create(const std::string& title, double price, std::string* id);
|
|
|
|
bool Get(const std::string& id, Book* book);
|
|
|
|
bool Set(const std::string& id, const std::string& title, double price);
|
|
|
|
bool Delete(const std::string& id);
|
|
|
|
// Get photo, save to the given path.
|
|
bool GetPhoto(const std::string& id, const webcc::fs::path& path);
|
|
|
|
// Set photo using the file of the given path.
|
|
bool SetPhoto(const std::string& id, const webcc::fs::path& path);
|
|
|
|
private:
|
|
bool CheckPhoto(const webcc::fs::path& photo);
|
|
|
|
// Check HTTP response status.
|
|
bool CheckStatus(webcc::ResponsePtr response, int expected_status);
|
|
|
|
private:
|
|
std::string url_;
|
|
webcc::ClientSession session_;
|
|
};
|
|
|
|
#endif // BOOK_CLIENT_H_
|