mirror of
https://github.com/ChronosX88/psyced.git
synced 2024-12-05 00:22:19 +00:00
http/fetch: call callback even if status is not OK so errors can be handled; surf: added back dest param for cmd()
This commit is contained in:
parent
7d715092c1
commit
c6264e1087
@ -1352,8 +1352,9 @@ _PAGES_start_description
|
||||
|<script>
|
||||
|var longer = 44
|
||||
|
|
||||
|function cmd(wish) {
|
||||
|function cmd(wish, dest) {
|
||||
| Pef.cmd.value = wish
|
||||
| Pef.dest.value = dest || ''
|
||||
| Pef.submit()
|
||||
| longer = 44
|
||||
| return false
|
||||
|
@ -202,15 +202,14 @@ disconnected(remainder) {
|
||||
fheaders = headers;
|
||||
buffer = headers = 0;
|
||||
switch (http_status) {
|
||||
case R_OK:
|
||||
default:
|
||||
mixed *waiter;
|
||||
while (qSize(ME)) {
|
||||
waiter = shift(ME);
|
||||
P2(("%O calls back.. body is %O\n", ME, fetched))
|
||||
funcall(waiter[0], fetched, waiter[1] ? fheaders : copy(fheaders));
|
||||
funcall(waiter[0], fetched, waiter[1] ? fheaders : copy(fheaders), http_status);
|
||||
}
|
||||
break;
|
||||
default:
|
||||
if (http_status == R_OK) break;
|
||||
// doesn't seem to get here when HTTP returns 301 or 302. strange.
|
||||
// fall thru
|
||||
case R_NOTMODIFIED:
|
||||
|
@ -9,6 +9,7 @@
|
||||
|
||||
#include <net.h>
|
||||
#include <tls.h>
|
||||
#include <ht/http.h>
|
||||
|
||||
string consumer_key;
|
||||
string consumer_secret;
|
||||
@ -51,28 +52,32 @@ varargs void fetch(object ua, string url, string method, mapping post, mapping o
|
||||
ua->fetch(url, method, post, (["authorization": "OAuth " + p]));
|
||||
}
|
||||
|
||||
void parse_request_token(string body, mapping headers) {
|
||||
P3((">> oauth:parse_request_token(%O, %O)\n", body, headers))
|
||||
request_params = ([]);
|
||||
url_parse_query(request_params, body);
|
||||
if (strlen(request_params["oauth_token"]) && strlen(request_params["oauth_token_secret"])) {
|
||||
shared_memory("oauth_request_tokens")[request_params["oauth_token"]] = ME;
|
||||
sendmsg(user, "_notice_oauth_authorize_url", "Open [_url] to perform authorization.",
|
||||
(["_url": authorize_url + "?oauth_token=" + request_params["oauth_token"]]));
|
||||
} else {
|
||||
sendmsg(user, "_error_oauth_token_request", "OAuth failed: could not get a request token.");
|
||||
void parse_request_token(string body, mapping headers, int http_status) {
|
||||
P3((">> oauth:parse_request_token(%O, %O, %O)\n", body, headers, http_status))
|
||||
if (http_status == R_OK) {
|
||||
request_params = ([]);
|
||||
url_parse_query(request_params, body);
|
||||
if (strlen(request_params["oauth_token"]) && strlen(request_params["oauth_token_secret"])) {
|
||||
shared_memory("oauth_request_tokens")[request_params["oauth_token"]] = ME;
|
||||
sendmsg(user, "_notice_oauth_authorize_url", "Open [_url] to perform authorization.",
|
||||
(["_url": authorize_url + "?oauth_token=" + request_params["oauth_token"]]));
|
||||
return;
|
||||
}
|
||||
}
|
||||
sendmsg(user, "_error_oauth_token_request", "OAuth failed: could not get a request token.");
|
||||
}
|
||||
|
||||
void parse_access_token(string body, mapping headers) {
|
||||
P3((">> oauth:parse_access_token(%O, %O)\n", body, headers))
|
||||
access_params = ([]);
|
||||
url_parse_query(access_params, body);
|
||||
if (strlen(access_params["oauth_token"]) && strlen(access_params["oauth_token_secret"])) {
|
||||
sendmsg(user, "_notice_oauth_success", "OAuth successful.");
|
||||
} else {
|
||||
sendmsg(user, "_error_oauth_token_access", "OAuth failed: could not get an access token.");
|
||||
void parse_access_token(string body, mapping headers, int http_status) {
|
||||
P3((">> oauth:parse_access_token(%O, %O, %O)\n", body, headers, http_status))
|
||||
if (http_status == R_OK) {
|
||||
access_params = ([]);
|
||||
url_parse_query(access_params, body);
|
||||
if (strlen(access_params["oauth_token"]) && strlen(access_params["oauth_token_secret"])) {
|
||||
sendmsg(user, "_notice_oauth_success", "OAuth successful.");
|
||||
return;
|
||||
}
|
||||
}
|
||||
sendmsg(user, "_error_oauth_token_access", "OAuth failed: could not get an access token.");
|
||||
}
|
||||
|
||||
void verified(string verifier) {
|
||||
|
@ -1,4 +1,5 @@
|
||||
/* twitter client
|
||||
* http://apiwiki.twitter.com/Twitter-API-Documentation
|
||||
*
|
||||
* - register @ http://twitter.com/apps
|
||||
* - settings:
|
||||
@ -23,8 +24,10 @@ object load(object usr, string key, string secret, string request, string access
|
||||
return ::load(usr, key, secret, request, access, authorize);
|
||||
}
|
||||
|
||||
void parse_status_update(string body, string headers) {
|
||||
P3(("twitter/client:parse_status_update(%O, %O)\n", body, headers))
|
||||
void parse_status_update(string body, string headers, int http_status) {
|
||||
P3(("twitter/client:parse_status_update(%O, %O, %O)\n", body, headers, http_status))
|
||||
if (http_status != R_OK)
|
||||
sendmsg(user, "_error_twitter_status_update", "Error: failed to post status update on twitter.");
|
||||
}
|
||||
|
||||
void status_update(string text) {
|
||||
@ -36,8 +39,8 @@ void status_update(string text) {
|
||||
fetch(ua, "http://api.twitter.com/1/statuses/update.json", "POST", (["status": text]));
|
||||
}
|
||||
|
||||
void parse_home_timeline(string body, string headers) {
|
||||
P3(("twitter/client:parse_home_timeline(%O, %O)\n", body, headers))
|
||||
void parse_home_timeline(string body, string headers, int http_status) {
|
||||
P3(("twitter/client:parse_home_timeline(%O, %O, %O)\n", body, headers, http_status))
|
||||
}
|
||||
|
||||
void home_timeline() {
|
||||
|
Loading…
Reference in New Issue
Block a user