#pragma once #include "V8Tree/Service.h" #include "Util/AsyncHttpCache.h" namespace RBX { extern const char* const sPages; class Pages : public DescribedNonCreatable { protected: bool finished; shared_ptr currentPage; public: Pages(); virtual void fetchNextChunk(boost::function resumeFunction, boost::function errorFunction) {}; shared_ptr getCurrentPage(); bool isFinished() const; void advanceToNextPageAsync(boost::function resumeFunction, boost::function errorFunction); }; extern const char* const sStandardPages; class StandardPages : public DescribedNonCreatable { weak_ptr weakDM; std::string fieldName; std::string requestUrl; int pageNumber; void processFetchSuccess(std::string response, boost::function resumeFunction, boost::function errorFunction); void processFetchError(std::string error, boost::function errorFunction); void processFetch(std::string* response, std::exception* exception, boost::function resumeFunction, boost::function errorFunction); public: StandardPages(weak_ptr weakDM, const std::string& requestUrl, const std::string& fieldName); virtual void fetchNextChunk(boost::function resumeFunction, boost::function errorFunction); }; extern const char* const sFriendPages; class FriendPages : public DescribedNonCreatable { weak_ptr weakDM; std::string fieldName; std::string requestUrl; shared_ptr nextPage; int pageNumber; bool firstTime; void processFetchSuccess(std::string response, boost::function resumeFunction, boost::function errorFunction); void processFetchError(std::string error, boost::function errorFunction); void processFetch(std::string* response, std::exception* exception, boost::function resumeFunction, boost::function errorFunction); public: FriendPages(weak_ptr weakDM, const std::string& requestUrl); virtual void fetchNextChunk(boost::function resumeFunction, boost::function errorFunction); }; extern const char *const sLuaWebService; #define LUA_WEB_SERVICE_STANDARD_PRIORITY 50 // This service is used to make web queries. It is frequently used by // function calls originating in Lua, but is not restricted to use // by Lua class LuaWebService : public DescribedNonCreatable , public Service { private: typedef DescribedNonCreatable Super; struct CachedLuaWebServiceInfo { Reflection::Variant value; CachedLuaWebServiceInfo() {} CachedLuaWebServiceInfo(shared_ptr data, shared_ptr filename); }; struct CachedRawLuaWebServiceInfo { std::string value; CachedRawLuaWebServiceInfo() {} CachedRawLuaWebServiceInfo(shared_ptr data, shared_ptr filename); }; boost::shared_ptr > webCache; boost::shared_ptr > webRawCache; bool checkApiAccess; Time timeToRecheckApiAccess; boost::optional apiAccess; template bool checkCache(const std::string& url, boost::function resumeFunction, boost::function errorFunction); template static bool TryDispatchRequest(AsyncHttpCache* webCache, const std::string& url, boost::function resumeFunction, boost::function errorFunction); template static bool TryRawDispatchRequest(AsyncHttpCache* webCache, const std::string& url, boost::function resumeFunction, boost::function errorFunction); template static void Callback(boost::weak_ptr weakLuaWebService, AsyncHttpQueue::RequestResult requestResult, std::string url, boost::function resumeFunction, boost::function errorFunction); static void RawCallback(boost::weak_ptr weakLuaWebService, AsyncHttpQueue::RequestResult requestResult, std::string url, boost::function resumeFunction, boost::function errorFunction); public: LuaWebService(); void asyncRequest(const std::string& url, float priority, boost::function)> resumeFunction, boost::function errorFunction); void asyncRequest(const std::string& url, float priority, boost::function)> resumeFunction, boost::function errorFunction); void asyncRequest(const std::string& url, float priority, boost::function resumeFunction, boost::function errorFunction); void asyncRequest(const std::string& url, float priority, boost::function resumeFunction, boost::function errorFunction); void asyncRequest(const std::string& url, float priority, boost::function resumeFunction, boost::function errorFunction); //Skips the caches void asyncRequestNoCache(const std::string& url, float priority, boost::function)> callback, AsyncHttpQueue::ResultJob resultJob); // will block until api access request has returned bool isApiAccessEnabled(); void setCheckApiAccessBecauseInStudio(); static bool parseWebJSONResponseHelper(std::string* response, std::exception* exception, shared_ptr& result, std::string& status); }; }