vector<Category*>* Session::GetCategories(string configId) { AuthRequest* authRequest = new AuthRequest(consumerKey, consumerSecret, configId, applicationName); QueryMethod method = GET; string url = host + "/categories." + format; cout << endl << "url: " << url << endl; int status = authRequest->authWebRequest(url, method); vector<Category*>* result = new vector<Category*>(); if (status <= 202 && "" != authRequest->GetReceivedData()) { Stub_Categories* stub = new Stub_Categories(); if (format == "xml") { (static_cast<XmlSerializer*>(serializer))->Deserialize(authRequest->GetReceivedData(), stub); } else { (static_cast<JsonSerializer*>(serializer))->Deserialize(authRequest->GetReceivedData(), stub); } result = stub->GetCategories(); delete stub; } HandleRequest(method, url, ""); HandleConfigurationResponse(status, authRequest); delete authRequest; return result; }
vector<string>* Session::GetBlacklist(string configId) { AuthRequest* authRequest = new AuthRequest(consumerKey, consumerSecret, configId, applicationName); QueryMethod method = GET; string url = host + "/blacklist." + format; cout << endl << "url: " << url << endl; int status = authRequest->authWebRequest(url, method); vector<string>* result = new vector<string>(); if (status <= 202 && "" != authRequest->GetReceivedData()) { Stub_Blacklist* stub = new Stub_Blacklist(); if (format == "xml") { (static_cast<XmlSerializer*>(serializer))->Deserialize(authRequest->GetReceivedData(), stub); } else { (static_cast<JsonSerializer*>(serializer))->Deserialize(authRequest->GetReceivedData(), stub); } result = stub->GetBlacklistItems(); // @TODO don't forget that items are stored in stub, so if // we delete items in stub's destructor - all items from result // will be removed too. // maybe we should use smart pointer? delete stub; } HandleRequest(method, url, ""); HandleConfigurationResponse(status, authRequest); delete authRequest; return result; }
int Session::QueueCollection(Collection* collection, string configId) { AuthRequest* authRequest = new AuthRequest(consumerKey, consumerSecret, configId, applicationName); QueryMethod method = POST; string url = host + "/collection." + format; cout << endl << "url: " << url << endl; string body = ""; if (format == "xml") { body = (static_cast<XmlSerializer*>(serializer))->Serialize(collection); } else { body = (static_cast<JsonSerializer*>(serializer))->Serialize(collection); } int result = authRequest->authWebRequest(url, method, body); HandleCollAutoResponse(result, authRequest); HandleRequest(method, url, body); delete authRequest; return result; }
int Session::UpdateItems(string path, UpdateProxy<T>* proxy, string configId) { AuthRequest* authRequest = new AuthRequest(consumerKey, consumerSecret, configId, applicationName); QueryMethod method = POST; string url = host + "/" + path + "." + format; cout << endl << "url: " << url << endl; string body = ""; if (format == "xml") { body = (static_cast<XmlSerializer*>(serializer))->Serialize(proxy); } else { body = (static_cast<JsonSerializer*>(serializer))->Serialize(proxy); } int result = authRequest->authWebRequest(url, method, body); HandleRequest(POST, url, body); HandleConfigurationResponse(result, authRequest); delete authRequest; return result; }
CollAnalyticData* Session::GetCollection(string collectionId, string configId) { AuthRequest* authRequest = new AuthRequest(consumerKey, consumerSecret, configId, applicationName); QueryMethod method = GET; string url = host + "/collection/" + collectionId + "." + format; cout << endl << "url: " << url << endl; int status = authRequest->authWebRequest(url, method); CollAnalyticData* result = new CollAnalyticData(); if (status <= 202 && "" != authRequest->GetReceivedData()) { if (format == "xml") { (static_cast<XmlSerializer*>(serializer))->Deserialize(authRequest->GetReceivedData(), result); } else { (static_cast<JsonSerializer*>(serializer))->Deserialize(authRequest->GetReceivedData(), result); } } HandleRequest(method, url, ""); HandleConfigurationResponse(status, authRequest); delete authRequest; return result; }
Subscription* Session::VerifySubscription() { AuthRequest* authRequest = new AuthRequest(consumerKey, consumerSecret, "", applicationName); QueryMethod method = GET; string url = host + "/subscription." + format; cout << endl << "url: " << url << endl; int status = authRequest->authWebRequest(url, method); Subscription* result = new Subscription(); if (status <= 202 && "" != authRequest->GetReceivedData()) { if (format == "xml") { (static_cast<XmlSerializer*>(serializer))->Deserialize(authRequest->GetReceivedData(), result); } else { (static_cast<JsonSerializer*>(serializer))->Deserialize(authRequest->GetReceivedData(), result); } } HandleRequest(method, url, ""); HandleConfigurationResponse(status, authRequest); delete authRequest; return result; }
int Session::QueueBatch(vector<Document*>* documents, string configId) { AuthRequest* authRequest = new AuthRequest(consumerKey, consumerSecret, configId, applicationName); QueryMethod method = POST; string url = host + "/document/batch." + format; cout << endl << "url: " << url << endl; Stub_Tasks* documentsStub = new Stub_Tasks(documents); string body = ""; if (format == "xml") { body = (static_cast<XmlSerializer*>(serializer))->Serialize(documentsStub); } else { body = (static_cast<JsonSerializer*>(serializer))->Serialize(documentsStub); } delete documentsStub; int result = authRequest->authWebRequest(url, method, body); HandleDocAutoResponse(result, authRequest); HandleRequest(method, url, body); delete authRequest; return result; }