diff options
| author | Simon Robertshaw <simon@hardwired.org.uk> | 2012-08-04 19:55:59 (GMT) |
|---|---|---|
| committer | Simon Robertshaw <simon@hardwired.org.uk> | 2012-08-04 19:55:59 (GMT) |
| commit | 5a2da01a5b1d59bae3d1f00132230835e6803301 (patch) | |
| tree | a580fe32daa8bac4acb002d32f51552a00c30e72 /src/client/Client.cpp | |
| parent | 82d2bcc7c2fe7ae5ba40b915ce22422a36d68639 (diff) | |
| download | powder-5a2da01a5b1d59bae3d1f00132230835e6803301.zip powder-5a2da01a5b1d59bae3d1f00132230835e6803301.tar.gz | |
Tags, fixes #55
Diffstat (limited to 'src/client/Client.cpp')
| -rw-r--r-- | src/client/Client.cpp | 49 |
1 files changed, 49 insertions, 0 deletions
diff --git a/src/client/Client.cpp b/src/client/Client.cpp index 2684689..5d1e439 100644 --- a/src/client/Client.cpp +++ b/src/client/Client.cpp @@ -1262,6 +1262,55 @@ std::vector<SaveComment*> * Client::GetComments(int saveID, int start, int count return commentArray; } +std::vector<std::pair<std::string, int> > * Client::GetTags(int start, int count, string query, int & resultCount) +{ + lastError = ""; + resultCount = 0; + std::vector<std::pair<std::string, int> > * tagArray = new std::vector<std::pair<std::string, int> >(); + std::stringstream urlStream; + char * data; + int dataStatus, dataLength; + urlStream << "http://" << SERVER << "/Browse/Tags.json?Start=" << start << "&Count=" << count; + if(query.length()) + { + urlStream << "&Search_Query="; + if(query.length()) + urlStream << URLEscape(query); + } + + data = http_simple_get((char *)urlStream.str().c_str(), &dataStatus, &dataLength); + if(dataStatus == 200 && data) + { + try + { + std::istringstream dataStream(data); + json::Object objDocument; + json::Reader::Read(objDocument, dataStream); + + json::Number tempCount = objDocument["TagTotal"]; + resultCount = tempCount.Value(); + json::Array tagsArray = objDocument["Tags"]; + for(int j = 0; j < tagsArray.Size(); j++) + { + json::Number tagCount = tagsArray[j]["Count"]; + json::String tag = tagsArray[j]["Tag"]; + tagArray->push_back(std::pair<std::string, int>(tag.Value(), tagCount.Value())); + } + } + catch (json::Exception &e) + { + lastError = "Could not read response"; + } + } + else + { + lastError = http_ret_text(dataStatus); + } + if(data) + free(data); + return tagArray; +} + std::vector<SaveInfo*> * Client::SearchSaves(int start, int count, string query, string sort, std::string category, int & resultCount) { lastError = ""; |
