Sha256: 6b600e6da36119e0b1b1046c31e7b88bd310f0a41cb4dfcc39e6a9fa2bfb5043

Contents?: true

Size: 1.8 KB

Versions: 1

Compression:

Stored size: 1.8 KB

Contents

# encoding: utf-8

require 'faraday'
require 'github_api/response'
require 'github_api/response/mashify'
require 'github_api/response/jsonize'
require 'github_api/response/raise_error'
require 'github_api/request/oauth2'
require 'github_api/request/basic_auth'

module Github
  module Connection

  private

    def header_options() # :nodoc:
      {
        :headers => {
          'Accept'       => '*/*', #accepts,
          'User-Agent'   => user_agent,
          'Content-Type' => 'application/x-www-form-urlencoded'
        },
        :ssl => { :verify => false },
        :url => endpoint
      }
    end

    def clear_cache # :nodoc:
      @connection = nil
    end

    def caching? # :nodoc:
      !@connection.nil?
    end

    def connection(options = {}) # :nodoc:

      # parse(options['resource'], options['mime_type'] || mime_type) if options['mime_type']
      debugger

      merged_options = if connection_options.empty?
        header_options
      else
        connection_options.merge(header_options)
      end

      clear_cache unless options.empty?

      @connection ||= begin
        Faraday.new(merged_options) do |builder|

          puts options.inspect

          builder.use Faraday::Request::JSON
          builder.use Faraday::Request::Multipart
          builder.use Faraday::Request::UrlEncoded
          builder.use Faraday::Response::Logger

          builder.use Github::Request::OAuth2, oauth_token if oauth_token?
          builder.use Github::Request::BasicAuth, login, password if login? && password?

          unless options[:raw]
            builder.use Github::Response::Mashify
            builder.use Github::Response::Jsonize
          end

          builder.use Github::Response::RaiseError
          builder.adapter adapter
        end
      end
    end

  end # Connection
end # Github

Version data entries

1 entries across 1 versions & 1 rubygems

Version Path
github_api-0.2.1 lib/github_api/connection.rb