1
0
mirror of https://github.com/laurent22/joplin.git synced 2025-07-16 00:14:34 +02:00

Added session service

This commit is contained in:
Laurent Cozic
2017-05-07 23:20:34 +01:00
parent e5d7294b69
commit b6cf34450f
7 changed files with 57 additions and 23 deletions

View File

@ -0,0 +1,5 @@
class BaseModel {
}
export { BaseModel };

View File

@ -0,0 +1,9 @@
class BaseService {
constructor(webApi) {
this.api_ = webApi;
}
}
export { BaseService };

View File

@ -0,0 +1,11 @@
import { BaseModel } from 'src/base-model.js';
class Session extends BaseModel {
static login(email, password) {
}
}
export { Session };

View File

@ -0,0 +1,15 @@
import { BaseService } from 'src/base-service.js';
class SessionService extends BaseService {
login(email, password, clientId) {
return this.api_.post('sessions', null, {
'email': email,
'password': password,
'client_id': clientId,
});
}
}
export { SessionService };

View File

@ -2,9 +2,8 @@ const queryString = require('query-string');
class WebApi {
constructor(baseUrl, clientId) {
constructor(baseUrl) {
this.baseUrl_ = baseUrl;
this.clientId_ = clientId;
}
makeRequest(method, path, query, data) {
@ -36,11 +35,15 @@ class WebApi {
fetch(r.url, r.options).then(function(response) {
let responseClone = response.clone();
return response.json().then(function(data) {
resolve(data);
if (data && data.error) {
reject(data);
} else {
resolve(data);
}
})
.catch(function(error) {
responseClone.text().then(function(text) {
reject('Cannot parse JSON: ' + text);
reject(new Error('Cannot parse JSON: ' + text));
});
});
})