summaryrefslogtreecommitdiff
path: root/lambda-calcul/javascript/src/client.js
blob: d046187ce8b36f06929ca5979ca62e44fc2bb6ae (plain)
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
const axios = require('axios');

const newClient = ({ playerName, challengerURL }) => {
  const nextChallenge = (token) => axios ({
    url: `${challengerURL}/api/challenge?token=${token}`,
  })
    .then(({ data: { expr } }) => expr);

  const start = () => axios({
    method: 'POST',
    url: `${challengerURL}/api/register`,
    headers: { 'Content-Type': 'application/json;charset=utf-8' },
    data: playerName,
  })
    .then(({ data }) => data);

  return {
    nextChallenge,
    start,
  };
};

module.exports = {
  newClient,
};