1
0
mirror of https://github.com/bitwarden/browser synced 2025-12-13 14:53:33 +00:00

setting up more models and services

This commit is contained in:
Kyle Spearrin
2016-09-03 12:07:30 -04:00
parent c39aab4ee7
commit c3053ea3a7
7 changed files with 323 additions and 95 deletions

View File

@@ -5,13 +5,13 @@
!function () {
// Account APIs
ApiService.prototype.getProfile = function (success, error) {
var self = this;
this.tokenService.getToken(function (token) {
$.ajax({
type: 'GET',
url: self.baseUrl + '/accounts/profile',
data: 'access_token=' + token,
url: self.baseUrl + '/accounts/profile?access_token=' + token,
dataType: 'json',
success: function (response) {
success(new ProfileResponse(response))
@@ -25,16 +25,122 @@
// Site APIs
ApiService.prototype.getSite = function (id, success, error) {
var self = this;
this.tokenService.getToken(function (token) {
$.ajax({
type: 'GET',
url: self.baseUrl + '/sites/' + id + '?access_token=' + token,
dataType: 'json',
success: function (response) {
success(new SiteResponse(response))
},
error: function (jqXHR, textStatus, errorThrown) {
handleError(error, jqXHR, textStatus, errorThrown);
}
});
});
};
ApiService.prototype.postSite = function (siteRequest, success, error) {
var self = this;
this.tokenService.getToken(function (token) {
$.ajax({
type: 'POST',
url: self.baseUrl + '/sites?access_token=' + token,
data: siteRequest,
dataType: 'json',
success: function (response) {
success(new SiteResponse(response))
},
error: function (jqXHR, textStatus, errorThrown) {
handleError(error, jqXHR, textStatus, errorThrown);
}
});
});
};
ApiService.prototype.putSite = function (id, siteRequest, success, error) {
var self = this;
this.tokenService.getToken(function (token) {
$.ajax({
type: 'POST',
url: self.baseUrl + '/sites/' + id + '?access_token=' + token,
data: siteRequest,
dataType: 'json',
success: function (response) {
success(new SiteResponse(response))
},
error: function (jqXHR, textStatus, errorThrown) {
handleError(error, jqXHR, textStatus, errorThrown);
}
});
});
};
// Folder APIs
ApiService.prototype.getFolder = function (id, success, error) {
var self = this;
this.tokenService.getToken(function (token) {
$.ajax({
type: 'GET',
url: self.baseUrl + '/folders/' + id + '?access_token=' + token,
dataType: 'json',
success: function (response) {
success(new FolderResponse(response))
},
error: function (jqXHR, textStatus, errorThrown) {
handleError(error, jqXHR, textStatus, errorThrown);
}
});
});
};
ApiService.prototype.postFolder = function (folderRequest, success, error) {
var self = this;
this.tokenService.getToken(function (token) {
$.ajax({
type: 'POST',
url: self.baseUrl + '/folders?access_token=' + token,
data: folderRequest,
dataType: 'json',
success: function (response) {
success(new FolderResponse(response))
},
error: function (jqXHR, textStatus, errorThrown) {
handleError(error, jqXHR, textStatus, errorThrown);
}
});
});
};
ApiService.prototype.putFolder = function (id, folderRequest, success, error) {
var self = this;
this.tokenService.getToken(function (token) {
$.ajax({
type: 'POST',
url: self.baseUrl + '/folders/' + id + '?access_token=' + token,
data: folderRequest,
dataType: 'json',
success: function (response) {
success(new FolderResponse(response))
},
error: function (jqXHR, textStatus, errorThrown) {
handleError(error, jqXHR, textStatus, errorThrown);
}
});
});
};
// Cipher APIs
ApiService.prototype.getCipher = function (id, success, error) {
var self = this;
this.tokenService.getToken(function (token) {
$.ajax({
type: 'GET',
url: self.baseUrl + '/ciphers/' + id,
data: 'access_token=' + token,
url: self.baseUrl + '/ciphers/' + id + '?access_token=' + token,
dataType: 'json',
success: function (response) {
success(new CipherResponse(response))
@@ -51,8 +157,7 @@
this.tokenService.getToken(function (token) {
$.ajax({
type: 'GET',
url: self.baseUrl + '/ciphers',
data: 'access_token=' + token,
url: self.baseUrl + '/ciphers?access_token=' + token,
dataType: 'json',
success: function (response) {
var data = [];
@@ -69,6 +174,23 @@
});
};
ApiService.prototype.deleteCipher = function (id, success, error) {
var self = this;
this.tokenService.getToken(function (token) {
$.ajax({
type: 'POST',
url: self.baseUrl + '/ciphers/' + id + '/delete?access_token=' + token,
dataType: 'json',
success: success,
error: function (jqXHR, textStatus, errorThrown) {
handleError(error, jqXHR, textStatus, errorThrown);
}
});
});
};
// Helpers
function handleError(errorCallback, jqXHR, textStatus, errorThrown) {
errorCallback(new ErrorResponse(jqXHR));
}