Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include "cpprest/http_client.h"
- #include "cpprest/filestream.h"
- #include "cpprest/json.h"
- #include "string"
- using namespace utility;
- using namespace web;
- using namespace web::http;
- using namespace web::http::client;
- using namespace concurrency::streams;
- using namespace web::json;
- pplx::task<void> WoWRealmCheck(std::string& realm) {
- uri_builder uribuild(U"http://us.battle.net");
- uribuild.append_path(U"/api/wow/realm/status?locale=en_US");
- auto uri = uribuild.to_uri();
- std::cout << uri.to_string() << std::endl;
- http_client client(uri);
- return client.request(methods::GET)
- .then([](http_response response) -> pplx::task<json::value>
- {
- std::cout << "Received response code: " << response.status_code() << std::endl;
- if (response.status_code() == status_codes::OK)
- return response.extract_json();
- else
- return pplx::task_from_result(web::json::value());
- })
- .then([realm](pplx::task<web::json::value> jsonResponse)
- {
- try
- {
- bool found = false;
- const web::json::value v = jsonResponse.get();
- const web::json::value realms = v.at(U"realms");
- for (size_t i = 0; i < realms.size(); i++)
- {
- if (realm.compare(realms.at(i).at(U"name").as_string()) == 0) {
- found = true;
- std::cout << "------------------------------------------------------\n";
- std::cout << realms.at(i).at(U"name").as_string() << std::endl
- << "Status: " << realms.at(i).at(U"status").as_bool() << std::endl
- << "Population: " << realms.at(i).at(U"population").as_string() << std::endl
- << "-------------------------------------------------------\n";
- }
- }
- if (found == false) std::cout << "Realm not found perhaps try again? \n";
- }
- catch (const web::http::http_exception& e)
- {
- std::cout << e.what();
- }
- });
- };
- int main() {
- while (true) {
- char input[30];
- std::string realmName;
- std::cout << "Enter realm name: ";
- std::cin.getline(input, 30);
- realmName = input;
- std::cout << "Checking current status of realm...\n";
- WoWRealmCheck(realmName).wait();
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement