<commit_before>"use strict";
var Client = require("./client");
var CALL_PATH = "calls";

function Call(){
  //for compatibility
  if(arguments.length > 0){
    this.from = arguments[0];
    this.to = arguments[1];
  }
}

/** Get information about a call that was made or received
 * @param client Client instance
 * @param id Id of call
 * @param callback callback function
 * @example
 * bandwidth.Client.get(client, "id", function(err, call){});
 * */
Call.get = function(client, id, callback){
  if(arguments.length === 2){
    callback = id;
    id = client;
    client = new Client();
  }
  client.makeRequest("get", client.concatUserPath(CALL_PATH) + "/" +  id, function(err, item){
    if(err){
      return callback(err);
    }
    item.client = client;
    item.__proto__ = Call.prototype;
    callback(null, item);
  });
};

/** Get a list of previous calls that were made or received
 *  @param client Client instance
 *  @param query query parametes
 *  @param callback callback function
 *  @example
 *  bandwidth.Call.list(client, function(err, list){});
 * */
Call.list = function(client, query, callback){
  if(arguments.length === 2){
    callback = query;
    if(client instanceof Client){
      query = {};
    }
    else{
      query = client;
      client = new Client();
    }
  }
  else if(arguments.length === 1){
    callback = client;
    client = new Client();
    query = {};
  }
  client.makeRequest("get", client.concatUserPath(CALL_PATH), query, function(err, items){
    if(err){
      return callback(err);
    }
    items = items || [];
    var result = items.map(function(item){
      item.client = client;
      item.__proto__ = Call.prototype;
      return item;
    });
    callback(null, result);
  });
};

/** Make a phone call
 * @param client Client instance
 * @param item call's data
 * @param callback callback function
 * #example
 * bandwidth.Call.create(client, {from: "", to: ""}, function(err, call){});
 * */
Call.create = function(client, item, callback){
  if(arguments.length === 2){
    callback = item;
    item = client;
    client = new Client();
  }
  var request = client.createRequest("post", client.concatUserPath(CALL_PATH));
  request.type("json").send(item).end(function(res){
    if(res.ok && res.headers.location){
      Client.getIdFromLocationHeader(res.headers.location, function(err, id){
        if(err){
          return callback(err);
        }
        Call.get(client, id, callback);
      });
    }
    else{
      client.checkResponse(res, callback);
    }
  });
};

/** Make changes to an active phone call. E.g.: transfer, hang up, answer or reject incoming calls, call recording, etc.
 * @param client Client instance
 * @param id Id of call
 * @param data changed data
 * @param callback callback function
 * @example
 * bandwidth.Call.update(client, "id", {state: "rejected"}, function(err){}) ;
 * */
Call.update = function(client, id, data, callback){
  client.makeRequest("post", client.concatUserPath(CALL_PATH) + "/" + id, data, callback);
};

/** Make changes to an active phone call. E.g.: transfer, hang up, answer or reject incoming calls, call recording, etc.
 * @param data changed data
 * @param callback callback function
 * @example
 * call.update({state: "rejected"}, function(err){}) ;
 * */
Call.prototype.update = function(data, callback){
  this.client.makeRequest("post", this.client.concatUserPath(CALL_PATH) + "/" + this.id,  data, callback);
};

/** Play an audio or speak a sentence in a call
 * @param data audio data
 * @param callback callback function
 * @example
 * call.playAudio({fileUrl: ""}, function(err}{});
 * */
Call.prototype.playAudio = function(data, callback){
  this.client.makeRequest("post", this.client.concatUserPath(CALL_PATH) + "/" + this.id + "/audio",  data, callback);
};

/** Speak a sentence in a call
 * @param sentence sentence to speak
 * @param tag optional tag value which will be used in events
 * @param gender optional gender value (default: female)
 * @param voice optional voice name (default: kate)
 * @param callback callback function
 * @example
 * call.speakSentence("test", "tag", function(err){});<commit_msg>Allow static call update without a client instance<commit_after>"use strict";
var Client = require("./client");
var CALL_PATH = "calls";

function Call(){
  //for compatibility
  if(arguments.length > 0){
    this.from = arguments[0];
    this.to = arguments[1];
  }
}

/** Get information about a call that was made or received
 * @param client Client instance
 * @param id Id of call
 * @param callback callback function
 * @example
 * bandwidth.Client.get(client, "id", function(err, call){});
 * */
Call.get = function(client, id, callback){
  if(arguments.length === 2){
    callback = id;
    id = client;
    client = new Client();
  }
  client.makeRequest("get", client.concatUserPath(CALL_PATH) + "/" +  id, function(err, item){
    if(err){
      return callback(err);
    }
    item.client = client;
    item.__proto__ = Call.prototype;
    callback(null, item);
  });
};

/** Get a list of previous calls that were made or received
 *  @param client Client instance
 *  @param query query parametes
 *  @param callback callback function
 *  @example
 *  bandwidth.Call.list(client, function(err, list){});
 * */
Call.list = function(client, query, callback){
  if(arguments.length === 2){
    callback = query;
    if(client instanceof Client){
      query = {};
    }
    else{
      query = client;
      client = new Client();
    }
  }
  else if(arguments.length === 1){
    callback = client;
    client = new Client();
    query = {};
  }
  client.makeRequest("get", client.concatUserPath(CALL_PATH), query, function(err, items){
    if(err){
      return callback(err);
    }
    items = items || [];
    var result = items.map(function(item){
      item.client = client;
      item.__proto__ = Call.prototype;
      return item;
    });
    callback(null, result);
  });
};

/** Make a phone call
 * @param client Client instance
 * @param item call's data
 * @param callback callback function
 * #example
 * bandwidth.Call.create(client, {from: "", to: ""}, function(err, call){});
 * */
Call.create = function(client, item, callback){
  if(arguments.length === 2){
    callback = item;
    item = client;
    client = new Client();
  }
  var request = client.createRequest("post", client.concatUserPath(CALL_PATH));
  request.type("json").send(item).end(function(res){
    if(res.ok && res.headers.location){
      Client.getIdFromLocationHeader(res.headers.location, function(err, id){
        if(err){
          return callback(err);
        }
        Call.get(client, id, callback);
      });
    }
    else{
      client.checkResponse(res, callback);
    }
  });
};

/** Make changes to an active phone call. E.g.: transfer, hang up, answer or reject incoming calls, call recording, etc.
 * @param client Client instance
 * @param id Id of call
 * @param data changed data
 * @param callback callback function
 * @example
 * bandwidth.Call.update(client, "id", {state: "rejected"}, function(err){}) ;
 * */
Call.update = function(client, id, data, callback){
  if(arguments.length === 3){
    callback = data;
    data = id;
    id = client;
    client = new Client();
  }
  client.makeRequest("post", client.concatUserPath(CALL_PATH) + "/" + id, data, callback);
};

/** Make changes to an active phone call. E.g.: transfer, hang up, answer or reject incoming calls, call recording, etc.
 * @param data changed data
 * @param callback callback function
 * @example
 * call.update({state: "rejected"}, function(err){}) ;
 * */
Call.prototype.update = function(data, callback){
  this.client.makeRequest("post", this.client.concatUserPath(CALL_PATH) + "/" + this.id,  data, callback);
};

/** Play an audio or speak a sentence in a call
 * @param data audio data
 * @param callback callback function
 * @example
 * call.playAudio({fileUrl: ""}, function(err}{});
 * */
Call.prototype.playAudio = function(data, callback){
  this.client.makeRequest("post", this.client.concatUserPath(CALL_PATH) + "/" + this.id + "/audio",  data, callback);
};

/** Speak a sentence in a call
 * @param sentence sentence to speak
 * @param tag optional tag value which will be used in events
 * @param gender optional gender value (default: female)
 * @param voice optional voice name (default: kate)
 * @param callback callback function
 * @example
 * call.speakSentence("test", "tag", function(err){});
{'fraction_non_alphanumeric': 0.14992326761893518, 'fraction_numerical': 0.0017707472553417543, 'mean_word_length': 3.4968152866242037, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 5, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '1715687', 'n_tokens_mistral': 2513, 'n_tokens_neox': 2495, 'n_words': 751}