1
0
mirror of https://github.com/bitwarden/browser synced 2025-12-22 03:03:43 +00:00

convert to using new sync api

This commit is contained in:
Kyle Spearrin
2017-09-20 12:28:41 -04:00
parent d1fb388ea3
commit fd538494c0
3 changed files with 122 additions and 182 deletions

View File

@@ -30,8 +30,8 @@ function initApiService() {
}
// Desktop
//self.baseUrl = 'http://localhost:4000';
//self.identityBaseUrl = 'http://localhost:33656';
self.baseUrl = 'http://localhost:4000';
self.identityBaseUrl = 'http://localhost:33656';
// Desktop HTTPS
//self.baseUrl = 'https://localhost:44377';
@@ -46,8 +46,8 @@ function initApiService() {
//self.identityBaseUrl = 'https://preview-identity.bitwarden.com';
// Production
self.baseUrl = 'https://api.bitwarden.com';
self.identityBaseUrl = 'https://identity.bitwarden.com';
//self.baseUrl = 'https://api.bitwarden.com';
//self.identityBaseUrl = 'https://identity.bitwarden.com';
};
// Auth APIs
@@ -138,26 +138,6 @@ function initApiService() {
});
};
ApiService.prototype.getProfile = function (success, error) {
var self = this;
handleTokenState(self).then(function (tokenHeader) {
$.ajax({
type: 'GET',
url: self.baseUrl + '/accounts/profile',
dataType: 'json',
headers: tokenHeader,
success: function (response) {
success(new ProfileResponse(response));
},
error: function (jqXHR, textStatus, errorThrown) {
handleError(error, jqXHR, false, self);
}
});
}, function (jqXHR) {
handleError(error, jqXHR, true, self);
});
};
ApiService.prototype.getKeys = function (success, error) {
var self = this;
handleTokenState(self).then(function (tokenHeader) {
@@ -212,28 +192,6 @@ function initApiService() {
});
};
// Settings APIs
ApiService.prototype.getIncludedDomains = function (success, error) {
var self = this;
handleTokenState(self).then(function (tokenHeader) {
$.ajax({
type: 'GET',
url: self.baseUrl + '/settings/domains?excluded=false',
dataType: 'json',
headers: tokenHeader,
success: function (response) {
success(new DomainsResponse(response));
},
error: function (jqXHR, textStatus, errorThrown) {
handleError(error, jqXHR, false, self);
}
});
}, function (jqXHR) {
handleError(error, jqXHR, true, self);
});
};
// Login APIs
ApiService.prototype.getLogin = function (id, success, error) {
@@ -322,31 +280,6 @@ function initApiService() {
});
};
ApiService.prototype.getFolders = function (success, error) {
var self = this;
handleTokenState(self).then(function (tokenHeader) {
$.ajax({
type: 'GET',
url: self.baseUrl + '/folders',
dataType: 'json',
headers: tokenHeader,
success: function (response) {
var data = [];
for (var i = 0; i < response.Data.length; i++) {
data.push(new FolderResponse(response.Data[i]));
}
success(new ListResponse(data));
},
error: function (jqXHR, textStatus, errorThrown) {
handleError(error, jqXHR, false, self);
}
});
}, function (jqXHR) {
handleError(error, jqXHR, true, self);
});
};
ApiService.prototype.postFolder = function (folderRequest, success, error) {
var self = this;
handleTokenState(self).then(function (tokenHeader) {
@@ -433,31 +366,6 @@ function initApiService() {
});
};
ApiService.prototype.getCiphers = function (success, error) {
var self = this;
handleTokenState(self).then(function (tokenHeader) {
$.ajax({
type: 'GET',
url: self.baseUrl + '/ciphers',
dataType: 'json',
headers: tokenHeader,
success: function (response) {
var data = [];
for (var i = 0; i < response.Data.length; i++) {
data.push(new CipherResponse(response.Data[i]));
}
success(new ListResponse(data));
},
error: function (jqXHR, textStatus, errorThrown) {
handleError(error, jqXHR, false, self);
}
});
}, function (jqXHR) {
handleError(error, jqXHR, true, self);
});
};
ApiService.prototype.deleteCipher = function (id, success, error) {
var self = this;
handleTokenState(self).then(function (tokenHeader) {
@@ -521,6 +429,28 @@ function initApiService() {
});
};
// Sync APIs
ApiService.prototype.getSync = function (success, error) {
var self = this;
handleTokenState(self).then(function (tokenHeader) {
$.ajax({
type: 'GET',
url: self.baseUrl + '/sync',
dataType: 'json',
headers: tokenHeader,
success: function (response) {
success(new SyncResponse(response));
},
error: function (jqXHR, textStatus, errorThrown) {
handleError(error, jqXHR, false, self);
}
});
}, function (jqXHR) {
handleError(error, jqXHR, true, self);
});
};
// Helpers
function handleError(errorCallback, jqXHR, tokenError, self) {