void Campfire::ListenWorker() { void******* m_pRest = NULL;//This is a thread; so don't use m_pRest! std::string strAddress = GetStreamingURL(m_nRoomNum, m_bUseSSL); while( !m_bExit ) { RestClientFactory factory; RestClient* pClient = factory.SetUsernamePassword(m_strAuthCode, "x").SetVerbosity(false).CreateRestClient(); pClient->SetCallback(Campfire::listen_callback); pClient->SetUserData((void*)this); RestClient::response r = pClient->get(strAddress); cout << "Finished Listening!!!" << r.code << endl; SAFE_DELETE(pClient);//Done with this so no need to revert the callback/userdata if( !m_bExit ) { #ifdef _WIN32 Sleep(200); #else usleep(200*1000); #endif } } }
void RestClientTests::testGet() { RestClient client; QJsonDocument* jsonResponse = client.getJson(QUrl(QString("http://localhost:5000/api/colors"))); QCOMPARE(client.statusCode(), 200); QJsonObject jsonRootObject = jsonResponse->object(); QJsonValue value = jsonRootObject.value("data"); QJsonArray jsonArray = value.toArray(); QCOMPARE(jsonArray.count(), 6); foreach (const QJsonValue& current, jsonArray) { QVERIFY(!current.toObject().value("name").toString().isEmpty()); QVERIFY(!current.toObject().value("value").toString().isEmpty()); }
void getColors() { qDebug() << "########## GET REQUEST TEST ##########"; qDebug() << "########## GET LIST ##########"; RestClient client; QJsonDocument* jsonResponse = client.getJson(QUrl(QString("http://localhost:5000/api/colors"))); qDebug() << "Response: " << jsonResponse->toJson(); QJsonObject jsonRootObject = jsonResponse->object(); QJsonValue value = jsonRootObject.value("data"); QJsonArray jsonArray = value.toArray(); foreach (const QJsonValue& current, jsonArray) { qDebug() << "Name: " << current.toObject().value("name").toString(); qDebug() << "Value: " << current.toObject().value("value").toString(); }
const char* SwitchScheduler::getAstronomyDataResponse() { Uri apiUri = Uri::Parse(configuration->astronomyApiUrl); RestClient client = RestClient(apiUri.Host.c_str()); String response = ""; int statusCode = client.get(apiUri.Path.c_str(), &response); if (statusCode == 200) { DEBUG_PRINT("Successfully retrieved JSON response\n"); return response.c_str(); } else { DEBUG_PRINT("Failed to retrieve sunset data with status: "); DEBUG_PRINT(statusCode); DEBUG_PRINT("\n"); return ""; } }
* Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. */ #include "catch.hpp" #include "hippomocks.h" #include "rest/rest_client.h" TEST_CASE("RestClient", "[rest][client][server]") { SECTION("URI not matching: short") { MockRepository mocks; RestState * restState = mocks.Mock<RestState>(); mocks.NeverCall(restState, RestState::getClientJson); RestClient client("/testclient", *restState); RestRequest request(RestRequestType::RRT_GET, "/testclien", "1.0"); REQUIRE(client.handleRequest(Host::ALL_INTERFACES4, request, std::map<std::string, std::string>(), std::vector<char>()) == std::vector<char>()); } SECTION("URI not matching: long") { MockRepository mocks; RestState * restState = mocks.Mock<RestState>(); mocks.NeverCall(restState, RestState::getClientJson); RestClient client("/testclient", *restState); RestRequest request(RestRequestType::RRT_GET, "/testclient2", "1.0"); REQUIRE(client.handleRequest(Host::ALL_INTERFACES4, request, std::map<std::string, std::string>(), std::vector<char>()) == std::vector<char>()); }