Skip to content

Instantly share code, notes, and snippets.

@patmood
Last active December 28, 2015 18:38
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save patmood/7544249 to your computer and use it in GitHub Desktop.
Save patmood/7544249 to your computer and use it in GitHub Desktop.
Ember app with Imgur API
<!DOCTYPE html>
<html>
<head>
<meta charset=utf-8 />
<title>JS Bin</title>
<script src="http://code.jquery.com/jquery-2.0.2.js"></script>
<script src="http://builds.emberjs.com/handlebars-1.0.0.js"></script>
<script src="http://builds.emberjs.com/ember-latest.js"></script>
</head>
<body>
<script type="text/x-handlebars" data-template-name="application">
<h1>ember-latest jsbin</h1>
{{outlet}}
</script>
<script type="text/x-handlebars" data-template-name="index">
<h2>Index Content:</h2>
<img {{bindAttr src="model.link"}}>
</script>
</body>
</html>
App = Ember.Application.create({});
App.IndexRoute = Ember.Route.extend({
model: function(){
return App.Item.all();
}
});
App.Item = Ember.Object.extend({});
App.Item.reopenClass({
all: function() {
return $.ajax({
url: 'https://api.imgur.com/3/image/bvXuubg',
headers: {
'Authorization': 'Client-ID 2b577f722a2e8e9'
},
type: 'GET',
success: function(imgData) {
return imgData.data;
},
error: function(){
alert('oh noez!');
}
}).then(function(response) {
return App.Item.create(response.data);
});
}
});
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment