Last active
January 29, 2016 08:09
-
-
Save NikitaObukhov/7c272a7f5797b232b2cc to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
var $vk = { | |
init: function() { | |
var defer = $q.defer(); | |
VK.init(function() { | |
// API initialization succeeded | |
// Your code here | |
defer.resolve(arguments); | |
}, function() { | |
// API initialization failed | |
// Can reload page here | |
defer.reject(arguments); | |
}, '5.44'); | |
return defer.promise; | |
}, | |
call: function(method, params) { | |
var defer = $q.defer(); | |
VK.api(method, params, function(data) { | |
if (data.response) { | |
// Тут наверное еще нужно проверять что у Response статус 200, если нет то вызывать defer.reject | |
defer.resolve(data.response); | |
} | |
else { | |
defer.reject({error: 'No response'}); | |
} | |
}); | |
return defer.promise; | |
} | |
}; | |
$vk.init().then(function() { | |
// Init success | |
}, function() { | |
// Init failed. | |
}); | |
$vk.call('method_name', {}).then(function(response) { | |
// success | |
}, function(error) { | |
// fail | |
}); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment