<commit_before>import Rx from 'rx'
import request from 'superagent'

let fromSuperagent = request => Rx.Observable.create(obs => {
  request.end((err, res) => {
    if (err) {
      obs.onError(err)
    } else {
      obs.onNext(res)
    }
    obs.onCompleted()
  })

  return () => request.abort()
})

export function makeAPIRequest ({
  token,
  method,
  query,
  httpMethod = 'POST'
}) {
  let endpoint = `https://api.telegram.org/bot${token}`
  let url = `${endpoint}/${method}`
  let req = request(httpMethod, url)
    .redirects(0)
    .send(query)

  return fromSuperagent(req)
    .catch(e => Rx.Observable.throw(e instanceof Error ? e : new Error(e)))
    .map(res => res.body)
    .map(
      body => body.ok ? Rx.Observable.just(body.result)
        : Rx.Observable.throw(new Error(body)))
    .switch()
}<commit_msg>refactor(api-request): change `Rx.Observable` to `$`<commit_after>import { Observable as $ } from 'rx'
import request from 'superagent'

let fromSuperagent = request => $.create(obs => {
  request.end((err, res) => {
    if (err) {
      obs.onError(err)
    } else {
      obs.onNext(res)
    }
    obs.onCompleted()
  })

  return () => request.abort()
})

export function makeAPIRequest ({
  token,
  method,
  query,
  httpMethod = 'POST'
}) {
  let endpoint = `https://api.telegram.org/bot${token}`
  let url = `${endpoint}/${method}`
  let req = request(httpMethod, url)
    .redirects(0)
    .send(query)

  return fromSuperagent(req)
    .catch(e => $.throw(e instanceof Error ? e : new Error(e)))
    .map(res => res.body)
    .map(
      body => body.ok ? $.just(body.result)
        : $.throw(new Error(body)))
    .switch()
}
{'fraction_non_alphanumeric': 0.1722689075630252, 'fraction_numerical': 0.0012004801920768306, 'mean_word_length': 2.940898345153664, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 17, 'https://': 2, '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': '5431053', 'n_tokens_mistral': 587, 'n_tokens_neox': 584, 'n_words': 125}