Skip to content

Instantly share code, notes, and snippets.

@jwendell
Created April 1, 2016 16:04
Show Gist options
  • Save jwendell/b3d90177932347efafae4b1c6d7b9b08 to your computer and use it in GitHub Desktop.
Save jwendell/b3d90177932347efafae4b1c6d7b9b08 to your computer and use it in GitHub Desktop.
getting an avatar url from github (run with 'gjs' interpreter)
const Soup = imports.gi.Soup;
const Mainloop = imports.mainloop;
let _httpSession = new Soup.Session({user_agent: 'curl/7.43.0'});
let url = 'https://api.github.com/users/jwendell';
let message = new Soup.Message({method: 'GET', uri: new Soup.URI(url)});
_httpSession.queue_message(message, function(session, message) {
if (message.status_code != Soup.KnownStatusCode.OK) {
log('Error: ' + message.status_code.toString());
log('got: ' + message.response_body.data);
} else {
// log('got: ' + message.response_body.data);
let p = JSON.parse(message.response_body.data);
log('Avatar URL: ' + p.avatar_url);
}
Mainloop.quit('t');
});
Mainloop.run('t');
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment