From b73a095f5f791cc55af03a718478d433a13e509c Mon Sep 17 00:00:00 2001 From: Sude Date: Fri, 2 Aug 2013 16:16:53 +0300 Subject: [PATCH] Move the API constants from GlobalConstants to API as private members --- include/api.h | 7 +++++++ include/globalconstants.h | 7 ------- src/api.cpp | 24 ++++++++++++------------ 3 files changed, 19 insertions(+), 19 deletions(-) diff --git a/include/api.h b/include/api.h index 74548aa..896e2dd 100644 --- a/include/api.h +++ b/include/api.h @@ -100,6 +100,13 @@ class API void setError(const std::string& err); bool error; std::string error_message; + + // API constants + const std::string CONSUMER_KEY = "1f444d14ea8ec776585524a33f6ecc1c413ed4a5"; + const std::string CONSUMER_SECRET = "20d175147f9db9a10fc0584aa128090217b9cf88"; + const int OAUTH_VERIFIER_LENGTH = 14; + const int OAUTH_TOKEN_LENGTH = 11; + const int OAUTH_SECRET_LENGTH = 18; }; #endif // API_H diff --git a/include/globalconstants.h b/include/globalconstants.h index 198a342..adf3f56 100644 --- a/include/globalconstants.h +++ b/include/globalconstants.h @@ -12,13 +12,6 @@ namespace GlobalConstants { - // API constants - const std::string CONSUMER_KEY = "1f444d14ea8ec776585524a33f6ecc1c413ed4a5"; - const std::string CONSUMER_SECRET = "20d175147f9db9a10fc0584aa128090217b9cf88"; - const int OAUTH_VERIFIER_LENGTH = 14; - const int OAUTH_TOKEN_LENGTH = 11; - const int OAUTH_SECRET_LENGTH = 18; - // Language constants const unsigned int LANGUAGE_EN = 1; const unsigned int LANGUAGE_DE = 2; diff --git a/src/api.cpp b/src/api.cpp index 8a14a3e..684fc4d 100644 --- a/src/api.cpp +++ b/src/api.cpp @@ -118,16 +118,16 @@ int API::login(const std::string& email, const std::string& password) std::string token, secret; // Get temporary request token - url = oauth_sign_url2(this->config.oauth_get_temp_token.c_str(), NULL, OA_HMAC, NULL, GlobalConstants::CONSUMER_KEY.c_str(), GlobalConstants::CONSUMER_SECRET.c_str(), NULL /* token */, NULL /* secret */); + url = oauth_sign_url2(this->config.oauth_get_temp_token.c_str(), NULL, OA_HMAC, NULL, CONSUMER_KEY.c_str(), CONSUMER_SECRET.c_str(), NULL /* token */, NULL /* secret */); std::string request_token_resp = this->getResponse(url); char **rv = NULL; int rc = oauth_split_url_parameters(request_token_resp.c_str(), &rv); qsort(rv, rc, sizeof(char *), oauth_cmpstringp); - if (rc == 3 && !strncmp(rv[1], "oauth_token=", GlobalConstants::OAUTH_TOKEN_LENGTH) && !strncmp(rv[2], "oauth_token_secret=", GlobalConstants::OAUTH_SECRET_LENGTH)) { - token = rv[1]+GlobalConstants::OAUTH_TOKEN_LENGTH+1; - secret = rv[2]+GlobalConstants::OAUTH_SECRET_LENGTH+1; + if (rc == 3 && !strncmp(rv[1], "oauth_token=", OAUTH_TOKEN_LENGTH) && !strncmp(rv[2], "oauth_token_secret=", OAUTH_SECRET_LENGTH)) { + token = rv[1]+OAUTH_TOKEN_LENGTH+1; + secret = rv[2]+OAUTH_SECRET_LENGTH+1; rv = NULL; } else @@ -137,14 +137,14 @@ int API::login(const std::string& email, const std::string& password) // Authorize temporary token and get verifier url = this->config.oauth_authorize_temp_token + "?username=" + oauth_url_escape(email.c_str()) + "&password=" + oauth_url_escape(password.c_str()); - url = oauth_sign_url2(url.c_str(), NULL, OA_HMAC, NULL, GlobalConstants::CONSUMER_KEY.c_str(), GlobalConstants::CONSUMER_SECRET.c_str(), token.c_str(), secret.c_str()); + url = oauth_sign_url2(url.c_str(), NULL, OA_HMAC, NULL, CONSUMER_KEY.c_str(), CONSUMER_SECRET.c_str(), token.c_str(), secret.c_str()); std::string authorize_resp = this->getResponse(url); std::string verifier; rc = oauth_split_url_parameters(authorize_resp.c_str(), &rv); qsort(rv, rc, sizeof(char *), oauth_cmpstringp); - if (rc == 2 && !strncmp(rv[1], "oauth_verifier=", GlobalConstants::OAUTH_VERIFIER_LENGTH)) { - verifier = rv[1]+GlobalConstants::OAUTH_VERIFIER_LENGTH+1; + if (rc == 2 && !strncmp(rv[1], "oauth_verifier=", OAUTH_VERIFIER_LENGTH)) { + verifier = rv[1]+OAUTH_VERIFIER_LENGTH+1; rv = NULL; } else @@ -154,14 +154,14 @@ int API::login(const std::string& email, const std::string& password) // Get final token and secret url = this->config.oauth_get_token + "?oauth_verifier=" + verifier; - url = oauth_sign_url2(url.c_str(), NULL, OA_HMAC, NULL, GlobalConstants::CONSUMER_KEY.c_str(), GlobalConstants::CONSUMER_SECRET.c_str(), token.c_str(), secret.c_str()); + url = oauth_sign_url2(url.c_str(), NULL, OA_HMAC, NULL, CONSUMER_KEY.c_str(), CONSUMER_SECRET.c_str(), token.c_str(), secret.c_str()); std::string token_resp = this->getResponse(url); rc = oauth_split_url_parameters(token_resp.c_str(), &rv); qsort(rv, rc, sizeof(char *), oauth_cmpstringp); - if (rc == 2 && !strncmp(rv[0], "oauth_token=", GlobalConstants::OAUTH_TOKEN_LENGTH) && !strncmp(rv[1], "oauth_token_secret=", GlobalConstants::OAUTH_SECRET_LENGTH)) { - this->config.oauth_token = rv[0]+GlobalConstants::OAUTH_TOKEN_LENGTH+1; - this->config.oauth_secret = rv[1]+GlobalConstants::OAUTH_SECRET_LENGTH+1; + if (rc == 2 && !strncmp(rv[0], "oauth_token=", OAUTH_TOKEN_LENGTH) && !strncmp(rv[1], "oauth_token_secret=", OAUTH_SECRET_LENGTH)) { + this->config.oauth_token = rv[0]+OAUTH_TOKEN_LENGTH+1; + this->config.oauth_secret = rv[1]+OAUTH_SECRET_LENGTH+1; free(rv); res = 1; } @@ -257,7 +257,7 @@ std::string API::getResponseOAuth(const std::string& url) #ifdef DEBUG std::cerr << "DEBUG INFO (API::getResponseOAuth)" << std::endl << "URL: " << url << std::endl; #endif - std::string url_oauth = oauth_sign_url2(url.c_str(), NULL, OA_HMAC, NULL, GlobalConstants::CONSUMER_KEY.c_str(), GlobalConstants::CONSUMER_SECRET.c_str(), this->config.oauth_token.c_str(), this->config.oauth_secret.c_str()); + std::string url_oauth = oauth_sign_url2(url.c_str(), NULL, OA_HMAC, NULL, CONSUMER_KEY.c_str(), CONSUMER_SECRET.c_str(), this->config.oauth_token.c_str(), this->config.oauth_secret.c_str()); std::string response = this->getResponse(url_oauth); return response;