<commit_before>angular.module('oauth.rally', ['oauth.utils'])
  .factory('$ngCordovaRally', rally);

function rally($q, $http, $cordovaOauthUtility) {
  return { signin: oauthRally };

  /*
   * Sign into the Rally service
   *
   * @param    string clientId
   * @param    string clientSecret
   * @param    string appScope
   * @param    object options
   * @return   promise
   */
  function oauthRally(clientId, clientSecret, appScope, options) {
    var deferred = $q.defer();
    if(window.cordova) {
        if($cordovaOauthUtility.isInAppBrowserInstalled()) {
          var redirect_uri = "http://localhost/callback";
          if(options !== undefined) {
            if(options.hasOwnProperty("redirect_uri")) {
              redirect_uri = options.redirect_uri;
            }
          }
          var browserRef = window.cordova.InAppBrowser.open('https://rally1.rallydev.com/login/oauth2/auth?client_id=' + clientId + '&redirect_uri=' + redirect_uri + '&scope=' + appScope + '&response_type=code', '_blank', 'location=no,clearsessioncache=yes,clearcache=yes');
          browserRef.addEventListener('loadstart', function(event) {
            if((event.url).indexOf("http://localhost/callback") === 0) {
              requestToken = (event.url).split("code=")[1];
              $http.defaults.headers.post['Content-Type'] = 'application/x-www-form-urlencoded';
              $http({method: "post", url: "https://rally1.rallydev.com/login/oauth2/auth", data: "client_id=" + clientId + "&client_secret=" + clientSecret + "&redirect_uri=" + redirect_uri + "&grant_type=authorization_code" + "&code=" + requestToken })
                .success(function(data) {
                  deferred.resolve(data);
                })
                .error(function(data, status) {
                  deferred.reject("Problem authenticating");
                })
                .finally(function() {
                  setTimeout(function() {
                    browserRef.close();
                  }, 10);
                });
            }
          });
          browserRef.addEventListener('exit', function(event) {
            deferred.reject("The sign in flow was canceled");
          });
        } else {
          deferred.reject("Could not find InAppBrowser plugin");
        }
    } else {
      deferred.reject("Cannot authenticate via a web browser");
    }

    return deferred.promise;
  }
}

rally.$inject = ['$q', '$http', '$cordovaOauthUtility'];<commit_msg>IIFE rally<commit_after>(function() {
  'use strict';

  angular.module('oauth.rally', ['oauth.utils'])
    .factory('$ngCordovaRally', rally);

  function rally($q, $http, $cordovaOauthUtility) {
    return { signin: oauthRally };

    /*
     * Sign into the Rally service
     *
     * @param    string clientId
     * @param    string clientSecret
     * @param    string appScope
     * @param    object options
     * @return   promise
     */
    function oauthRally(clientId, clientSecret, appScope, options) {
      var deferred = $q.defer();
      if(window.cordova) {
          if($cordovaOauthUtility.isInAppBrowserInstalled()) {
            var redirect_uri = "http://localhost/callback";
            if(options !== undefined) {
              if(options.hasOwnProperty("redirect_uri")) {
                redirect_uri = options.redirect_uri;
              }
            }
            var browserRef = window.cordova.InAppBrowser.open('https://rally1.rallydev.com/login/oauth2/auth?client_id=' + clientId + '&redirect_uri=' + redirect_uri + '&scope=' + appScope + '&response_type=code', '_blank', 'location=no,clearsessioncache=yes,clearcache=yes');
            browserRef.addEventListener('loadstart', function(event) {
              if((event.url).indexOf("http://localhost/callback") === 0) {
                requestToken = (event.url).split("code=")[1];
                $http.defaults.headers.post['Content-Type'] = 'application/x-www-form-urlencoded';
                $http({method: "post", url: "https://rally1.rallydev.com/login/oauth2/auth", data: "client_id=" + clientId + "&client_secret=" + clientSecret + "&redirect_uri=" + redirect_uri + "&grant_type=authorization_code" + "&code=" + requestToken })
                  .success(function(data) {
                    deferred.resolve(data);
                  })
                  .error(function(data, status) {
                    deferred.reject("Problem authenticating");
                  })
                  .finally(function() {
                    setTimeout(function() {
                      browserRef.close();
                    }, 10);
                  });
              }
            });
            browserRef.addEventListener('exit', function(event) {
              deferred.reject("The sign in flow was canceled");
            });
          } else {
            deferred.reject("Could not find InAppBrowser plugin");
          }
      } else {
        deferred.reject("Cannot authenticate via a web browser");
      }

      return deferred.promise;
    }
  }

  rally.$inject = ['$q', '$http', '$cordovaOauthUtility'];
})();
{'fraction_non_alphanumeric': 0.14353126228863547, 'fraction_numerical': 0.0031458906802988595, 'mean_word_length': 2.1913425345043915, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 3, 'https://': 4, 'lorem ipsum': 0, 'www.': 2, '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': '722816', 'n_tokens_mistral': 1458, 'n_tokens_neox': 1421, 'n_words': 239}