Пример #1
0
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;
}
Пример #2
0
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;
}
Пример #3
0
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;
}
Пример #4
0
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;
}