Skip to content

Commit

Permalink
Merge branch 'feature/50-reply-rate-limit' #50
Browse files Browse the repository at this point in the history
  • Loading branch information
mynetx committed Dec 14, 2013
2 parents 3225870 + 4e48a98 commit 166de2b
Show file tree
Hide file tree
Showing 3 changed files with 32 additions and 6 deletions.
1 change: 1 addition & 0 deletions CHANGELOG
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ codebird-js - changelog
+ #24 Add README section about xAuth
+ #46 Don't force to send base64 media uploads via proxy
+ #23 Support internal API methods
+ #50 Current rate sent back with each call

2.4.3 (2013-07-24)
- #31 HTTP error on multiple oauth_requestToken calls
Expand Down
14 changes: 14 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -294,6 +294,20 @@ rate-limited.
See the [Rate Limiting FAQ](https://dev.twitter.com/docs/rate-limiting-faq)
for more information.
If you allow your callback function to accept a second parameter,
you will receive rate-limiting details in this parameter.
```javascript
cb.__call(
"search_tweets",
"q=Twitter",
function (reply, rate_limit_status) {
console.log(rate_limit_status);
// ...
}
);
```
6. API calls and the same-origin policy
---------------------------------------
Expand Down
23 changes: 17 additions & 6 deletions codebird.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
* A Twitter library in JavaScript
*
* @package codebird
* @version 2.5.0-dev
* @version 2.4.3
* @author J.M. <[email protected]>
* @copyright 2010-2013 J.M. <[email protected]>
*
Expand Down Expand Up @@ -131,7 +131,7 @@ var Codebird = function () {
/**
* The current Codebird version
*/
var _version = "2.5.0-dev";
var _version = "2.4.3";

/**
* Sets the OAuth consumer key and secret (App key)
Expand Down Expand Up @@ -729,7 +729,7 @@ var Codebird = function () {

/**
* Clone objects
*
*
* @param object obj The object to clone
*
* @return object clone The cloned object
Expand Down Expand Up @@ -1197,7 +1197,13 @@ var Codebird = function () {
var callback_name = _nonce();
window[callback_name] = function (reply) {
reply.httpstatus = 200;
callback(reply);

var rate = {
limit: xml.getResponseHeader('x-rate-limit-limit'),
remaining: xml.getResponseHeader('x-rate-limit-remaining'),
reset: xml.getResponseHeader('x-rate-limit-reset'),
};
callback(reply, rate);
};
params.callback = callback_name;
url_with_params = url + "?" + _sign(httpmethod, url, params, true);
Expand Down Expand Up @@ -1228,7 +1234,7 @@ var Codebird = function () {
params = http_build_query(params);
}
post_fields = params;
if (_use_proxy) {
if (_use_proxy || multipart) { // force proxy for multipart base64
url = url.replace(
_endpoint_base,
_endpoint_proxy
Expand Down Expand Up @@ -1265,7 +1271,12 @@ var Codebird = function () {
} catch (e) {}
var reply = _parseApiReply(method_template, xml.responseText);
reply.httpstatus = httpstatus;
callback(reply);
var rate = {
limit: xml.getResponseHeader('x-rate-limit-limit'),
remaining: xml.getResponseHeader('x-rate-limit-remaining'),
reset: xml.getResponseHeader('x-rate-limit-reset'),
};
callback(reply, rate);
}
};
xml.send(httpmethod === "GET" ? null : post_fields);
Expand Down

0 comments on commit 166de2b

Please sign in to comment.