<commit_before>import request from "superagent/lib/client";
import saPrefix from "superagent-prefix";
import { TILEHOSTING_API_KEY } from "./constants/App";
import { OFDB_API, TH_GEOCODER, NOMINATIM } from "./constants/URLs"
import CATEGORY_IDS from "./constants/Categories";

const prefix = saPrefix(OFDB_API.link);

const jsonCallback = (cb) => (err, res) => {
  if (err) {
    cb(err);
  } else {
    cb(null, res.body);
  }
};

module.exports = {

  searchEntries: (txt, cats, bbox, cb) => {

    if (txt == null) {
      txt = '';
    }
    if (cats == null) {
      cats = [];
    }
    if (bbox == null) {
      bbox = [];
    }

    request
      .get('/search')
      .use(prefix)
      .query({
        text: txt.trim()
      })
      .query((cats.length > 0) ? ('categories=' + cats.join(',')) : "")
      .query('bbox=' + bbox.join(','))
      .set('Accept', 'application/json')
      .end(jsonCallback(cb));
  },

  searchEvents: (tags, bbox, start, end, cb) => { 
    let req = request
      .get('/events')
      .use(prefix)
      .set('Accept', 'application/json');
    if(bbox && bbox.length > 0) req.query('bbox=' + bbox.join(','))
    if(tags && tags.length > 0) req.query('tags=' + tags) // TODO
    if(start) req.query(start ? ('start=' + start) : "")
    if(end) req.query(end ? ('end=' + end) : "")

    req.end(jsonCallback(cb));
  },

  getEvent: (id, cb) => {
    request
      .get('/events/' + id)
      .use(prefix)
      .set('Accept', 'application/json')<commit_msg>fix(events): set correct query parameters<commit_after>import request from "superagent/lib/client";
import saPrefix from "superagent-prefix";
import { TILEHOSTING_API_KEY } from "./constants/App";
import { OFDB_API, TH_GEOCODER, NOMINATIM } from "./constants/URLs"
import CATEGORY_IDS from "./constants/Categories";

const prefix = saPrefix(OFDB_API.link);

const jsonCallback = (cb) => (err, res) => {
  if (err) {
    cb(err);
  } else {
    cb(null, res.body);
  }
};

module.exports = {

  searchEntries: (txt, cats, bbox, cb) => {

    if (txt == null) {
      txt = '';
    }
    if (cats == null) {
      cats = [];
    }
    if (bbox == null) {
      bbox = [];
    }

    request
      .get('/search')
      .use(prefix)
      .query({
        text: txt.trim()
      })
      .query((cats.length > 0) ? ('categories=' + cats.join(',')) : "")
      .query('bbox=' + bbox.join(','))
      .set('Accept', 'application/json')
      .end(jsonCallback(cb));
  },

  searchEvents: (tags, bbox, start, end, cb) => { 
    let req = request
      .get('/events')
      .use(prefix)
      .set('Accept', 'application/json');
    if(bbox && bbox.length > 0) req.query('bbox=' + bbox.join(','))
    if(tags && tags.length > 0) req.query('tags=' + tags) // TODO
    if(start) req.query(start ? ('start_min=' + start) : "")
    if(end) req.query(end ? ('start_max=' + end) : "")

    req.end(jsonCallback(cb));
  },

  getEvent: (id, cb) => {
    request
      .get('/events/' + id)
      .use(prefix)
      .set('Accept', 'application/json')
{'fraction_non_alphanumeric': 0.20468029004614371, 'fraction_numerical': 0.001977587343441002, 'mean_word_length': 2.574793875147232, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 19, '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': '4687706', 'n_tokens_mistral': 1100, 'n_tokens_neox': 1079, 'n_words': 225}