Created
November 23, 2014 02:46
-
-
Save ksin/41653c949b96a37178a8 to your computer and use it in GitHub Desktop.
Index Controller refactored
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
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