export class Doctor{
  getByIssue(issue){
    return new Promise(function(resolve,reject){
      let request = new XMLHttpRequest();
      let url = `https://api.betterdoctor.com/2016-03-01/doctors?query=${issue}&location=45.5122%2C%20-122.6587%2C%2030&skip=0&limit=10&user_key=${process.env.exports.apiKey}`;
      request.onload = function(){
        if(this.status === 200){
          resolve(request.response);
        }else{
          reject(Error(request.statusText));
        }
      }
      request.open("GET", url, true);
      request.send();
    });
  }
  getByName(name){
    return new Promise(function(resolve,reject){
      let request = new XMLHttpRequest();
      let url = `https://api.betterdoctor.com/2016-03-01/doctors?name=${name}&location=45.5122%2C%20-122.6587%2C%2030&skip=0&limit=10&user_key=${process.env.exports.apiKey}`;
      request.onload = function(){
        if(this.status == 200){
          resolve(request.response);
        }else{
          reject(Error(request.statusText));
        }
      }
      request.open("GET", url, true);
      request.send();
    });
  }
}