| 1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374 |
- import axios from 'axios'
-
- const SETTINGS = {
- LOADING_SEGMENTS: 2,
- API_BASE_PATH: '/wp-json/craft/v2/',
- API_MEDIA_PATH: '/wp-json/wp/v2/media/',
- }
-
- export default {
- getByType(type, sortType, cb) {
- if (sortType) {
- return axios
- .get(SETTINGS.API_BASE_PATH + `sort/${type}/${sortType}`)
- .then(response => {
- cb(response.data)
- return response.data
- })
- .catch(e => {
- cb(e)
- })
- } else {
- return axios
- .get(SETTINGS.API_BASE_PATH + `${type}`)
- .then(response => {
- cb(response.data)
- return response.data
- })
- .catch(e => {
- cb(e)
- })
- }
- },
- async getSingleType(type, id, cb) {
- await axios
- .get(SETTINGS.API_BASE_PATH + `${type}/${id}`)
- .then(response => {
- cb(Object.values(response.data)[0])
- })
- .catch(e => {
- cb(e)
- })
- },
- async getSingleMedia(id, cb) {
- await axios
- .get(SETTINGS.API_MEDIA_PATH + `${id}`)
- .then(response => {
- cb(response.data)
- })
- .catch(e => {
- cb(e)
- })
- },
-
- getSticky(cb) {
- axios
- .get(SETTINGS.API_BASE_PATH + 'sticky')
- .then(response => {
- cb(response.data)
- })
- .catch(e => {
- cb(e)
- })
- },
- getPosts(limit = 5, cb) {
- axios
- .get(SETTINGS.API_BASE_PATH + 'posts')
- .then(response => {
- cb(response.data)
- })
- .catch(e => {
- cb(e)
- })
- },
- }
|