Sha256: 38a0b25514e1613aac43d2b6f4af7d21d3442ee0f0f411e780191ecad3763980

Contents?: true

Size: 1.11 KB

Versions: 1

Compression:

Stored size: 1.11 KB

Contents

# encoding: utf-8

module GithubCLI

  # The API class is the main entry point for creating GithubCLI APIs.
  class API

    @@api = nil

    class << self

      attr_reader :config

      def github_api
        @@api ||= begin
          @@api = configure_api
        end
      end

      def configure_api
        @@api = Github.new
        config = GithubCLI.config.data

        if config['user.token']
          @@api.oauth_token = config['user.token']
        end
        if config['user.login'] && config['user.password']
          @@api.basic_auth = "#{config['user.login']}:#{config['user.password']}"
        end
        @@api.endpoint = GithubCLI.config['core.endpoint'] || @@api.endpoint
        if ENV['TEST_HOST']
          @@api.endpoint = 'http://' + ENV['TEST_HOST']
        end
        @@api
      end

      def output(format=:table, &block)
        response  = block.call
        formatter = Formatter.new response, :format => format
        formatter.render_output
      end

    end

    class All
      def initialize(params)
        puts Github::Repos.new.all params
      end
    end

  end # API
end # GithubCLI

Version data entries

1 entries across 1 versions & 1 rubygems

Version Path
github_cli-0.5.4 lib/github_cli/api.rb