mirror of
https://github.com/Sude-/lgogdownloader.git
synced 2024-11-20 11:49:17 +01:00
Move the API constants from GlobalConstants to API as private members
This commit is contained in:
parent
c5d8665593
commit
b73a095f5f
@ -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
|
||||
|
@ -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;
|
||||
|
24
src/api.cpp
24
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;
|
||||
|
Loading…
Reference in New Issue
Block a user