Advertisement
GrandaThePanda

WindowsVersion

Aug 8th, 2014
309
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 2.16 KB | None | 0 0
  1. #include <cpprest/http_client.h>
  2. #include <cpprest/filestream.h>
  3. #include <cpprest/json.h>
  4. #include <string>
  5. #include <cwchar>
  6. #include <vector>
  7.  
  8. using namespace utility;
  9. using namespace web;
  10. using namespace web::http;
  11. using namespace web::http::client;
  12. using namespace concurrency::streams;
  13. using namespace web::json;
  14.  
  15.  
  16.  
  17. pplx::task<void> WoWRealmCheck(std::wstring& realm) {
  18.     uri_builder uribuild(L"http://us.battle.net");
  19.     uribuild.append_path(L"/api/wow/realm/status?locale=en_US");
  20.     auto uri = uribuild.to_uri();
  21.     std::wcout << uri.to_string() << std::endl;
  22.     http_client client(uri);
  23.     return client.request(methods::GET)
  24.         .then([](http_response response) -> pplx::task<json::value>
  25.     {
  26.         std::wcout << "Received response code: " << response.status_code() << std::endl;
  27.         if (response.status_code() == status_codes::OK)
  28.             return response.extract_json();
  29.         else
  30.             return pplx::task_from_result(web::json::value());
  31.  
  32.     })
  33.         .then([realm](pplx::task<web::json::value> jsonResponse)
  34.     {
  35.         try
  36.         {
  37.             bool found = false;
  38.             const web::json::value v = jsonResponse.get();
  39.             std::wcout << v.has_field(L"realms") << std::endl;
  40.             const web::json::value realms = v.at(L"realms");
  41.             for (size_t i = 0; i < realms.size(); i++)
  42.             {
  43.                 if (realm.compare(realms.at(i).at(L"name").as_string()) == 0) {
  44.                     found = true;
  45.                     std::wcout << "------------------------------------------------------\n";
  46.                     std::wcout << realms.at(i).at(L"name").as_string() << std::endl
  47.                         << "Status: " << realms.at(i).at(L"status").as_bool() << std::endl
  48.                         << "Population: " << realms.at(i).at(L"population").as_string() << std::endl
  49.                         << "-------------------------------------------------------\n";
  50.                 }
  51.             }
  52.             if (found == false) std::wcout << "Realm not found perhaps try again? \n";
  53.  
  54.            
  55.         }
  56.         catch (const web::http::http_exception& e)
  57.         {
  58.             std::wcout << e.what();
  59.         }
  60.     });
  61. };
  62.  
  63. int main() {
  64.     while (true) {
  65.         wchar_t input[30];
  66.         std::wstring realmName;
  67.         std::wcout << "Enter realm name: ";
  68.         std::wcin.getline(input, 30);
  69.         realmName = input;
  70.         std::wcout << "Checking current status of realm...\n";
  71.         WoWRealmCheck(realmName).wait();
  72.     }
  73.  
  74. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement