<commit_before>import assert from 'assert'
import util from 'util'
import { OAuth2 } from 'oauth'
import Request from 'request'

import Helpers from './helpers'
import StreamingAPIConnection from './streaming-api-connection'

import {
    STATUS_CODES_TO_ABORT_ON,
    DEFAULT_REST_ROOT,
    DEFAULT_REST_BASE,
    REQUIRED_KEYS_FOR_AUTH,
    DEFAULT_OAUTH_APPS_ENDPOINT
} from './settings'

class Mastodon {

    constructor(config) {
        this.apiUrl = config.api_url || DEFAULT_REST_ROOT

        Mastodon._validateConfigOrThrow(config)

        this.config = config
        this._mastodon_time_minus_local_time_ms = 0
    }

    get(path, params, callback) {
        return this.request('GET', path, params, callback)
    }

    post(path, params, callback) {
        return this.request('POST', path, params, callback)
    }

    delete(path, params, callback) {
        return this.request('DELETE', path, params, callback)
    }

    request(method, path, params, callback) {
        const self = this
        assert(method === 'GET' || method === 'POST' || method === 'DELETE')
        // if no `params` is specified but a callback is, use default params
        if (typeof params === 'function') {
            callback = params
            params = {}
        }

        return new Promise((resolve, reject) => {
            const _returnErrorToUser = (err) => {
                if (callback && typeof callback === 'function') {
                    callback(err, null, null)
                }
                reject(err)
            }

            self._buildRequestOptions(method, path, params, (err, requestOptions) => {
                if (err) {
                    _returnErrorToUser(err)
                    return
                }

                const mastodonOptions = (params && params.masto_options) || {}

                process.nextTick(() => {<commit_msg>Allow PATCH and PUT as HTTP methods<commit_after>import assert from 'assert'
import util from 'util'
import { OAuth2 } from 'oauth'
import Request from 'request'

import Helpers from './helpers'
import StreamingAPIConnection from './streaming-api-connection'

import {
    STATUS_CODES_TO_ABORT_ON,
    DEFAULT_REST_ROOT,
    DEFAULT_REST_BASE,
    REQUIRED_KEYS_FOR_AUTH,
    DEFAULT_OAUTH_APPS_ENDPOINT
} from './settings'

class Mastodon {

    constructor(config) {
        this.apiUrl = config.api_url || DEFAULT_REST_ROOT

        Mastodon._validateConfigOrThrow(config)

        this.config = config
        this._mastodon_time_minus_local_time_ms = 0
    }

    get(path, params, callback) {
        return this.request('GET', path, params, callback)
    }

    patch(path, params, callback) {
        return this.request('PATCH', path, params, callback)
    }

    post(path, params, callback) {
        return this.request('POST', path, params, callback)
    }

    put(path, params, callback) {
        return this.request('PUT', path, params, callback)
    }

    delete(path, params, callback) {
        return this.request('DELETE', path, params, callback)
    }

    request(method, path, params, callback) {
        const self = this
        assert(method === 'GET' || method === 'PATCH' || method === 'POST' || method === 'PUT' || method === 'DELETE')
        // if no `params` is specified but a callback is, use default params
        if (typeof params === 'function') {
            callback = params
            params = {}
        }

        return new Promise((resolve, reject) => {
            const _returnErrorToUser = (err) => {
                if (callback && typeof callback === 'function') {
                    callback(err, null, null)
                }
                reject(err)
            }

            self._buildRequestOptions(method, path, params, (err, requestOptions) => {
                if (err) {
                    _returnErrorToUser(err)
                    return
                }

                const mastodonOptions = (params && params.masto_options) || {}

                process.nextTick(() => {
{'fraction_non_alphanumeric': 0.1110009910802775, 'fraction_numerical': 0.0009910802775024777, 'mean_word_length': 2.146531566640686, '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': '5648019', 'n_tokens_mistral': 1157, 'n_tokens_neox': 1098, 'n_words': 284}