       cb?() unless callbackAsync
 
   createClient: ->
-    token = atom.config.get 'sync-settings.personalAccessToken'
+    token = @getPersonalAccessToken()
     console.debug "Creating GitHubApi client with token = #{token}"
     github = new GitHubApi
       version: '3.0.0'

        content: (@fileContent atom.config.configDirPath + "/#{file}") ? "#{cmtstart} #{file} (not found) #{cmtend}"

    @createClient().gists.edit
      id: atom.config.get 'sync-settings.gistId'
      description: atom.config.get 'sync-settings.gistDescription'
      files: files
    , (err, res) ->


  serialize: ->

  getGistId: ->
    gistId = atom.config.get 'sync-settings.gistId'
    if gistId
      gistId = gistId.trim()
    return gistId

  getPersonalAccessToken: ->
    token = atom.config.get 'sync-settings.personalAccessToken'
    if token
      token = token.trim()
    return token

  checkMandatorySettings: ->
    missingSettings = []
    if not @getGistId()
      missingSettings.push("Gist ID")
    if not @getPersonalAccessToken()
      missingSettings.push("GitHub personal access token")
    if missingSettings.length
      @notifyMissingMandatorySettings(missingSettings)
    return missingSettings.length is 0

  checkForUpdate: (cb=null) ->
    if @getGistId()
      console.debug('checking latest backup...')
      @createClient().gists.get
        id: @getGistId()
      , (err, res) =>
        console.debug(err, res)
        if err
