<commit_before>ERROR_TOO_MANY_REQUESTS = 6


module.exports =

  version: "5.50"


  getAuthUrl: ( @appId = @appId, permissions = [], {
    @version = @version
    windowStyle = "popup"
    redirectUrl = "https://oauth.vk.com/blank.html"
  } = {}) ->
    "https://oauth.vk.com/authorize?client_id=#{@appId}&scope=#{permissions.join ','}&redirect_uri=#{encodeURIComponent redirectUrl}&" +
    "display=#{windowStyle}&v=#{@version}&response_type=token"


  authWebsite: ( appId, permissions, windowStyle = "popup", callback = -> ) ->
    new Promise ( resolve, reject ) =>
      @getAccessToken appId
      .then ( accessToken ) ->
        if accessToken
          callback accessToken
          resolve accessToken

        else
          authUrl = @getAuthUrl appId, permissions,
            windowStyle: windowStyle
            redirectUrl: "close.html"

          popup = window.open authUrl

          intervalHandler = window.setInterval =>
            if popup.closed
              window.clearInterval intervalHandler

              @getAccessToken appId
              .then ( accessToken ) ->
                callback accessToken
                resolve accessToken

          , 100

  getAccessToken: ( @appId = @appId, callback = -> ) ->
    new Promise ( resolve, reject ) =>
      @request<commit_msg>fix(authWebsite): preserve context throughout the method<commit_after>ERROR_TOO_MANY_REQUESTS = 6


module.exports =

  version: "5.50"


  getAuthUrl: ( @appId = @appId, permissions = [], {
    @version = @version
    windowStyle = "popup"
    redirectUrl = "https://oauth.vk.com/blank.html"
  } = {}) ->
    "https://oauth.vk.com/authorize?client_id=#{@appId}&scope=#{permissions.join ','}&redirect_uri=#{encodeURIComponent redirectUrl}&" +
    "display=#{windowStyle}&v=#{@version}&response_type=token"


  authWebsite: ( appId, permissions, windowStyle = "popup", callback = -> ) ->
    new Promise ( resolve, reject ) =>
      @getAccessToken appId
      .then ( accessToken ) =>
        if accessToken
          callback accessToken
          resolve accessToken

        else
          authUrl = @getAuthUrl appId, permissions,
            windowStyle: windowStyle
            redirectUrl: "close.html"

          popup = window.open authUrl

          intervalHandler = window.setInterval =>
            if popup.closed
              window.clearInterval intervalHandler

              @getAccessToken appId
              .then ( accessToken ) ->
                callback accessToken
                resolve accessToken

          , 100

  getAccessToken: ( @appId = @appId, callback = -> ) ->
    new Promise ( resolve, reject ) =>
      @request
{'fraction_non_alphanumeric': 0.11736032995875516, 'fraction_numerical': 0.005249343832020997, 'mean_word_length': 2.3060718711276333, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 23, 'https://': 4, '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': '5471733', 'n_tokens_mistral': 775, 'n_tokens_neox': 731, 'n_words': 154}