-# types of githubs
+# types of github urls
 #
 # github.com
 #   gist.github.com/also/5794205

    ensure_access = (ctx, url) ->
      unless url?
        domain = github.default()
        instance = settings.get 'githubs', domain
      else
        instance = github.get_github url
        domain = url.hostname()
      if instance? and instance.requires_access_token and not instance.access_token?
        result = Q.defer()
        ctx.text 'Please set a GitHub access token:'
        input = ctx.input.text_input()
        button = ctx.input.button('Save')
        user_details = button.map(input).flatMapLatest (access_token) ->
          Bacon.combineTemplate
            user: Bacon.fromPromise http.get github.to_api_url(instance, '/user').setQuery {access_token}
            access_token: access_token
          .changes()
        user_details.onValue ({user, access_token}) =>
          global_settings.user_settings.set 'github', 'githubs', domain, 'access_token', access_token
          ctx.text "Logged in as #{user.name}"
          result.resolve url?.setQuery {access_token}
        user_details.onError =>


      save_gist: (gist, options={}) ->
        github_host = options.github ? github.default()
        gh = settings.get 'sites', github_host
        http.post github.to_api_url(gh, '/gists'), gist

      to_api_url: (site, path, params={}) ->
        result = URI("#{site.api_base_url}#{path}").setQuery(params)
        result.setQuery('access_token', site.access_token) if site.access_token?
        result

      to_gist_url: (gist) ->
