Permalink
Browse files

launched jslint, fixed some things

  • Loading branch information...
1 parent e2247c6 commit 1b6c23ea301df6e7b852fe2bb51d1e0a0a9fc2ca @bobrik bobrik committed Sep 20, 2011
Showing with 29 additions and 25 deletions.
  1. +28 −24 lib/index.js
  2. +1 −1 package.json
View
@@ -3,29 +3,13 @@ var https = require("https");
var VkClient = function(token) {
this.token = token;
-}
+};
VkClient.prototype.PATH_START = "/method/";
VkClient.prototype.HOST = "api.vkontakte.ru";
VkClient.prototype.api = function(method, params, callback) {
- var queryParams = {};
- if (typeof params == "object") {
- for (var i in params) {
- if (params.hasOwnProperty(i)) {
- queryParams[i] = params[i];
- }
- }
- }
-
- queryParams.access_token = this.token;
-
- var options = {
- host: this.HOST,
- path: this.PATH_START + method + "?" + qs.stringify(queryParams)
- };
-
- https.get(options, function(res) {
+ https.get(this.getHttpGetOptions(method, params), function(res) {
var responseData = "";
res.on("data", function(data) {
responseData += data.toString();
@@ -36,17 +20,37 @@ VkClient.prototype.api = function(method, params, callback) {
var result = JSON.parse(responseData);
if (result.error) {
- callback && callback(result.error);
+ return callback && callback(result.error);
} else {
- callback(undefined, result.response);
+ return callback && callback(undefined, result.response);
}
} catch (e) {
- callback && callback(e);
+ return callback && callback(e);
}
- })
- }).on('error', function(e) {
- callback && callback(e);
+ });
+ }).on("error", function(e) {
+ return callback && callback(e);
});
};
+VkClient.prototype.getHttpGetOptions = function(method, params) {
+ var queryParams = {},
+ i;
+
+ if (typeof params === "object") {
+ for (i in params) {
+ if (params.hasOwnProperty(i)) {
+ queryParams[i] = params[i];
+ }
+ }
+ }
+
+ queryParams.access_token = this.token;
+
+ return {
+ host: this.HOST,
+ path: this.PATH_START + method + "?" + qs.stringify(queryParams)
+ };
+};
+
exports.VkClient = VkClient;
View
@@ -1,6 +1,6 @@
{
"name": "vk",
- "version": "0.1.2",
+ "version": "0.1.3",
"description": "Vkontakte module for node.js",
"keywords": ["vk", "vkontakte", "social", "api"],
"author": "Ian Babrou <ibobrik@gmail.com>",

0 comments on commit 1b6c23e

Please sign in to comment.