Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- Clarizen.prototype.convertToObject = function(json)
- {
- console.log("convertToObject: " + json);
- return JSON.parse(json);
- };
- Clarizen.prototype.debug = function (message) {
- console.log("clarizen object debug " + message);
- };
- Clarizen.prototype.validateMethod = function (method) {
- if (method === "GET" || method === "POST" || method === "HEAD") {
- return true;
- }
- return false;
- };
- Clarizen.prototype.request = function (options) {
- var url = (options.url !== null) ? options.url : null;
- var callback = (typeof options.callback === "function") ? options.callback : null;
- var method = (options.method !== null) ? options.method : "GET";
- if (url === null)
- { throw new Error("url missing"); }
- if (callback === null)
- { throw new Error("callback is missing/not a function type"); }
- if (!Clarizen.prototype.validateMethod(options.method)) {
- throw new Error("method can isnt supported currently " + method)
- }
- var util = new Bradaz();
- var xhr = util.createXHR(url, method, true);
- xhr.onreadystatechange = function () {
- if (xhr.readyState === 4 && xhr.status === 200) {
- var response = callback(xhr.responseText);
- return response;
- }
- };
- if (options.body !== null) {
- xhr.send(options.body)
- }
- else {
- xhr.send();
- }
- };
- Clarizen.prototype.getSessionId = function(response)
- {
- var loginResponse = JSON.parse(response);
- console.log("getSessionId " + loginResponse.serverLocation);
- //The followin ERRORS
- var r = this.request (
- {
- url: this.serverLocation + ClarizenConstants.Urls.authentication,
- method: "POST",
- callback: this.convertToObject,
- body: this.jsonUser
- }
- );
- };
- Clarizen.prototype.login = function () {
- var obj = new ClarizenObject();
- var user = obj.factory({
- type: 'User',
- userName: "username",
- password: "password"
- });
- var jsonBody = JSON.stringify(user);
- this.jsonUser = jsonBody;
- var response = this.request (
- {
- url: ClarizenConstants.Urls.getServerDefinition,
- method: "POST",
- callback: this.getSessionId,
- body: jsonBody
- }
- );
- };
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement