Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Current rate sent back with each call #50

Merged
merged 1 commit into from
Dec 14, 2013
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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 @@ -126,7 +126,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 @@ -722,7 +722,7 @@ var Codebird = function () {

/**
* Clone objects
*
*
* @param object obj The object to clone
*
* @return object clone The cloned object
Expand Down Expand Up @@ -1130,7 +1130,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 @@ -1161,7 +1167,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 @@ -1198,7 +1204,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