Rename Request() to Send().
This commit is contained in:
+12
-14
@@ -12,30 +12,28 @@ int main() {
|
||||
webcc::ResponsePtr r;
|
||||
|
||||
try {
|
||||
r = session.Request(webcc::RequestBuilder{}.
|
||||
Get("http://httpbin.org/get").
|
||||
Query("name", "Adam Gu", /*encode*/true).
|
||||
Header("Accept", "application/json").
|
||||
Date()
|
||||
());
|
||||
r = session.Send(webcc::RequestBuilder{}.
|
||||
Get("http://httpbin.org/get").
|
||||
Query("name", "Adam Gu", /*encode*/true).
|
||||
Header("Accept", "application/json").Date()
|
||||
());
|
||||
|
||||
assert(r->status() == webcc::Status::kOK);
|
||||
assert(!r->data().empty());
|
||||
|
||||
r = session.Request(webcc::RequestBuilder{}.
|
||||
Post("http://httpbin.org/post").
|
||||
Body("{'name'='Adam', 'age'=20}").
|
||||
Json().Utf8()
|
||||
());
|
||||
r = session.Send(webcc::RequestBuilder{}.
|
||||
Post("http://httpbin.org/post").
|
||||
Body("{'name'='Adam', 'age'=20}").Json().Utf8()
|
||||
());
|
||||
|
||||
assert(r->status() == webcc::Status::kOK);
|
||||
assert(!r->data().empty());
|
||||
|
||||
#if WEBCC_ENABLE_SSL
|
||||
|
||||
r = session.Request(webcc::RequestBuilder{}.
|
||||
Get("https://httpbin.org/get")
|
||||
());
|
||||
r = session.Send(webcc::RequestBuilder{}.
|
||||
Get("https://httpbin.org/get")
|
||||
());
|
||||
|
||||
assert(r->status() == webcc::Status::kOK);
|
||||
assert(!r->data().empty());
|
||||
|
||||
@@ -26,8 +26,7 @@ int main(int argc, char* argv[]) {
|
||||
webcc::ClientSession session;
|
||||
|
||||
try {
|
||||
auto r = session.Request(webcc::RequestBuilder{}.Get(url)(),
|
||||
true); // Stream the response data to file.
|
||||
auto r = session.Send(webcc::RequestBuilder{}.Get(url)(), true);
|
||||
|
||||
if (auto file_body = r->file_body()) {
|
||||
file_body->Move(path);
|
||||
|
||||
@@ -41,11 +41,10 @@ int main(int argc, char* argv[]) {
|
||||
webcc::ClientSession session;
|
||||
|
||||
try {
|
||||
auto r = session.Request(webcc::RequestBuilder{}.
|
||||
Post(url).
|
||||
FormFile("file", upload_dir / "remember.txt").
|
||||
FormData("json", "{}", "application/json")
|
||||
());
|
||||
auto r = session.Send(webcc::RequestBuilder{}.Post(url).
|
||||
FormFile("file", upload_dir / "remember.txt").
|
||||
FormData("json", "{}", "application/json")
|
||||
());
|
||||
|
||||
std::cout << r->status() << std::endl;
|
||||
|
||||
|
||||
+12
-17
@@ -55,9 +55,8 @@ void PrettyPrintJsonString(const std::string& str) {
|
||||
// List public events.
|
||||
void ListEvents(webcc::ClientSession& session) {
|
||||
try {
|
||||
auto r = session.Request(webcc::RequestBuilder{}.
|
||||
Get(kUrlRoot).Path("events")
|
||||
());
|
||||
auto r = session.Send(webcc::RequestBuilder{}.Get(kUrlRoot).Path("events")
|
||||
());
|
||||
|
||||
PRINT_JSON_STRING(r->data());
|
||||
|
||||
@@ -71,10 +70,9 @@ void ListEvents(webcc::ClientSession& session) {
|
||||
// ListUserFollowers(session, "<user>")
|
||||
void ListUserFollowers(webcc::ClientSession& session, const std::string& user) {
|
||||
try {
|
||||
auto r = session.Request(webcc::RequestBuilder{}.
|
||||
Get(kUrlRoot).Path("users").Path(user).
|
||||
Path("followers")
|
||||
());
|
||||
auto r = session.Send(webcc::RequestBuilder{}.Get(kUrlRoot).
|
||||
Path("users").Path(user).Path("followers")
|
||||
());
|
||||
|
||||
PRINT_JSON_STRING(r->data());
|
||||
|
||||
@@ -90,10 +88,9 @@ void ListAuthUserFollowers(webcc::ClientSession& session,
|
||||
const std::string& login,
|
||||
const std::string& password) {
|
||||
try {
|
||||
auto r = session.Request(webcc::RequestBuilder{}.
|
||||
Get(kUrlRoot).Path("user/followers").
|
||||
AuthBasic(login, password)
|
||||
());
|
||||
auto r = session.Send(webcc::RequestBuilder{}.Get(kUrlRoot).
|
||||
Path("user/followers").AuthBasic(login, password)
|
||||
());
|
||||
|
||||
PRINT_JSON_STRING(r->data());
|
||||
|
||||
@@ -112,12 +109,10 @@ void CreateAuthorization(webcc::ClientSession& session,
|
||||
" 'scopes': ['public_repo', 'repo', 'repo:status', 'user']\n"
|
||||
"}";
|
||||
|
||||
auto r = session.Request(webcc::RequestBuilder{}.
|
||||
Post(kUrlRoot).Path("authorizations").
|
||||
Body(std::move(data)).
|
||||
Json().Utf8().
|
||||
AuthBasic(login, password)
|
||||
());
|
||||
auto r = session.Send(webcc::RequestBuilder{}.Post(kUrlRoot).
|
||||
Path("authorizations").AuthBasic(login, password).
|
||||
Body(std::move(data)).Json().Utf8()
|
||||
());
|
||||
|
||||
std::cout << r->data() << std::endl;
|
||||
|
||||
|
||||
@@ -57,7 +57,7 @@ BookClient::BookClient(const std::string& url, int timeout)
|
||||
|
||||
bool BookClient::ListBooks(std::list<Book>* books) {
|
||||
try {
|
||||
auto r = session_.Request(WEBCC_GET(url_).Path("books")());
|
||||
auto r = session_.Send(WEBCC_GET(url_).Path("books")());
|
||||
|
||||
if (!CheckStatus(r, webcc::Status::kOK)) {
|
||||
// Response HTTP status error.
|
||||
@@ -89,9 +89,9 @@ bool BookClient::CreateBook(const std::string& title, double price,
|
||||
req_json["price"] = price;
|
||||
|
||||
try {
|
||||
auto r = session_.Request(WEBCC_POST(url_).Path("books").
|
||||
Body(JsonToString(req_json))
|
||||
());
|
||||
auto r = session_.Send(WEBCC_POST(url_).Path("books").
|
||||
Body(JsonToString(req_json))
|
||||
());
|
||||
|
||||
if (!CheckStatus(r, webcc::Status::kCreated)) {
|
||||
return false;
|
||||
@@ -110,7 +110,7 @@ bool BookClient::CreateBook(const std::string& title, double price,
|
||||
|
||||
bool BookClient::GetBook(const std::string& id, Book* book) {
|
||||
try {
|
||||
auto r = session_.Request(WEBCC_GET(url_).Path("books").Path(id)());
|
||||
auto r = session_.Send(WEBCC_GET(url_).Path("books").Path(id)());
|
||||
|
||||
if (!CheckStatus(r, webcc::Status::kOK)) {
|
||||
return false;
|
||||
@@ -131,9 +131,9 @@ bool BookClient::UpdateBook(const std::string& id, const std::string& title,
|
||||
json["price"] = price;
|
||||
|
||||
try {
|
||||
auto r = session_.Request(WEBCC_PUT(url_).Path("books").Path(id).
|
||||
Body(JsonToString(json))
|
||||
());
|
||||
auto r = session_.Send(WEBCC_PUT(url_).Path("books").Path(id).
|
||||
Body(JsonToString(json))
|
||||
());
|
||||
|
||||
if (!CheckStatus(r, webcc::Status::kOK)) {
|
||||
return false;
|
||||
@@ -149,7 +149,7 @@ bool BookClient::UpdateBook(const std::string& id, const std::string& title,
|
||||
|
||||
bool BookClient::DeleteBook(const std::string& id) {
|
||||
try {
|
||||
auto r = session_.Request(WEBCC_DELETE(url_).Path("books").Path(id)());
|
||||
auto r = session_.Send(WEBCC_DELETE(url_).Path("books").Path(id)());
|
||||
|
||||
if (!CheckStatus(r, webcc::Status::kOK)) {
|
||||
return false;
|
||||
|
||||
Reference in New Issue
Block a user