8
8
* @copyright Copyright (c) Mosufy
9
9
*/
10
10
11
- import Constant from './../helpers/constant' ;
12
11
import axios from 'axios' ;
13
12
13
+ const apiHost = process . env . API_HOST || 'https://lumenapi.local/v1' ;
14
+ const apiClientId = process . env . API_CLIENT_ID || '6fC2745co07D4yW7X9saRHpJcE0sm0MT' ;
15
+ const apiClientSecret = process . env . API_CLIENT_SECRET || 'KLqMw5D7g1c6KX23I72hx5ri9d16GJDW' ;
16
+
14
17
const config = ( accessToken = '' ) => {
15
18
return ( {
16
19
headers : { 'Authorization' : 'Bearer ' + accessToken }
@@ -23,10 +26,10 @@ const config = (accessToken = '') => {
23
26
* @returns AxiosPromise
24
27
*/
25
28
export function generateClientAccessToken ( ) {
26
- return axios . post ( Constant . apiUrl + '/oauth/access_token/client' , {
29
+ return axios . post ( apiHost + '/oauth/access_token/client' , {
27
30
grant_type : 'client_credentials' ,
28
- client_id : Constant . clientId ,
29
- client_secret : Constant . clientSecret ,
31
+ client_id : apiClientId ,
32
+ client_secret : apiClientSecret ,
30
33
scope : 'role.app'
31
34
} ) ;
32
35
}
@@ -40,10 +43,10 @@ export function generateClientAccessToken() {
40
43
* @returns AxiosPromise
41
44
*/
42
45
export function generateUserAccessToken ( clientAccessToken , username , password ) {
43
- return axios . post ( Constant . apiUrl + '/oauth/access_token' , {
46
+ return axios . post ( apiHost + '/oauth/access_token' , {
44
47
grant_type : 'password' ,
45
- client_id : Constant . clientId ,
46
- client_secret : Constant . clientSecret ,
48
+ client_id : apiClientId ,
49
+ client_secret : apiClientSecret ,
47
50
username,
48
51
password,
49
52
scope : 'role.user'
@@ -60,7 +63,7 @@ export function generateUserAccessToken(clientAccessToken, username, password) {
60
63
* @returns AxiosPromise
61
64
*/
62
65
export function signup ( clientAccessToken , email , password , name ) {
63
- return axios . post ( Constant . apiUrl + '/account' , {
66
+ return axios . post ( apiHost + '/account' , {
64
67
email,
65
68
password,
66
69
name
@@ -74,7 +77,7 @@ export function signup(clientAccessToken, email, password, name) {
74
77
* @returns AxiosPromise
75
78
*/
76
79
export function getUserData ( accessToken ) {
77
- return axios . get ( Constant . apiUrl + '/account' , config ( accessToken ) ) ;
80
+ return axios . get ( apiHost + '/account' , config ( accessToken ) ) ;
78
81
}
79
82
80
83
/**
@@ -85,28 +88,28 @@ export function getUserData(accessToken) {
85
88
* @returns AxiosPromise
86
89
*/
87
90
export function refreshToken ( clientAccessToken , refreshToken ) {
88
- return axios . post ( Constant . apiUrl + '/oauth/access_token' , {
91
+ return axios . post ( apiHost + '/oauth/access_token' , {
89
92
grant_type : 'refresh_token' ,
90
- client_id : Constant . clientId ,
91
- client_secret : Constant . clientSecret ,
93
+ client_id : apiClientId ,
94
+ client_secret : apiClientSecret ,
92
95
refresh_token : refreshToken
93
96
} , config ( clientAccessToken ) ) ;
94
97
}
95
98
96
99
export function getTodos ( accessToken ) {
97
- return axios . get ( Constant . apiUrl + '/todos' , config ( accessToken ) ) ;
100
+ return axios . get ( apiHost + '/todos' , config ( accessToken ) ) ;
98
101
}
99
102
100
103
export function insertTodo ( accessToken , text ) {
101
- return axios . post ( Constant . apiUrl + '/todos' , {
104
+ return axios . post ( apiHost + '/todos' , {
102
105
title : text
103
106
} , config ( accessToken ) ) ;
104
107
}
105
108
106
109
export function toggleTodo ( accessToken , id ) {
107
- return axios . put ( Constant . apiUrl + '/todos/' + id + '/toggle' , null , config ( accessToken ) ) ;
110
+ return axios . put ( apiHost + '/todos/' + id + '/toggle' , null , config ( accessToken ) ) ;
108
111
}
109
112
110
113
export function deleteAllTodos ( accessToken ) {
111
- return axios . delete ( Constant . apiUrl + '/todos' , config ( accessToken ) ) ;
114
+ return axios . delete ( apiHost + '/todos' , config ( accessToken ) ) ;
112
115
}
0 commit comments