Skip to content

Instantly share code, notes, and snippets.

@NikitaObukhov
Last active January 29, 2016 08:09
Show Gist options
  • Save NikitaObukhov/7c272a7f5797b232b2cc to your computer and use it in GitHub Desktop.
Save NikitaObukhov/7c272a7f5797b232b2cc to your computer and use it in GitHub Desktop.
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