-
Notifications
You must be signed in to change notification settings - Fork 0
/
codapi.js
53 lines (45 loc) · 1.41 KB
/
codapi.js
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
import React from 'react';
import axios from 'axios';
import { setFlash } from './flash';
const DATA = 'DATA';
const BASE_URL = 'https://my.callofduty.com/api/papi-client';
const getDataFromAPI = (uri) => {
debugger
return (dispatch) => {
axios.get(uri)
.then( res => dispatch({
type: DATA,
data: res.data.data
}) )
.catch( res => {debugger})
}
}
export const getLeaderboard = (params) => {
const { title, platform, time, type, mode, username } = params
const leaderboardEndpoint = BASE_URL + '/leaderboards/v2'
const uri =
`${leaderboardEndpoint}/title/${title}/platform/${platform}/time/${time}/type/${type}/mode/${mode}/gamer/${username}`
return getDataFromAPI(uri)
}
export const getProfile = (params) => {
const { title, platform, username } = params
const profileEndpoint = BASE_URL + '/crm/cod/v2'
const uri =
`${profileEndpoint}/title/${title}/platform/${platform}/gamer/${username}/profile`
return getDataFromAPI(uri)
}
export const getMatches = (params) => {
const { title, platform, username, days } = params
const matchesEndpoint = BASE_URL + '/crm/cod/v2'
const uri =
`${matchesEndpoint}/title/${title}/platform/${platform}/gamer/${username}/matches/days/${days}`
return getDataFromAPI(uri)
}
export default (state = {}, action) => {
switch (action.type) {
case DATA:
return action.data;
default:
return state;
}
};