-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathwpACFreader.js
More file actions
81 lines (70 loc) · 1.72 KB
/
wpACFreader.js
File metadata and controls
81 lines (70 loc) · 1.72 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
import axios from 'axios';
import WPReader from './wpreader';
/**
*
*/
export default class ACFReader extends WPReader {
/**
*
* @param {Object} options
*/
constructor (options = {}) {
super(options);
this.settings.completeEndpoint = this.settings.endpoint +
(!(this.settings.endpoint.endsWith('/')) ? '/' : '') + 'wp-json/acf/v3/';
}
/**
*
*/
tags () {
throw 'ACF for tags is not supported yet';
}
/**
*
*/
taxonomies () {
throw 'ACF for taxonomies is not supported yet';
}
/**
*
*/
postTypes () {
throw 'ACF for post types is not supported yet';
}
async options (args = {}) {
let method = 'options';
return this._doRequest(method, args, {});
}
/**
*
* @param {*} method
* @param {*} args
* @param {*} def
*/
_doRequest (method, args, def) {
if (typeof args.id !== 'undefined') {
method += '/' + args.id;
delete args.id;
}
if (typeof args.fieldName !== 'undefined') {
method += '/' + args.fieldName;
delete args.fieldName;
}
let params = Object.assign({}, def, args);
if (this.settings.debug) {
console.log(`${this.settings.completeEndpoint}${method}/?${this._queryParams(params)}`, this.auth);
}
if (!this.settings.auth) {
return axios.get(`${this.settings.completeEndpoint}${method}/?${this._queryParams(params)}`);
}
if (this.auth.loggedin) {
return axios.get(`${this.settings.completeEndpoint}${method}/?${this._queryParams(params)}`, {
headers: {
Authorization: `Token ${this.auth.token}`,
}
});
} else {
throw new WPAuth.AuthException('La chiamata necessita di autenticazione, non sei autenticato');
}
}
}