Remove unused API code

This commit is contained in:
Alan Friedman 2019-05-27 16:21:27 -04:00
parent 435e193c93
commit 810be10293
4 changed files with 0 additions and 73 deletions

View File

@ -1,12 +0,0 @@
const methodMap = {
GET: '',
POST: 'CREATE_',
PUT: 'UPDATE_',
DELETE: 'DELETE_',
}
export const fetchStart = (name, method, resourceId, meta) => ({ type: `FETCH_${methodMap[method]}${name.toUpperCase()}_START`, payload: { resourceId, meta } })
export const fetchSuccess = (name, method, response) => ({ type: `FETCH_${methodMap[method]}${name.toUpperCase()}_SUCCESS`, payload: response })
export const fetchFailure = (name, method, response) => ({ type: `FETCH_${methodMap[method]}${name.toUpperCase()}_FAILURE`, payload: response })

View File

@ -1,4 +1,3 @@
export * from './fetch'
export * from './room'
export * from './app'

View File

@ -1,4 +1,3 @@
import fetch from 'api'
import isEqual from 'lodash/isEqual'
import {
process as processMessage,

View File

@ -1,59 +0,0 @@
import {
fetchStart,
fetchSuccess,
fetchFailure,
} from 'actions'
import queryString from 'querystring'
import generateUrl from './generator'
export default (opts, dispatch, name, metaOpts = {}) => {
const method = opts.method || 'GET'
const resourceId = opts.resourceId
let url = generateUrl(opts.resourceName, resourceId)
const config = {
method,
headers: {},
type: 'cors',
}
if (opts.body) {
config.body = JSON.stringify(opts.body)
config.headers['Content-Type'] = 'application/json'
}
if (opts.query) {
url = `${url}?${queryString.stringify(opts.query)}`
}
return new Promise((resolve, reject) => {
const meta = { ...metaOpts, timestamp: Date.now() }
dispatch(fetchStart(name, method, resourceId, meta))
return window.fetch(url, config)
.then(async (response) => {
let json = {}
try {
json = await response.json()
} catch (e) {
throw new Error(e)
}
const dispatchOps = {
response,
json,
resourceId,
meta,
}
if (response.ok) {
dispatch(fetchSuccess(name, method, dispatchOps))
return resolve(dispatchOps)
}
dispatch(fetchFailure(name, method, dispatchOps))
return reject(dispatchOps)
})
})
}