<commit_before>require!<[http winston]>

set-default-opts = (opts) ->
    if not opts?
        opts = {}

    if not opts._api_prefix?
        opts._host = \uhunt.felix-halim.net
        opts._port = 80
        opts._api_prefix = \/api

    opts

get-req-opts = (query, opts) ->
    do
        hostname: opts._host
        path: opts._api_prefix ++ query
        port: 80


module.exports.get-uid-by-name = (name, opts, callback) ->
    winston.info 'get-uid-by-name: name = %s' name

    opts = set-default-opts opts
    req-opts = get-req-opts \/uname2uid/ ++ name, opts

    req = http.request req-opts, (res) ->
        res.on \data (data) ->
            callback null, data.toString!

    req.on \error (err) ->
        callback err, null

    req.end!<commit_msg>Use _inject-config to do dependency injection<commit_after>require!<[http winston]>

config = do
    hostname: \uhunt.felix-halim.net
    port: 80
    path: \/api

module.exports._inject-config = (new-config) ->
    config <<< new-config

get-req-opts = (query, opts) ->
    do
        hostname: config.hostname
        port: config.port
        path: config.path ++ query


module.exports.get-uid-by-name = (name, opts, callback) ->
    winston.info 'get-uid-by-name: name = %s' name

    opts = set-default-opts opts
    req-opts = get-req-opts \/uname2uid/ ++ name, opts

    req = http.request req-opts, (res) ->
        res.on \data (data) ->
            callback null, data.toString!

    req.on \error (err) ->
        callback err, null

    req.end!
{'fraction_non_alphanumeric': 0.14145383104125736, 'fraction_numerical': 0.005239030779305829, 'mean_word_length': 2.074446680080483, 'pattern_counts': {'":': 0, '<': 8, '<?xml version=': 0, '>': 17, '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': '3989212', 'n_tokens_mistral': 537, 'n_tokens_neox': 517, 'n_words': 126}