   , delay
 
 loader = (apiEventChannel, settings) ->
+  apiEventChannel.on 'set.access_token', (token) ->
+    API_ACCESS_TOKEN = token
 
   _.each settings.endpoints, (setting, eventName) ->
     apiEventChannel.on eventName, _.partial(handleAPIEvent, apiEventChannel, settings.baseUrl or setting.baseUrl, setting)


METHODS_WITH_DATA = ['PUT', 'PATCH', 'POST']


defaultFail = (response) ->
  console.info(response)

    apiSetting.url = "#{interpolate(apiSetting.url, data)}/#{apiSetting.method}.json"
    apiSetting.method = 'GET'
  else
    if API_ACCESS_TOKEN
      apiSetting.transformRequest = axios.defaults.transformRequest.concat( (data, headers) ->
        headers['Authorization'] = "Bearer #{API_ACCESS_TOKEN}"
      )
    else if setting.useCredentials
      apiSetting.withCredentials = true
    apiSetting.url = "#{baseUrl}/#{interpolate(apiSetting.url, data)}"

  apiSetting
