summaryrefslogtreecommitdiff
path: root/src/client/Client.cpp
diff options
context:
space:
mode:
Diffstat (limited to 'src/client/Client.cpp')
-rw-r--r--src/client/Client.cpp46
1 files changed, 46 insertions, 0 deletions
diff --git a/src/client/Client.cpp b/src/client/Client.cpp
index ce7c9e6..5054dc4 100644
--- a/src/client/Client.cpp
+++ b/src/client/Client.cpp
@@ -422,6 +422,52 @@ Thumbnail * Client::GetPreview(int saveID, int saveDate)
}
}
+std::vector<Comment*> * Client::GetComments(int saveID, int start, int count)
+{
+ lastError = "";
+ std::vector<Comment*> * commentArray = new std::vector<Comment*>();
+
+ std::stringstream urlStream;
+ char * data;
+ int dataStatus, dataLength;
+ urlStream << "http://" << SERVER << "/Browse/View.json?ID=" << saveID << "&Mode=Comments&Start=" << start << "&Count=" << count;
+ data = http_simple_get((char *)urlStream.str().c_str(), &dataStatus, &dataLength);
+ if(dataStatus == 200 && data)
+ {
+ try
+ {
+ std::istringstream dataStream(data);
+ json::Array commentsArray;
+ json::Reader::Read(commentsArray, dataStream);
+
+ for(int j = 0; j < commentsArray.Size(); j++)
+ {
+ json::Number tempUserID = commentsArray[j]["UserID"];
+ json::String tempUsername = commentsArray[j]["Username"];
+ json::String tempComment = commentsArray[j]["Text"];
+ commentArray->push_back(
+ new Comment(
+ tempUserID.Value(),
+ tempUsername.Value(),
+ tempComment.Value()
+ )
+ );
+ }
+ }
+ catch (json::Exception &e)
+ {
+ lastError = "Could not read response";
+ }
+ }
+ else
+ {
+ lastError = http_ret_text(dataStatus);
+ }
+ if(data)
+ free(data);
+ return commentArray;
+}
+
std::vector<Save*> * Client::SearchSaves(int start, int count, string query, string sort, int & resultCount)
{
lastError = "";