import axios from 'axios'

/*
 * Make the Request and call onSuccess method on the call back object.
 */

export default {

  request (route, data = 0, callback) {
    axios({
      method: route.method,
      url: this.server + route.url,
      data: data,
      timeout: this.timeout
    }).then(function (response) {
      // console.log('response...')
      if (callback && callback.onSuccess) {
        callback.onSuccess(response.data)
      }
    })
  },
  // server: '',
  server: 'http://192.168.1.6:8081',
  timeout: 1000,
  route: {

    /*
     * The route tree for the Domo APIs.
     */
    lights: {
      get: {
        url: '/v1/capabilities/lights',
        method: 'get'
      },
      set: {
        url: '/v1/capabilities/lights',
        method: 'post'
      }
    },
    sprinklers: {
      get: {
        url: '/v1/capabilities/sprinklers',
        method: 'get'
      },
      set: {
        url: '/v1/capabilities/sprinklers',
        method: 'post'
      }
    }
  }
}
