You cannot select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
27 lines
591 B
JavaScript
27 lines
591 B
JavaScript
7 months ago
|
// External dependencies.
|
||
|
import $ from 'jquery';
|
||
|
|
||
|
// Internal dependencies.
|
||
|
import config from './config';
|
||
|
|
||
|
|
||
|
export const request = (method, data, options = {}) => {
|
||
|
const deferred = $.ajax({
|
||
|
type: method,
|
||
|
url: config.api,
|
||
|
dataType: 'json',
|
||
|
data,
|
||
|
...options,
|
||
|
});
|
||
|
|
||
|
return Promise.resolve(deferred.promise())
|
||
|
.then(response => {
|
||
|
if (false === response.success) {
|
||
|
return Promise.reject(response.data || {});
|
||
|
}
|
||
|
return Promise.resolve(response.data);
|
||
|
});
|
||
|
};
|
||
|
|
||
|
export const post = (data, options = {}) => request('POST', data, options);
|