<commit_before>import 'isomorphic-fetch';
import Promise from 'bluebird';
import * as queryString from 'query-string';

export default class UserService {
  constructor(options) {
    if (!options) {
      throw new Error('options params is required.');
    }
    if (!options.apiURL || options.apiURL === '') {
      throw new Error('options.apiURL param is required.');
    }
    this.opts = options;
  }

  /**
   * Gets the user that is currently logged
   * @returns {Promise}
   */
  getLoggedUser(token) {
    return new Promise((resolve) => {
      fetch(`${this.opts.apiURL}/auth/check-logged`, {
        headers: {
          Authorization: token,
          'Upgrade-Insecure-Requests': 1
        }
      })
        .then(response => resolve(response.json()));
    });
  }

  /**
  * Updates the user that is currently logged in
  */
  updateUser(user, token) {
    return fetch(`${this.opts.apiURL}/auth/user/me`, {
      method: 'PATCH',
      body: JSON.stringify(user),
      headers: {
        'Content-Type': 'application/json',
        Authorization: token
      }
    })
      .then(response => response.json());
  }

  /**
   * Register a new user based on email + password combination
   */
  registerUser({ email, password, repeatPassword }) {
    return fetch(`${this.opts.apiURL}/auth/sign-up`, {
      method: 'POST',
      body: JSON.stringify({ email, password, repeatPassword }),
      headers: { 'Content-Type': 'application/json' }
    })
      .then((response) => {
        if (response.ok) return response.json();
        throw response;
      });
  }

  /**
   * Logs in a user based on email + password combination
   */
  loginUser({ email, password }) {<commit_msg>Adds apps property to register user call<commit_after>import 'isomorphic-fetch';
import Promise from 'bluebird';
import * as queryString from 'query-string';

export default class UserService {
  constructor(options) {
    if (!options) {
      throw new Error('options params is required.');
    }
    if (!options.apiURL || options.apiURL === '') {
      throw new Error('options.apiURL param is required.');
    }
    this.opts = options;
  }

  /**
   * Gets the user that is currently logged
   * @returns {Promise}
   */
  getLoggedUser(token) {
    return new Promise((resolve) => {
      fetch(`${this.opts.apiURL}/auth/check-logged`, {
        headers: {
          Authorization: token,
          'Upgrade-Insecure-Requests': 1
        }
      })
        .then(response => resolve(response.json()));
    });
  }

  /**
  * Updates the user that is currently logged in
  */
  updateUser(user, token) {
    return fetch(`${this.opts.apiURL}/auth/user/me`, {
      method: 'PATCH',
      body: JSON.stringify(user),
      headers: {
        'Content-Type': 'application/json',
        Authorization: token
      }
    })
      .then(response => response.json());
  }

  /**
   * Register a new user based on email + password combination
   */
  registerUser({ email, password, repeatPassword }) {
    return fetch(`${this.opts.apiURL}/auth/sign-up`, {
      method: 'POST',
      body: JSON.stringify({
        email,
        password,
        repeatPassword,
        apps: ['rw']
      }),
      headers: { 'Content-Type': 'application/json' }
    })
      .then((response) => {
        if (response.ok) return response.json();
        throw response;
      });
  }

  /**
   * Logs in a user based on email + password combination
   */
  loginUser({ email, password }) {
{'fraction_non_alphanumeric': 0.14782858786310038, 'fraction_numerical': 0.0005752085130859936, 'mean_word_length': 2.4198623402163224, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 11, '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': '5360388', 'n_tokens_mistral': 1020, 'n_tokens_neox': 1016, 'n_words': 254}