<commit_before>'use strict';

import _ from 'lodash';
import request from 'superagent';
import AppActions from '../actions/AppActions';

import {
  POSTS_REQUEST_GET_COMPLETE,
  POSTS_REQUEST_GET_SUCCESS,
  POSTS_REQUEST_GET_ERROR,
  SINGLE_POST_REQUEST_GET_COMPLETE,
  SINGLE_POST_REQUEST_GET_SUCCESS,
  SINGLE_POST_REQUEST_GET_ERROR
} from '../constants/AppConstants';

let endpoint = 'http://localhost:9000';

let exampleNews = require('../data/example-news.json');
let exampleComments = require('../data/example-comments.json');

class API {

  getNews(opts) {

    return new Promise((resolve, reject) => {

      if (process.env.NODE_ENV !== 'production') {
        console.info('Serving mocked data for WebAPI.getNews()');
        return setTimeout(resolve.bind(null, exampleNews.news), 600);
      }

      opts = _.merge({
        sort: 'latest',
        start: 0,
        count: 30
      }, opts);

      let url = [endpoint, 'list'].concat(_.values(opts)).join('/');

      request
      .get(url)
      .set('Accept', 'application/json')
      .end((err, res) => {
        if (err) { return reject(err); }
        resolve(res.body.news);
      });
    });
  }

  getPost(postId) {

    return new Promise((resolve, reject) => {

      if (process.env.NODE_ENV !== 'production') {
        console.info('Serving mocked data for WebAPI.getPost()');
        return setTimeout(resolve.bind(null, {
          post: {},
          comments: exampleComments
        }), 600);
      }

      let url = [endpoint, 'comments', postId].join('/');

      request
      .get(url)
      .set('Accept', 'application/json')
      .end((err, res) => {
        if (err) { return reject(err); }
        resolve({
          post: {},
          comments: res.body
        });
      });
    });
  }
}

export default new API();
<commit_msg>Using remote API, it's working!!<commit_after>'use strict';

import _ from 'lodash';
import request from 'superagent';
import AppActions from '../actions/AppActions';

import {
  POSTS_REQUEST_GET_COMPLETE,
  POSTS_REQUEST_GET_SUCCESS,
  POSTS_REQUEST_GET_ERROR,
  SINGLE_POST_REQUEST_GET_COMPLETE,
  SINGLE_POST_REQUEST_GET_SUCCESS,
  SINGLE_POST_REQUEST_GET_ERROR
} from '../constants/AppConstants';

let endpoint = 'http://echojs-api.proxima.cc';

let exampleNews = require('../data/example-news.json');
let exampleComments = require('../data/example-comments.json');

class API {

  getNews(opts) {

    return new Promise((resolve, reject) => {

      // if (process.env.NODE_ENV !== 'production') {
      //   console.info('Serving mocked data for WebAPI.getNews()');
      //   return setTimeout(resolve.bind(null, exampleNews.news), 600);
      // }

      opts = _.merge({
        sort: 'latest',
        start: 0,
        count: 30
      }, opts);

      let url = [endpoint, 'list'].concat(_.values(opts)).join('/');

      request
      .get(url)
      .set('Accept', 'application/json')
      .end((err, res) => {
        if (err) { return reject(err); }
        resolve(res.body.news);
      });
    });
  }

  getPost(postId) {

    return new Promise((resolve, reject) => {

      // if (process.env.NODE_ENV !== 'production') {
      //   console.info('Serving mocked data for WebAPI.getPost()');
      //   return setTimeout(resolve.bind(null, {
      //     post: {},
      //     comments: exampleComments
      //   }), 600);
      // }

      let url = [endpoint, 'comments', postId].join('/');

      request
      .get(url)
      .set('Accept', 'application/json')
      .end((err, res) => {
        if (err) { return reject(err); }
        resolve({
          post: {},
          comments: res.body
        });
      });
    });
  }
}

export default new API();

{'fraction_non_alphanumeric': 0.16150740242261102, 'fraction_numerical': 0.0059219380888290716, 'mean_word_length': 2.469654528478058, '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': '2595606', 'n_tokens_mistral': 1205, 'n_tokens_neox': 1153, 'n_words': 236}