var angular = require('angular');

require('../modules');

var module = angular.module('toberead.services');
module.factory('RemoteService', function($http) {
  var  service = {
    allYueBi: allYueBi,
    processDispense: processDispense,
  };
  return service;

  function allYueBi(userId) {
    return $http.put('/toberead/allYB/' + userId, {
      timeout: 15000
    }).then(function(response) {
      return response.statusText == 'OK';
    });
  };

  /**
   * 内部分发请求到服务器
   *
   * @param  {entity} entity 内部分发的请求对象
   * @return {Promise}
   */
  function processDispense(userId, url, entity) {
    return $http({
      method: 'POST',
      url: '/toberead/dispense/' + userId + '?url=' + url,
      data: entity,
      headers: {
        'Content-Type': 'application/x-www-form-urlencoded'
      },
      timeout: 15000
    }).then(function(response) {
      return response.data;
    });
  };

});
