tshm
7/11/2014 - 2:36 AM

angular-coget.js

  app.factory('Coget', function( $http ) {
    var getViaYql = function( url ) {
      var proxy = 'http://whateverorigin.org/get?url=' + encodeURIComponent( url ) + '&callback=JSON_CALLBACK';
      var p = $http.jsonp( proxy, { cache: true }).then(function( resp ) {
        resp.data = resp.data.contents;
        return resp;
      });
      p.success = function( fn ) {
        this.then(function( resp ) {
          return fn( resp.data );
        });
      };
      return p;
    };
    return { get: getViaYql };
  });