Skip to content

Instantly share code, notes, and snippets.

@wayne-o
Created November 12, 2015 17:32
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 wayne-o/7ae989515e1c63d84f2d to your computer and use it in GitHub Desktop.
Save wayne-o/7ae989515e1c63d84f2d to your computer and use it in GitHub Desktop.
import Ember from 'ember';
import ajax from 'ic-ajax';
var inject = Ember.inject;
export default Ember.Service.extend({
sonatribeSession: inject.service(),
getSearchSuggestons(session, term, eid){
return this._getSuggestionsHash(term, eid)
.then((hash) => {
return Ember.run(function(){
return {
locations: hash.locations.locations,
listingEvents: hash.listingEvents.ListingEvents
};
});
});
},
_getSuggestionsHash(term, eid){
var _this = this;
let applicationConfig = this.container.lookupFactory('config:environment');
return Ember.RSVP.hash({
locations: ajax(
{
beforeSend: function(jqXHR) {
_this.beforeSend(jqXHR);
},
url: applicationConfig.sonatribe.apiUrl + '/api/v1/locations/search?term=' + term + '&eventInstanceId=' + eid
}),
listingEvents: ajax({
beforeSend: function(jqXHR) {
_this.beforeSend(jqXHR);
},
url: applicationConfig.sonatribe.apiUrl + '/api/v1/listingevents/search?term=' + term + '&eventInstanceId=' + eid
})
});
},
beforeSend: function(jqXHR) {
var session = this.get('sonatribeSession.session');
var accessToken = this.get('sonatribeSession.accessToken');
if (session.get('isAuthenticated') && !Ember.isEmpty(accessToken)) {
jqXHR.setRequestHeader('x-access-token', accessToken);
}
}
});
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment