{"size": 932, "ext": "js", "max_stars_repo_path": "src/httpStub/Stub.js", "max_stars_repo_name": "andykingking/cucumber-browser-preset-myob", "max_stars_repo_stars_event_min_datetime": null, "max_stars_repo_stars_event_max_datetime": null, "max_issues_repo_path": "src/httpStub/Stub.js", "max_issues_repo_name": "andykingking/cucumber-browser-preset-myob", "max_issues_repo_issues_event_min_datetime": null, "max_issues_repo_issues_event_max_datetime": null, "max_forks_repo_path": "src/httpStub/Stub.js", "max_forks_repo_name": "andykingking/cucumber-browser-preset-myob", "max_forks_repo_forks_event_min_datetime": null, "max_forks_repo_forks_event_max_datetime": null}
{"max_stars_count": null, "max_issues_count": null, "max_forks_count": null, "avg_line_length": 24.5263157895, "max_line_length": 103, "alphanum_fraction": 0.6008583691}
import axios from 'axios';
import Error from './Error';
import ScenarioNotFoundError from './ScenarioNotFoundError';

export default class Stub {

  constructor(host, port) {
    this.baseUri = `http://${host}:${port}`;
  }

  activate(scenarioName) {
    return axios.post(
      `${this.baseUri}/http_stub/scenarios/activate`,
      `name=${encodeURIComponent(scenarioName)}`,
      {
        headers: {
          'Content-Type': 'application/x-www-form-urlencoded'
        }
      }
    ).then((response) => {
      if (response.status !== 200) {
        throw new ScenarioNotFoundError(scenarioName);
      }
      return response;
    });
  }

  reset() {
    return axios.post(`${this.baseUri}/http_stub/stubs/reset`).then((response) => {
      if (response.status !== 200) {
        throw new Error(`Unable to reset stub memory.  Response: ${response.status} ${response.body}`);
      }
      return response;
    });
  }

}
