Skip to content

Instantly share code, notes, and snippets.

@ksin
Created November 23, 2014 02:46
Show Gist options
  • Save ksin/41653c949b96a37178a8 to your computer and use it in GitHub Desktop.
Save ksin/41653c949b96a37178a8 to your computer and use it in GitHub Desktop.
Index Controller refactored
import Ember from 'ember';
export default Ember.Controller.extend({
tag: null,
displayMessage: null,
searchResults: null,
count: 10,
instagramApiClient: null, // injected
actions: {
queryInstagram: function() {
if (!this.get('tag')) {
this.set('displayMessage', "Please enter a hashtag.");
return;
}
var options = {
count: this.get('count') || 10
};
var self = this;
var apiCall = this.instagramApiClient.recentMediaForTag(this.get('tag'), options);
apiCall.then(function(response) {
if (!response.data) {
self.set('displayMessage', "Your search yielded no results.");
return;
}
self.set('displayMessage', "Check out these images!");
self.set('searchResults', response.data);
});
apiCall.catch(function() {
self.set('displayMessage', "Instagram failed to find images within 10 seconds or returned an error.");
});
}
}
});
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment