Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse files

change init to load

  • Loading branch information...
commit 15ea6e8aa6137ddefabc1bfa9901f7d9e57e28de 1 parent 3217a16
@fengmk2 fengmk2 authored
View
4 README.md
@@ -32,8 +32,8 @@ tapi SDK api base on tsina(weibo) api document: [http://open.weibo.com/](http://
<script type="text/javascript" src="../weibo.js"></script>
<script type="text/javascript">
- // init with urlprefix where the `weibo` directory you put into
- weibo.init('/public/js/weibo');
+ // load all the lib scripts with urlprefix where the `weibo` directory you put into
+ weibo.load('/public/js/weibo');
</script>
var tapi = weibo.tapi;
View
47 lib/urllib.js
@@ -2,9 +2,16 @@
/**
* Fixed JSON bad word, more detail see [JSON parse在各浏览器的兼容性列表](http://www.cnblogs.com/rubylouvre/archive/2011/02/12/1951760.html)
+ * @type {String}
+ * @const
*/
-var RE_JSON_BAD_WORD = /[\u000B\u000C]/ig;
+exports.RE_JSON_BAD_WORD = /[\u000B\u000C]/ig;
+/**
+ * The default request timeout(in milliseconds)
+ * @type {Object.<Number>}
+ * @const
+ */
exports.TIMEOUT = 60000;
function format_args(args) {
@@ -16,7 +23,7 @@ function format_args(args) {
}
args.type = (args.type || 'GET').toUpperCase();
return args;
-}
+};
function format_result(args, data, res, callback, context) {
var error = null;
@@ -49,7 +56,22 @@ function format_result(args, data, res, callback, context) {
if(callback) {
callback.call(context, error, data, res);
}
-}
+};
+
+
+/**
+ * 生成HTTP Basic Authentication的字符串:"Base base64String"
+ *
+ * @param {String} user
+ * @param {String} password
+ * @return {String} 'Basic xxxxxxxxxxxxxxxx'
+ * @api public
+ */
+exports.make_base_auth_header = function(user, password) {
+ var token = user + ':' + password;
+ var hash = Base64.encode(token);
+ return "Basic " + hash;
+};
if(typeof require !== 'undefined') {
var http = require('http')
@@ -121,7 +143,6 @@ if(typeof require !== 'undefined') {
// console.log('on data ' + chunk.length);
});
res.on('end', function(){
-// console.log(chunks.length);
var data = new Buffer(length);
var error = null;
// 延后copy
@@ -130,7 +151,6 @@ if(typeof require !== 'undefined') {
pos += chunks[i].length;
}
data = data.toString();
- //console.log(res.statusCode, data)
format_result(args, data, res, callback, context);
});
});
@@ -138,7 +158,7 @@ if(typeof require !== 'undefined') {
req.write(body);
}
req.end();
- // set timeout
+ // TODO: add timeout
// setTimeout(function() {
//
// });
@@ -192,21 +212,6 @@ if(typeof require !== 'undefined') {
}
-
-/**
- * 生成HTTP Basic Authentication的字符串:"Base base64String"
- *
- * @param {String} user
- * @param {String} password
- * @return {String} 'Basic xxxxxxxxxxxxxxxx'
- * @api public
- */
-exports.make_base_auth_header = function(user, password) {
- var tok = user + ':' + password;
- var hash = Base64.encode(tok);
- return "Basic " + hash;
-};
-
})( (function(){
if(typeof exports === 'undefined') {
window.weibo.urllib = {};
View
2  test/browser/weibo_browser_test.html
@@ -4,7 +4,7 @@
<script type="text/javascript" src="jquery-1.6.min.js"></script>
<script type="text/javascript" src="../../weibo.js"></script>
<script type="text/javascript">
- weibo.init('../../');
+ weibo.load('../../');
function start_test() {
var keys = [
'sha1', 'oauth', 'base64',
View
8 weibo.js
@@ -1,6 +1,11 @@
/**
* only use in browser envirment
*
+ * MUST use the namespace: `weibo`
+ * e.g:
+ *
+ * weibo.tapi.init(key, sceret);
+ *
* deal with javascript script loading
*/
@@ -17,8 +22,7 @@ weibo._requires = [
, 'lib/tapi.js'
];
-
-weibo.init = function(url_prefix) {
+weibo.load = function(url_prefix) {
if(url_prefix[url_prefix.length - 1] != '/') {
url_prefix += '/';
}
Please sign in to comment.
Something went wrong with that request. Please try again.