void Scraper::scrape() { bool done = false; unsigned int page = 0; std::string responseBuffer; while (!done) { responseBuffer.clear(); const char *APIBlogUrl = getAPIBlogUrlForUsername("david-meade", page++); makeRequest(APIBlogUrl, &responseBuffer); std::string error; Json resJson = Json::parse(responseBuffer, error)["response"]; Json blogJson = resJson["blog"]; Json::array postsJson = resJson["posts"].array_items(); for(unsigned int i = 0; i < postsJson.size(); i++) { Json::object postObj = postsJson[i].object_items(); } done = postsJson.size() < 20; }; }
std::vector< boost::asio::const_buffer > response_base< Timer >::build_response( const json::array& bayeux_response ) { static const char response_header[] = "HTTP/1.1 200 OK\r\n" "Content-Type: application/json\r\n" "Content-Length: "; response_buffer_ = tools::as_string( bayeux_response.size() ) + "\r\n\r\n"; std::vector< boost::asio::const_buffer > result; result.push_back( boost::asio::buffer( response_header, sizeof response_header -1 ) ); result.push_back( boost::asio::buffer( response_buffer_ ) ); bayeux_response.to_json( result ); return result; }