Skip to content

Commit

Permalink
Api mapping for Toolwatchapp/tw-mobile#36
Browse files Browse the repository at this point in the history
  • Loading branch information
MathieuNls committed Jul 26, 2016
1 parent 3af2bb0 commit 328abe4
Show file tree
Hide file tree
Showing 7 changed files with 59 additions and 7 deletions.
2 changes: 1 addition & 1 deletion dist/app/directives/login/login.component.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ import { FormBuilder, Control, ControlGroup } from '@angular/common';
import { TwAPIService } from './../../services/twapi.service';
export declare class LoginComponent implements OnInit {
private translate;
private twapi;
protected twapi: TwAPIService;
private builder;
loginForm: ControlGroup;
email: Control;
Expand Down
2 changes: 1 addition & 1 deletion dist/app/directives/login/login.component.js.map

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

6 changes: 6 additions & 0 deletions dist/app/services/twapi.service.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -136,6 +136,12 @@ export declare class TwAPIService {
* @return {Promise<User>}
*/
login(email: string, password: string): Promise<User>;
/**
* Get an user using his API key
* @param {string} key [description]
* @return {Promise<User>} [description]
*/
getUser(key: string): Promise<User>;
/**
* Registers a new user
* @param {string} email
Expand Down
19 changes: 18 additions & 1 deletion dist/app/services/twapi.service.js

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion dist/app/services/twapi.service.js.map

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion src/app/directives/login/login.component.ts
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@ export class LoginComponent implements OnInit {
* @param {FormBuilder} private builder [description]
*/
constructor(private translate: TranslateService,
private twapi: TwAPIService, private builder: FormBuilder) {
protected twapi: TwAPIService, private builder: FormBuilder) {

//Lang definition
translate.setDefaultLang('en');
Expand Down
33 changes: 31 additions & 2 deletions src/app/services/twapi.service.ts
Original file line number Diff line number Diff line change
Expand Up @@ -194,8 +194,6 @@ export class TwAPIService {
.map((res) => { return ModelFactory.buildUser(res.json()); })
.toPromise().then(
res => {
console.log("works");

GAService.event('API', 'LOGIN');
TwAPIService.apikey = res.key;
TwAPIService.headers.delete('X-API-KEY');
Expand All @@ -207,6 +205,37 @@ export class TwAPIService {
)
}


/**
* Get an user using his API key
* @param {string} key [description]
* @return {Promise<User>} [description]
*/
getUser(key:string):Promise<User> {


TwAPIService.apikey = key;
TwAPIService.headers.delete('X-API-KEY');
TwAPIService.headers.append('X-API-KEY', TwAPIService.apikey);


return this.http.get(
this.baseUrl + "users",
TwAPIService.options
)
.map((res) => { return ModelFactory.buildUser(res.json()); })
.toPromise().then(
res => {

GAService.event('API', 'AUTOLOGIN');
TwAPIService.user = res;
return res;
},
err => this.handleError(err)
)

}

/**
* Registers a new user
* @param {string} email
Expand Down

0 comments on commit 328abe4

Please sign in to comment.