<commit_before>DEFAULT_API_VERSION = "5.50"
DEFAULT_WINDOW_STYLE = "popup"
REDIRECT_URI = "https%3A%2F%2Foauth.vk.com%2Fblank.html"


module.exports =

  version: DEFAULT_API_VERSION


  authUrl: ( appId, permissions, @version = DEFAULT_API_VERSION, windowStyle = DEFAULT_WINDOW_STYLE ) ->
    "https://oauth.vk.com/authorize?client_id=#{appId}&scope=#{permissions.join ','}&redirect_uri=#{REDIRECT_URI}&" +
    "display=#{windowStyle}&v=#{@version}&response_type=token"


  request: ( url, params, callback ) ->
    xhr = new XMLHttpRequest
    xhr.onload = ->
      callback JSON.parse @responseText

    serializedParams = ( "#{encodeURIComponent(key)}=#{encodeURIComponent(val)}" for own key, val of params ).join "&"
    xhr.open "POST", url
    xhr.send serializedParams


  method: ( methodName, params, callback = -> ) ->
    params.access_token = @accessToken
    params.v = @version

    new Promise ( resolve, reject ) =>
      @request "https://api.vk.com/method/#{methodName}", params, ({ error, response }) ->
        callback error, response
        if error?
          reject error
        else
          resolve response<commit_msg>fix(request): set `Content-Type` header, otherwise the api doesn't parse request body<commit_after>DEFAULT_API_VERSION = "5.50"
DEFAULT_WINDOW_STYLE = "popup"
REDIRECT_URI = "https%3A%2F%2Foauth.vk.com%2Fblank.html"


module.exports =

  version: DEFAULT_API_VERSION


  authUrl: ( appId, permissions, @version = DEFAULT_API_VERSION, windowStyle = DEFAULT_WINDOW_STYLE ) ->
    "https://oauth.vk.com/authorize?client_id=#{appId}&scope=#{permissions.join ','}&redirect_uri=#{REDIRECT_URI}&" +
    "display=#{windowStyle}&v=#{@version}&response_type=token"


  request: ( url, params, callback ) ->
    xhr = new XMLHttpRequest
    xhr.onload = ->
      callback JSON.parse @responseText

    serializedParams = ( "#{encodeURIComponent(key)}=#{encodeURIComponent(val)}" for own key, val of params ).join "&"
    xhr.open "POST", url
    xhr.setRequestHeader "Content-Type", "application/x-www-form-urlencoded"
    xhr.send serializedParams


  method: ( methodName, params, callback = -> ) ->
    params.access_token = @accessToken
    params.v = @version

    new Promise ( resolve, reject ) =>
      @request "https://api.vk.com/method/#{methodName}", params, ({ error, response }) ->
        callback error, response
        if error?
          reject error
        else
          resolve response
{'fraction_non_alphanumeric': 0.14017163874131588, 'fraction_numerical': 0.005721291377196567, 'mean_word_length': 3.7167630057803467, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 17, 'https://': 4, 'lorem ipsum': 0, 'www.': 1, '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': '868369', 'n_tokens_mistral': 796, 'n_tokens_neox': 774, 'n_words': 154}