laravel-request 1.1.15 → 1.1.17
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/package.json +1 -1
- package/readme.md +42 -4
- package/src/Api.js +6 -1
- package/src/ApiRequest.js +15 -0
- package/src/Builder.js +11 -10
package/package.json
CHANGED
package/readme.md
CHANGED
|
@@ -1,3 +1,12 @@
|
|
|
1
|
+
Install
|
|
2
|
+
|
|
3
|
+
npm install laravel-request
|
|
4
|
+
|
|
5
|
+
Connected package
|
|
6
|
+
|
|
7
|
+
https://github.com/olegstan/laravel-rest
|
|
8
|
+
|
|
9
|
+
|
|
1
10
|
Usage get data
|
|
2
11
|
|
|
3
12
|
```
|
|
@@ -8,12 +17,32 @@ Api.get('active-trade', 'index')
|
|
|
8
17
|
.with('from_account', 'from_account.currency')
|
|
9
18
|
.orderBy('trade_at', 'DESC')
|
|
10
19
|
.all((response) => {
|
|
11
|
-
|
|
20
|
+
//success
|
|
21
|
+
}, () => {
|
|
22
|
+
//error
|
|
12
23
|
})
|
|
13
|
-
.bind(this, 'trades')
|
|
14
24
|
}}
|
|
15
25
|
```
|
|
16
|
-
|
|
26
|
+
|
|
27
|
+
or
|
|
28
|
+
|
|
29
|
+
```
|
|
30
|
+
Api.get('active-trade', 'index')
|
|
31
|
+
.where('id', 115)
|
|
32
|
+
.with('currency')
|
|
33
|
+
.with('to_account', 'to_account.currency')
|
|
34
|
+
.with('from_account', 'from_account.currency')
|
|
35
|
+
.orderBy('trade_at', 'DESC')
|
|
36
|
+
.first((response) => {
|
|
37
|
+
//success
|
|
38
|
+
|
|
39
|
+
}, () => {
|
|
40
|
+
//error
|
|
41
|
+
})
|
|
42
|
+
}}
|
|
43
|
+
```
|
|
44
|
+
|
|
45
|
+
|
|
17
46
|
You can use
|
|
18
47
|
|
|
19
48
|
all or first or paginate
|
|
@@ -31,4 +60,13 @@ Api.post('active', 'store', {
|
|
|
31
60
|
}, (response) => {
|
|
32
61
|
//error
|
|
33
62
|
});
|
|
34
|
-
```
|
|
63
|
+
```
|
|
64
|
+
|
|
65
|
+
response must be like below, for 200 status should contains key "result" with text "success"
|
|
66
|
+
|
|
67
|
+
{
|
|
68
|
+
"meta": [],
|
|
69
|
+
"result": "success",
|
|
70
|
+
"data": [],
|
|
71
|
+
}
|
|
72
|
+
|
package/src/Api.js
CHANGED
|
@@ -9,6 +9,11 @@ export default class Api {
|
|
|
9
9
|
*/
|
|
10
10
|
static requestClass = ApiRequest;
|
|
11
11
|
|
|
12
|
+
static tokenResolver = () =>
|
|
13
|
+
{
|
|
14
|
+
return localStorage.getItem('api_token');
|
|
15
|
+
}
|
|
16
|
+
|
|
12
17
|
/**
|
|
13
18
|
*
|
|
14
19
|
* @param controller
|
|
@@ -147,7 +152,7 @@ export default class Api {
|
|
|
147
152
|
try {
|
|
148
153
|
headers['Content-Type'] = 'application/json';
|
|
149
154
|
|
|
150
|
-
let api_token =
|
|
155
|
+
let api_token = Api.tokenResolver();
|
|
151
156
|
if (api_token)
|
|
152
157
|
{
|
|
153
158
|
headers["Authorization"] = api_token;
|
package/src/ApiRequest.js
CHANGED
|
@@ -146,6 +146,21 @@ export default class ApiRequest {
|
|
|
146
146
|
return this.call(successCallback, errorCallback);
|
|
147
147
|
}
|
|
148
148
|
|
|
149
|
+
/**
|
|
150
|
+
*
|
|
151
|
+
* @param fields
|
|
152
|
+
* @param successCallback
|
|
153
|
+
* @param errorCallback
|
|
154
|
+
* @return {ApiRequest}
|
|
155
|
+
*/
|
|
156
|
+
pluck(fields, successCallback = (r) => {
|
|
157
|
+
}, errorCallback = () => {
|
|
158
|
+
}) {
|
|
159
|
+
this.data['paginateType'] = 'pluck';
|
|
160
|
+
this.data['fields'] = fields;
|
|
161
|
+
return this.call(successCallback, errorCallback);
|
|
162
|
+
}
|
|
163
|
+
|
|
149
164
|
getUrl()
|
|
150
165
|
{
|
|
151
166
|
return this.domain + '/api/v1/call/' + this.target + '/' + this.focus;
|
package/src/Builder.js
CHANGED
|
@@ -3,28 +3,33 @@ export default class Builder {
|
|
|
3
3
|
static availableMethod = [
|
|
4
4
|
'select',
|
|
5
5
|
'where',
|
|
6
|
+
'orWhere',
|
|
6
7
|
'whereDate',
|
|
8
|
+
'orWhereDate',
|
|
7
9
|
'whereYear',
|
|
10
|
+
'orWhereYear',
|
|
8
11
|
'whereMonth',
|
|
12
|
+
'orWhereMonth',
|
|
9
13
|
'has',
|
|
10
14
|
'whereIn',
|
|
15
|
+
'orWhereIn',
|
|
11
16
|
'whereNotIn',
|
|
17
|
+
'orWhereNotIn',
|
|
12
18
|
'whereHas',
|
|
13
19
|
'orWhereHas',
|
|
14
20
|
'whereHasMorph',
|
|
15
21
|
'orWhereHasMorph',
|
|
16
22
|
'whereDoesntHave',
|
|
17
23
|
'orWhereDoesntHave',
|
|
18
|
-
'orWhere',
|
|
19
|
-
'orderBy',
|
|
20
|
-
'groupBy',
|
|
21
24
|
'whereNull',
|
|
22
25
|
'orWhereNull',
|
|
23
26
|
'whereNotNull',
|
|
24
27
|
'orWhereNotNull',
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
+
|
|
29
|
+
|
|
30
|
+
'orderBy',
|
|
31
|
+
'groupBy',
|
|
32
|
+
|
|
28
33
|
'with',
|
|
29
34
|
'withCount',
|
|
30
35
|
'offset',
|
|
@@ -32,10 +37,6 @@ export default class Builder {
|
|
|
32
37
|
'distinct',
|
|
33
38
|
'owner',
|
|
34
39
|
'whereAbs',
|
|
35
|
-
|
|
36
|
-
'whereDate',
|
|
37
|
-
'whereYear',
|
|
38
|
-
'whereMonth',
|
|
39
40
|
];
|
|
40
41
|
|
|
41
42
|
constructor() {
|