Completed
Push — master ( 2040ba...cef9c4 )
by Vitaly
02:22
created

src/createAPI.js   A

Complexity

Total Complexity 4
Complexity/F 1

Size

Lines of Code 20
Function Count 4

Duplication

Duplicated Lines 0
Ratio 0 %

Importance

Changes 1
Bugs 0 Features 0
Metric Value
cc 0
wmc 4
c 1
b 0
f 0
nc 1
mnd 0
bc 3
fnc 4
dl 0
loc 20
rs 10
bpm 0.75
cpm 1
noi 0

1 Function

Rating   Name   Duplication   Size   Complexity  
A createAPI.js ➔ ??? 0 13 1
1
import callAPIMethod from './callAPIMethod';
2
3
import applyMiddleware from './applyMiddleware';
4
5
const createAPI = (resources = {}, middleware = [], APIPrefix = '', fetchOptions = {}) =>
6
7
    Object.keys(resources).reduce( (api, resourceId) => {
8
        api[resourceId] = Object.keys(resources[resourceId].methods).reduce( (resource, method) => {
9
            resource[method] = (params, methodOptions) => {
10
                const apiParams = resources[resourceId].methods[method](params);
11
                const bindedCallAPIMethod = callAPIMethod.bind(null, APIPrefix, fetchOptions, resources[resourceId].prefix);
12
                return applyMiddleware(bindedCallAPIMethod, middleware, methodOptions, apiParams, resourceId, method);
13
            };
14
            return resource;
15
        }, {});
16
        return api;
17
    }, {});
18
19
20
export default createAPI;