Skip to content

Instantly share code, notes, and snippets.

@juandazapata
Last active December 13, 2015 21:38
Show Gist options
  • Save juandazapata/4978357 to your computer and use it in GitHub Desktop.
Save juandazapata/4978357 to your computer and use it in GitHub Desktop.
# Include the authorization tokens if we're issuing an API request.
# By doing this, we can call the API and the system will include the authorization headers for us.
# http://api.jquery.com/jQuery.ajaxPrefilter/
$.ajaxPrefilter (options, originalOptions, xhr) ->
is_request_to_api = (options.url.indexOf('<%= Settings.API.URL %>') == 0)
if is_request_to_api
xhr.setRequestHeader('Authorization', "Token token=\"<%= Settings.API.TOKEN %>\", signature=\"<%= Settings.API.SIGNATURE %>\", timestamp=\"<%= Settings.API.TIMESTAMP %>\"")
return
# Get the user location using our API
$.ajax(
url: "<%= Settings.API.URL %>/cities/geocode.json?latitude=#{@latitude}&longitude=#{@longitude}"
).success( (data) =>
console.log data
).error( =>
console.log 'error'
)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment