module Github::Connection

def caching?

def caching?
  !@connection.nil?
end

def clear_cache

def clear_cache
  @connection = nil
end

def connection(options={})


Returns a Fraday::Connection object
def connection(options={})
  conn_options = default_options(options)
  clear_cache unless options.empty?
  puts "OPTIONS:#{conn_options.inspect}" if ENV['DEBUG']
  @connection ||= Faraday.new(conn_options.merge(:builder => stack(options)))
end

def default_middleware(options={})


configuration stage.
Default middleware stack that uses default adapter as specified at
def default_middleware(options={})
  Proc.new do |builder|
    builder.use Github::Request::Jsonize
    builder.use Faraday::Request::Multipart
    builder.use Faraday::Request::UrlEncoded
    builder.use Github::Request::OAuth2, oauth_token if oauth_token?
    builder.use Github::Request::BasicAuth, authentication if basic_authed?
    builder.use Faraday::Response::Logger if ENV['DEBUG']
    unless options[:raw]
      builder.use Github::Response::Mashify
      builder.use Github::Response::Jsonize
    end
    builder.use Github::Response::RaiseError
    builder.adapter adapter
  end
end

def default_options(options={})

def default_options(options={})
  {
    :headers => {
      ACCEPT           => "application/vnd.github.v3.full+json," \
                          "application/vnd.github.beta.full+json;q=0.7," \
                          "application/vnd.github+json;q=0.5," \
                          "application/json;q=0.1",
      ACCEPT_CHARSET   => "utf-8",
      USER_AGENT       => user_agent,
      CONTENT_TYPE     => 'application/json'
    },
    :ssl => options.fetch(:ssl) { ssl },
    :url => options.fetch(:endpoint) { Github.endpoint }
  }.merge(options)
end

def stack(options={}, &block)


addition of new extensions such as cache adapter.
Exposes middleware builder to facilitate custom stacks and easy
def stack(options={}, &block)
  @stack ||= begin
    if block_given?
      Faraday::Builder.new(&block)
    else
      Faraday::Builder.new(&default_middleware(options))
    end
  end
end