summaryrefslogtreecommitdiffabout
authorMichael Krelin <hacker@klever.net>2008-03-07 19:53:46 (UTC)
committer Michael Krelin <hacker@klever.net>2008-03-07 19:53:46 (UTC)
commitf953b073abbf9e58e5b2a46c6ddf65f57dec1fad (patch) (side-by-side diff)
treecd8bf29efc2dc59070c013a69a7c6d70f63322b4
parent0d19bbaa23b7bd07ec4f5e3683ffdd8df4641bc9 (diff)
downloadlibopkele-f953b073abbf9e58e5b2a46c6ddf65f57dec1fad.zip
libopkele-f953b073abbf9e58e5b2a46c6ddf65f57dec1fad.tar.gz
libopkele-f953b073abbf9e58e5b2a46c6ddf65f57dec1fad.tar.bz2
comitting updated test consumer
Signed-off-by: Michael Krelin <hacker@klever.net>
Diffstat (more/less context) (ignore whitespace changes)
-rw-r--r--test/test-oauth-consumer.cc18
1 files changed, 4 insertions, 14 deletions
diff --git a/test/test-oauth-consumer.cc b/test/test-oauth-consumer.cc
index 3b3ca70..c5a0fc0 100644
--- a/test/test-oauth-consumer.cc
+++ b/test/test-oauth-consumer.cc
@@ -1,83 +1,73 @@
#include <iostream>
#include <cassert>
#include <stdexcept>
using namespace std;
#include <openssl/sha.h>
#include <openssl/evp.h>
#include <openssl/hmac.h>
#include <opkele/exception.h>
#include <opkele/debug.h>
#include <opkele/util.h>
#include <opkele/util-internal.h>
#include <opkele/curl.h>
#include <opkele/oauth/consumer.h>
ostream& operator<<(ostream& o,const opkele::oauth::token_t& t) {
o << "{ key: \"" << t.key << "\", secret: \"" << t.secret <<"\" }";
return o;
}
int main(int,char**) {
try {
opkele::oauth::simple_consumer sc(
opkele::oauth::simple_provider_endpoints(
"http://term.ie/oauth/example/request_token.php",
"http://term.ie/oauth/example/user_authorization.php",
"http://term.ie/oauth/example/access_token.php",
"HMAC-SHA1", opkele::oauth::oauth_post_body,
opkele::oauth::oauth_auth_header),
opkele::oauth::token_t( "key","secret" ) );
opkele::oauth::token_t rt = sc.get_request_token();
cout << "Request token: " << rt << endl;
cout << "Authorize URL: " << sc.get_authorize_url(rt) << endl;
opkele::oauth::token_t at = sc.get_access_token(rt);
cout << "Access token: " << at << endl;
opkele::fields_t test;
test.set_field("foo","bar");
opkele::util::curl_pick_t curl = opkele::util::curl_t::easy_init();
opkele::oauth::http_request_t hr("POST",
"http://term.ie/oauth/example/echo_api.php");
sc.prepare_request(hr,
opkele::fields_t(),test,
opkele::oauth::oauth_auth_header,"HMAC-SHA1",
&at,"realm");
- DOUT_("url: " << hr.url << endl
- << "body: " << hr.body << endl
- << "header: " << hr.authorize_header);
- opkele::util::curl_slist_t rh;
- rh.append("Authorization: "+hr.authorize_header);
- CURLcode r;
- (r=curl.misc_sets())
- || (r=curl.set_write())
- || (r=curl.easy_setopt(CURLOPT_HTTPHEADER,rh) )
- || (r=curl.easy_setopt(CURLOPT_URL,hr.url.c_str()))
- || (r=curl.easy_setopt(CURLOPT_POST,1))
- || (r=curl.easy_setopt(CURLOPT_POSTFIELDS,hr.body.c_str()))
- || (r=curl.easy_setopt(CURLOPT_POSTFIELDSIZE,hr.body.size()));
+ CURLcode r = curl.misc_sets();
+ r || (r=curl.set_write());
if(r)
throw opkele::exception_curl(OPKELE_CP_ "failed to set curly options",r);
+ hr.setup_curl(curl);
if( (r=curl.easy_perform()) )
throw opkele::exception_curl(OPKELE_CP_ "failed to perform curly request",r);
- DOUT_("Response: " << endl << curl.response);
+ cout << "Response: " << curl.response << endl;
#ifdef OPKELE_HAVE_KONFORKA
}catch(konforka::exception& e) {
cerr
<< "oops, caught " << opkele::util::abi_demangle(typeid(e).name()) << endl
<< " what: " << e.what() << endl
<< " where: " << e.where() << endl;
if(!e._seen.empty()) {
cerr << " seen:" << endl;
for(list<konforka::code_point>::const_iterator
i=e._seen.begin();i!=e._seen.end();++i) {
cerr << " " << i->c_str() << endl;
}
}
#endif
}catch(std::exception& e){
cerr
<< "oops, caught " << opkele::util::abi_demangle(typeid(e).name()) << endl
<< " what: " << e.what() << endl;
}
}