diff options
author | Merov Linden <merov@lindenlab.com> | 2014-05-05 15:13:48 -0700 |
---|---|---|
committer | Merov Linden <merov@lindenlab.com> | 2014-05-05 15:13:48 -0700 |
commit | 1a837c5719fa8dded91561a97839d2ed28e87553 (patch) | |
tree | 5f805b02e95e4a4b24c0711257afc9136a2a01a0 /indra/newview/llmarketplacefunctions.cpp | |
parent | 9c5d3de013921999b2dfb4994de91ab10308fd6a (diff) |
DD-22 : WIP : Completed GET and POST listings routes. Refactored the marketplace data code a bit as a result
Diffstat (limited to 'indra/newview/llmarketplacefunctions.cpp')
-rwxr-xr-x | indra/newview/llmarketplacefunctions.cpp | 97 |
1 files changed, 50 insertions, 47 deletions
diff --git a/indra/newview/llmarketplacefunctions.cpp b/indra/newview/llmarketplacefunctions.cpp index d71f328a28..64df5a8396 100755 --- a/indra/newview/llmarketplacefunctions.cpp +++ b/indra/newview/llmarketplacefunctions.cpp @@ -170,13 +170,24 @@ public: return; } - // Extract the info from the Json string : just get the id for the first element in the list - const int id = root["listings"][0u]["id"].asInt(); - //Json::Value listings = root["listings"]; - llinfos << "Merov : Parsed the json, string = " << body << llendl; - llinfos << "Merov : Parsed the json, id = " << id << llendl; + // Extract the info from the Json string + Json::ValueIterator it = root["listings"].begin(); + + while (it != root["listings"].end()) + { + Json::Value listing = *it; + + int listing_id = listing["id"].asInt(); + bool is_listed = listing["is_listed"].asBool(); + std::string folder_uuid_string = listing["inventory_info"]["listing_folder_id"].asString(); + std::string version_uuid_string = listing["inventory_info"]["version_folder_id"].asString(); + + LLUUID folder_id(folder_uuid_string); + LLUUID version_id(version_uuid_string); + LLMarketplaceData::instance().addListing(folder_id,listing_id,version_id,is_listed); + it++; + } } - }; class LLSLMCreateListingsResponder : public LLHTTPClient::Responder @@ -211,35 +222,23 @@ public: return; } - // Extract the info from the Json string : just get the id for the first element in the list - const int id = root["listings"][0u]["id"].asInt(); - //Json::Value listings = root["listings"]; - llinfos << "Merov : Parsed the json, string = " << body << llendl; - llinfos << "Merov : Parsed the json, id = " << id << llendl; - } - - virtual void completed(U32 status, const std::string& reason, const LLSD& content) - { - if (isGoodStatus(status)) - { - llinfos << "Merov : completed successful, status = " << status << ", reason = " << reason << ", content = " << content << llendl; - } - else - { - llinfos << "Merov : completed with error, status = " << status << ", reason = " << reason << ", content = " << content << llendl; - } - } - - void completedHeader(U32 status, const std::string& reason, const LLSD& content) - { - if (isGoodStatus(status)) - { - llinfos << "Merov : completed header successful, status = " << status << ", reason = " << reason << ", content = " << content << llendl; - } - else - { - llinfos << "Merov : completed header with error, status = " << status << ", reason = " << reason << ", content = " << content << llendl; - } + // Extract the info from the Json string + Json::ValueIterator it = root["listings"].begin(); + + while (it != root["listings"].end()) + { + Json::Value listing = *it; + + int listing_id = listing["id"].asInt(); + bool is_listed = listing["is_listed"].asBool(); + std::string folder_uuid_string = listing["inventory_info"]["listing_folder_id"].asString(); + std::string version_uuid_string = listing["inventory_info"]["version_folder_id"].asString(); + + LLUUID folder_id(folder_uuid_string); + LLUUID version_id(version_uuid_string); + LLMarketplaceData::instance().addListing(folder_id,listing_id,version_id,is_listed); + it++; + } } }; // SLM Responders End @@ -795,7 +794,7 @@ void LLMarketplaceData::getSLMListings() LLHTTPClient::get(getSLMConnectURL("/listings"), new LLSLMListingsResponder(), LLSD()); } -void LLMarketplaceData::postSLMListing(const LLUUID& folder_id) +void LLMarketplaceData::createSLMListing(const LLUUID& folder_id) { LLSD headers = LLSD::emptyMap(); headers["Accept"] = "application/json"; @@ -811,8 +810,6 @@ void LLMarketplaceData::postSLMListing(const LLUUID& folder_id) std::string json_str = writer.write(root); - llinfos << "Merov : postSLMListing, json body = " << json_str << ", size = " << json_str.size() << llendl; - // postRaw() takes ownership of the buffer and releases it later. size_t size = json_str.size(); U8 *data = new U8[size]; @@ -851,23 +848,29 @@ void LLMarketplaceData::setSLMStatus(U32 status) } // Creation / Deletion -bool LLMarketplaceData::addListing(const LLUUID& folder_id) +bool LLMarketplaceData::createListing(const LLUUID& folder_id) { if (isListed(folder_id)) { // Listing already exists -> exit with error return false; } - mMarketplaceItems[folder_id] = LLMarketplaceTuple(folder_id); - - // Post the listing to SLM - postSLMListing(folder_id); - // *TODO : Get the listing id from SLM - // For the moment, we use that wonky test ID generator... - S32 listing_id = LLMarketplaceData::instance().getTestMarketplaceID(); + // Post the listing creation request to SLM + createSLMListing(folder_id); - setListingID(folder_id,listing_id); + return true; +} + +bool LLMarketplaceData::addListing(const LLUUID& folder_id, S32 listing_id, const LLUUID& version_id, bool is_listed) +{ + if (isListed(folder_id)) + { + // Listing already exists -> exit with error + return false; + } + mMarketplaceItems[folder_id] = LLMarketplaceTuple(folder_id, listing_id, version_id, is_listed); + update_marketplace_category(folder_id); gInventory.notifyObservers(); return true; |