示例#1
0
  beforeEach(() => {
    let headers = new Headers();
    headers.append('Content-Type', 'application/json');
    headers.append('Authorization', 'Bearer secretToken');

    spyOn(RequestService.prototype, 'getAuthHeaders').and.returnValue(headers);
  });
示例#2
0
 HeroService.prototype.delete = function (hero) {
     var headers = new http_1.Headers();
     headers.append('Content-Type', 'application/json');
     var url = this.heroesUrl + "/" + hero.id;
     return this.http.delete(url, { headers: headers }).toPromise()
         .catch(this.handleError);
 };
 BaseLoopBackApi.prototype.request = function (method, url, urlParams, params, data) {
     if (urlParams === void 0) { urlParams = {}; }
     if (params === void 0) { params = {}; }
     if (data === void 0) { data = null; }
     var headers = new http_1.Headers();
     headers.append('Content-Type', 'application/json');
     if (auth.getAccessTokenId()) {
         headers.append('Authorization', auth.getAccessTokenId());
     }
     var requestUrl = url;
     var key;
     for (key in urlParams) {
         requestUrl = requestUrl.replace(new RegExp(":" + key + "(\/|$)", "g"), urlParams[key] + "$1");
     }
     var parameters = [];
     for (var param in params) {
         parameters.push(param + '=' + (typeof params[param] === 'object' ? JSON.stringify(params[param]) : params[param]));
     }
     requestUrl += (parameters ? '?' : '') + parameters.join('&');
     var request = new http_1.Request({
         headers: headers,
         method: method,
         url: requestUrl,
         body: data ? JSON.stringify(data) : undefined
     });
     return this.http.request(request)
         .map(function (res) { return (res.text() != "" ? res.json() : {}); })
         .catch(this.errorHandler.handleError);
 };
示例#4
0
 ViewPlayerComponent.prototype.challenge = function (sign) {
     var _this = this;
     if (this.challenging) {
         return;
     }
     this.challenging = true;
     document.getElementById("spinner").style.display = "block";
     var headers = new http_1.Headers();
     headers.append('Content-Type', 'application/x-www-form-urlencoded');
     var postdata = "player2_id=" + this.playerId + "&sign=" + sign;
     var data;
     this.http.post('../IksOks/php/services/new_game_service.php', postdata, { headers: headers })
         .subscribe(function (d) {
         data = d;
         console.log(data);
     }, function (err) {
         var obj = JSON.parse(err._body);
         document.getElementById("alert").innerHTML = obj;
         document.getElementById("spinner").style.display = "none";
         _this.challenging = false;
     }, function () {
         //console.log(data._body);
         var game = JSON.parse(data._body);
         _this.router.root.navigate(['./Play', { id: game.id }]);
         document.getElementById("spinner").style.display = "none";
         _this.challenging = false;
     });
 };
示例#5
0
 add(event) {
     let headers = new http_1.Headers();
     headers.append('Content-Type', 'application/json');
     return this._http
         .post(EventService_1.ENDPOINT.replace(':id', ''), event, { headers: headers })
         .map((r) => r.json());
 }
 ApiService.prototype.getHeaders = function () {
     var headers = new http_1.Headers();
     headers.append("Content-Type", "application/json");
     headers.append("Accept", "application/json");
     headers.append("AnimeApiClientKey", "AA46C009-49F8-4411-A4D6-131D4BA6D91B");
     return headers;
 };
示例#7
0
 LoginService.prototype.resetPassword = function (email) {
     var headers = new http_1.Headers();
     headers.append("Content-Type", "application/json");
     return this.http.post(backend_service_1.BackendService.apiUrl + "Users/resetpassword", JSON.stringify({
         Email: email
     }), { headers: headers }).catch(this.handleErrors);
 };
示例#8
0
 RegisterComponent.prototype.onRegister = function () {
     var _this = this;
     document.getElementById("alert").innerHTML = "";
     if (this.registerForm.value.password != this.registerForm.value.password_confirm) {
         document.getElementById("alert").innerHTML = "Šifre se ne slažu.";
         return;
     }
     document.getElementById("spinner").style.visibility = "visible";
     var postdata = "username="******"&email=" + this.registerForm.value.email + "&password="******"alert").innerHTML = obj;
         document.getElementById("spinner").style.visibility = "hidden";
     }, function () {
         //console.log(data);
         var obj = JSON.parse(data._body);
         localStorage.setItem('token', obj.token);
         localStorage.setItem('username', obj.username);
         _this.router.parent.navigate(['./Home']);
         document.getElementById("spinner").style.visibility = "hidden";
     });
 };
示例#9
0
 HomeComponent.prototype.ngOnInit = function () {
     var _this = this;
     var headers = new http_1.Headers();
     headers.append('Content-Type', 'application/x-www-form-urlencoded');
     var data1;
     this.http.post('../IksOks/php/services/get_players_service.php', "limit=5&sort_by=wins", { headers: headers })
         .subscribe(function (d) { return data1 = d; }, function (err) {
         console.log(err);
         var obj = JSON.parse(err._body);
         document.getElementById("spinner-players").style.display = "none";
         document.getElementById("alert-players").innerHTML = obj;
     }, function () {
         //console.log(data1._body);
         _this.players = JSON.parse(data1._body);
         document.getElementById("spinner-players").style.display = "none";
     });
     var data2;
     this.http.post('../IksOks/php/services/get_games_service.php', "limit=5", { headers: headers })
         .subscribe(function (d) { return data2 = d; }, function (err) {
         console.log(err);
         var obj = JSON.parse(err._body);
         document.getElementById("spinner-games").style.display = "none";
         document.getElementById("alert-games").innerHTML = obj;
     }, function () {
         //console.log(data2._body);
         _this.games = JSON.parse(data2._body);
         document.getElementById("spinner-games").style.display = "none";
     });
 };
示例#10
0
 function HomePageComponent(builder, http) {
     var _this = this;
     this.http = http;
     this.name = "";
     var headers = new http_1.Headers();
     headers.append('Content-Type', 'application/x-www-form-urlencoded');
     headers.append('token', localStorage.getItem('token'));
     http.get('http://localhost/it255-projekat/php/getvehicles.php', { headers: headers })
         .map(function (res) { return res.json(); }).share()
         .subscribe(function (data) {
         _this.data = data.vehicles;
     }, function (err) {
         _this.router.navigate(['./']);
     });
     http.get('http://localhost/it255-projekat/php/getvozilo.php', { headers: headers })
         .map(function (res) { return res.json(); }).share()
         .subscribe(function (dataS) {
         _this.dataS = dataS.serviser;
     }, function (err) {
         _this.router.navigate(['./']);
     });
     http.get('http://localhost/it255-projekat/php/getservis.php', { headers: headers })
         .map(function (res) { return res.json(); }).share()
         .subscribe(function (dataServis) {
         _this.dataServis = dataServis.servis;
         setInterval(function () {
             $('table').DataTable();
         }, 200);
     }, function (err) {
         _this.router.parent.navigate(['./Home']);
     });
 }
示例#11
0
 AlbumService.prototype.validateOTP = function (_id, otp) {
     var body = "otp=" + otp + "&_id=" + _id;
     var firstheader = new http_1.Headers();
     firstheader.append('Content-Type', 'application/x-www-form-urlencoded');
     return this.http.post(this.validateotpurl, body, { headers: firstheader })
         .map(function (response) { return response.json(); });
 };
示例#12
0
 AlbumService.prototype.postNewWish = function (newWish) {
     var body = "username="******"&wishmessage=" + newWish.wishmessage + "&mobile=" + newWish.mobile + "&emailid=" + newWish.emailid;
     var firstheader = new http_1.Headers();
     firstheader.append('Content-Type', 'application/x-www-form-urlencoded');
     return this.http.post(this.postwishurl, body, { headers: firstheader })
         .map(function (response) { return response.json(); });
 };
示例#13
0
 UserService.prototype.register = function (user) {
     if (!user) {
         return;
     }
     var headers = new http_1.Headers();
     headers.append("Content-Type", "application/json");
     return this._http.post(config_1.Config.apiUrl + "registerUser", JSON.stringify(user), { headers: headers }).catch(this.handleErrors);
 };
 TodoService.prototype.add = function (message) {
     var _messageStringified = JSON.stringify({ todoMessage: message });
     var headers = new http_1.Headers();
     headers.append('Content-Type', 'application/json');
     return this._http
         .post(TodoService.ENDPOINT.replace(':id', ''), _messageStringified, { headers: headers })
         .map(function (r) { return r.json(); });
 };
示例#15
0
 ApiService.prototype.get = function (url) {
     var headers = new http_1.Headers();
     headers.append('Authorization', this.token());
     headers.append('Content-Type', 'application/json');
     return this.http
         .get(this.getBaseUrl() + url, { headers: headers })
         .map(function (res) { return res.json(); });
 };
 ItemService.prototype.deleteItem = function (id) {
     var _this = this;
     var headers = new http_1.Headers();
     headers.append('Content-Type', 'application/json');
     this.http.delete(this.itemsAPIUrl + '/' + id, { headers: headers })
         .map(function (res) { return res.json(); })
         .subscribe(function (res) { return _this.router.navigate(['/items']); }, function (err) { return console.log('some error'); }, function () { return console.log('success get'); });
 };
示例#17
0
 SearchService.prototype.search = function (bible, searchText) {
     // console.log("Search " + bible + " for " + searchText);
     var url = this.biblerService.getUrl() + '/' + bible + '/search.json';
     var headers = new http_1.Headers();
     headers.append('Content-Type', 'application/x-www-form-urlencoded');
     var args = "text=" + searchText;
     return this.http.post(url, args, { headers: headers }).toPromise().then(function (res) { return res.json(); });
 };
 HeroService.prototype.post = function (hero) {
     var headers = new http_1.Headers();
     headers.append('Content-Type', 'application/json');
     return this.http.post(this.heroesUrl, JSON.stringify(hero), { headers: headers })
         .toPromise()
         .then(function (res) { return res.json().data; })
         .catch(this.handleError);
 };
示例#19
0
 RatingService.prototype.syncRating = function (rating) {
     var _this = this;
     if (rating === void 0) { rating = this.rating.Rating; }
     console.log("rating = " + rating);
     var headers = new http_1.Headers();
     headers.append('Content-Type', 'application/json');
     this.http.post("../../../api/BooksApi/Rating/" + this.bookId, JSON.stringify({ "rating": rating }), { headers: headers }).subscribe(function (response) { _this.fetchRating(); }, function (error) { return alert("Error: " + JSON.stringify(error)); });
 };
示例#20
0
 HttpClient.prototype.createAuthorizationHeader = function () {
     var headers = new http_1.Headers();
     headers.append('Content-Type', 'application/x-www-form-urlencoded');
     // headers.append('x-company-code',localStorage.getItem("company_code"));
     headers.append('x-company-code', this.memory.getCompanyCode());
     headers.append('Authorization', "Bearer " + localStorage.getItem("token"));
     return headers;
 };
示例#21
0
 MovieService.prototype.getRecommendations = function (currentUser) {
     var search = new http_1.URLSearchParams();
     search.set('username', currentUser.username);
     var headers = new http_1.Headers();
     headers.set('Authorization', 'JWT ' + currentUser.token);
     return this.http.get(this.apiURL + 'recommendations/', { headers: headers, search: search })
         .map(function (res) { return res.json(); });
 };
示例#22
0
 HeroService.prototype.put = function (hero) {
     var headers = new http_1.Headers();
     headers.append('Content-Type', 'application/json');
     var url = this.heroesUrl + "/" + hero.id;
     return this.http.put(url, JSON.stringify(hero), { headers: headers }).toPromise()
         .then(function () { return hero; })
         .catch(this.handleError);
 };
示例#23
0
 BookmarkService.prototype.delete = function (bookmark) {
     var headers = new http_1.Headers();
     headers.append('Content-Type', 'application/json');
     var url = this.bookmarkUrl + "/" + bookmark.id;
     return this.http
         .delete(url, headers)
         .toPromise()
         .catch(this.handleError);
 };
 LoginService.prototype.login = function (luser) {
     var headers = new http_1.Headers();
     var body = JSON.stringify(luser);
     headers.append('Content-Type', 'application/json');
     // Promise.resolve(USER).then((users: User[])=>users.push(user)user);
     // return this._http.post('http://127.0.0.1:8000/user',JSON.stringify(user))
     return this._http.post('http://127.0.0.1:8000/login/', body, { headers: headers }).map(function (res) {
     });
 };
 BucketlistService.prototype.deleteItem = function (item, bucketlist) {
     var headers = new http_1.Headers({ 'Content-Type': 'application/json' });
     headers.append('Authorization', (this.token));
     var options = new http_1.RequestOptions({ headers: headers });
     var itemPath = this.baseApi + "/" + bucketlist.id + "/items/" + item.id;
     return this.http.delete(itemPath, options)
         .map(this.extractData)
         .catch(this.handleError);
 };
 BucketlistService.prototype.addBucketlist = function (name) {
     var body = JSON.stringify({ name: name });
     var headers = new http_1.Headers({ 'Content-Type': 'application/json' });
     headers.append('Authorization', (this.token));
     var options = new http_1.RequestOptions({ headers: headers });
     return this.http.post(this.baseApi, body, options)
         .map(this.extractData)
         .catch(this.handleError);
 };
 ReviewService.prototype.rate = function (value, userId, reviewId) {
     var body = 'value=' + value + '&userId=' + userId + '&reviewId=' + reviewId;
     var headers = new http_1.Headers();
     headers.append('Content-Type', 'application/x-www-form-urlencoded');
     return this.http.post(path_1.Path[0] + "/rateReview", body, {
         headers: headers
     })
         .map(function (res) { return res.json(); });
 };
 RequestConditionService.prototype.delete = function (request_condition) {
     var _this = this;
     var headers = new http_1.Headers();
     headers.append('Content-Type', 'application/json');
     headers.append('Authorization', 'Token ' + localStorage.getItem('token'));
     var options = new http_1.RequestOptions({ headers: headers, body: {} });
     return this.http.delete('/mockatron/api/request_conditions/' + request_condition.id, options)
         .catch(function (error) { return _this.handleError(error, "Error deleting request condition."); });
 };
 GroupService.prototype.declineRequest = function (userId, groupId) {
     var body = 'uid=' + userId + '&gid=' + groupId;
     var headers = new http_1.Headers();
     headers.append('Content-Type', 'application/x-www-form-urlencoded');
     return this.http.post(path_1.Path[0] + "/declinerequest", body, {
         headers: headers
     })
         .map(function (res) { return res.json(); });
 };
 GroupService.prototype.editGroup = function (id, name, description, rated, tags, type) {
     var body = 'gid=' + id + '&name=' + name + '&description=' + description + '&rated=' + rated + '&tags=' + tags + '&type=' + type;
     var headers = new http_1.Headers();
     headers.append('Content-Type', 'application/x-www-form-urlencoded');
     return this.http.post(path_1.Path[0] + "/editgroup", body, {
         headers: headers
     })
         .map(function (res) { return res.json(); });
 };