summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--modules/curl.module/module.cpp38
-rw-r--r--modules/twitter.module/module.cpp57
2 files changed, 67 insertions, 28 deletions
diff --git a/modules/curl.module/module.cpp b/modules/curl.module/module.cpp
index b435523..2f76340 100644
--- a/modules/curl.module/module.cpp
+++ b/modules/curl.module/module.cpp
@@ -156,17 +156,24 @@ class Ccurl
(*curlObj->mMsg)["id"].str() << ") " << text);
}
#ifndef NDEBUG
-// else
-// {
-// string text;
-// text.resize(length);
-// memcpy((void *)text.c_str(),data,length);
-// text.erase(--text.end());
-// INFO("curl (" <<
-// curlObj->mMsg->dst << " " <<
-// (*curlObj->mMsg)["id"].str() << ") " << text);
-//
-// }
+ else
+ {
+ if (type==CURLINFO_HEADER_IN || type==CURLINFO_HEADER_OUT)
+ {
+ string text;
+ text.resize(length);
+ memcpy((void *)text.c_str(),data,length);
+ text.erase(--text.end());
+
+ //remove newline
+ if (text.length()>0)
+ text.resize(text.length()-1);
+
+ DEB("curl (" <<
+ curlObj->mMsg->dst << " " <<
+ (*curlObj->mMsg)["id"].str() << ") " << type << ": " << text);
+ }
+ }
#endif
return 0;
@@ -272,6 +279,7 @@ class Ccurl
char **argv = NULL;
argc = oauth_split_url_parameters((*mMsg)["url"].str().c_str(), &argv);
+
if ((*mMsg).isSet("post"))
{
//split it into a new array and add that to our current array:
@@ -316,8 +324,12 @@ class Ccurl
oauth_hdr = oauth_serialize_url_sep(argc, 1, argv, (char *)", ", 6);
//format header and add to curl
- string authHeader="Authorization: OAuth ";
- authHeader+=oauth_hdr;
+ string authHeader=oauth_hdr;
+ //workaround oauth bug? (remove leading ", ")
+ if (authHeader.substr(0,2)==", ")
+ authHeader=authHeader.substr(2);
+
+ authHeader="Authorization: OAuth "+authHeader;
DEB("oauth header: " << authHeader);
headers = curl_slist_append(headers, authHeader.c_str());
diff --git a/modules/twitter.module/module.cpp b/modules/twitter.module/module.cpp
index b0aa499..eb704cc 100644
--- a/modules/twitter.module/module.cpp
+++ b/modules/twitter.module/module.cpp
@@ -66,8 +66,9 @@ SYNAPSE_REGISTER(twitter_Request)
if (state==GET_USERS)
{
- out["url"]="http://api.twitter.com/1/statuses/user_timeline.json";
+ out["url"]="http://api.twitter.com/1/statuses/home_timeline.json?count=200";
}
+
else if (state==STREAM)
{
out["url"]="https://userstream.twitter.com/2/user.json";
@@ -180,23 +181,38 @@ SYNAPSE_REGISTER(curl_Ok)
{
Cvar data;
data.fromJson(queue);
- //traverse all the users and send their last statusses
- userIds="";
- for (CvarList::iterator I=data.list().begin(); I!=data.list().end(); I++)
- {
- if (userIds=="")
- userIds+=(*I)["id_str"].str();
- else
- userIds+=","+(*I)["id_str"].str();
+ if (data.which()==CVAR_MAP && data.isSet("error"))
+ {
Cmsg out;
- out.event="twitter_Data";
- out.map()=(*I).map();
+ out.event="twitter_Error";
+ out["error"]=data["error"].str();
out.send();
- }
- state=STREAM;
- request();
+ delayedRequest();
+ }
+ else
+ {
+ //traverse all the users and send their last statusses
+ userIds="";
+ ERROR("count " << data.list().size());
+
+ for (CvarList::reverse_iterator I=data.list().rbegin(); I!=data.list().rend(); I++)
+ {
+ if (userIds=="")
+ userIds+=(*I)["id_str"].str();
+ else
+ userIds+=","+(*I)["id_str"].str();
+
+ Cmsg out;
+ out.event="twitter_Data";
+ out.map()=(*I).map();
+ out.send();
+ }
+ state=STREAM;
+
+ request();
+ }
}
else if (state==STREAM)
{
@@ -251,7 +267,18 @@ SYNAPSE_REGISTER(curl_Data)
{
//convert to data
Cvar data;
- data.fromJson(jsonStr);
+ try
+ {
+ data.fromJson(jsonStr);
+ }
+ catch(...)
+ {
+ Cmsg out;
+ out.event="twitter_Error";
+ out["error"]=jsonStr;
+ out.send();
+ return;
+ }
//send out message
Cmsg out;