Last active
August 29, 2015 14:01
-
-
Save morenoh149/bf4620c99b2690cf04ec to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
'use strict'; | |
app.factory('Gapi', ['$q', function($q) { | |
function makeRequest() { | |
var request = gapi.client.urlshortener.url.get({ | |
'shortUrl': 'http://goo.gl/fbsS' | |
}); | |
request.execute(function(response) { | |
appendResults(response.longUrl); | |
}); | |
console.log('inside make request'); | |
} | |
function appendResults(text) { | |
var results = document.getElementById('results'); | |
results.appendChild(document.createElement('P')); | |
results.appendChild(document.createTextNode(text)); | |
} | |
function load() { | |
gapi.client.setApiKey(''); | |
gapi.client.load('urlshortener', 'v1', makeRequest); | |
} | |
return { | |
loadgoogle: function() { | |
var q = $q.defer(); | |
while (!gapi.client) { | |
setTimeout(this(), 1000); | |
} | |
q.resolve(load()); | |
return q.promise; | |
} | |
}; | |
}]); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment