Sha256: b118e017b4a9683d98ca0365669f1e68fc831e719c39f0f63f6e67e85003e912

Contents?: true

Size: 1.65 KB

Versions: 14

Compression:

Stored size: 1.65 KB

Contents

module Datapimp
  module Clients
    class Github
      include Singleton

      def self.method_missing(meth, *args, &block)
        if client.respond_to?(meth)
          return client.send(meth, *args, &block)
        end

        super
      end

      def self.client(options={})
        require 'octokit' unless defined?(::Oktokit)

        @client ||= begin
                      instance.with_options(options)
                    end
      end

      def options
        @options ||= {}
      end

      def with_options(opts={})
        options.merge!(opts)
        self
      end

      def api
        @api ||= begin
                   Octokit::Client.new(access_token: Datapimp.config.github_access_token, auto_paginate: true)
                 end
      end

      def setup(options={})
        access_token = options[:github_access_token] || Datapimp.config.github_access_token

        unless access_token.to_s.length == 40
          puts "You should generate an access token to use with the Github client."
          puts "Access tokens allow you to revoke and/or limit access if needed."
          puts "To learn more about access tokens, and how to generate them, visit: https://help.github.com/articles/creating-an-access-token-for-command-line-use/"

          if respond_to?(:ask)
            access_token = ask("Enter a 40 character access token when you have one", String)
          end
        end

        unless access_token.to_s.length == 40
          puts "Can not proceed without a valid access token: error code #{ access_token.length }"
          return
        end

        Datapimp.config.set(:github_access_token, access_token)
      end
    end
  end
end

Version data entries

14 entries across 14 versions & 1 rubygems

Version Path
datapimp-1.2.11 lib/datapimp/clients/github.rb
datapimp-1.2.10 lib/datapimp/clients/github.rb
datapimp-1.2.9 lib/datapimp/clients/github.rb
datapimp-1.2.8 lib/datapimp/clients/github.rb
datapimp-1.2.7 lib/datapimp/clients/github.rb
datapimp-1.2.6 lib/datapimp/clients/github.rb
datapimp-1.2.5 lib/datapimp/clients/github.rb
datapimp-1.2.4 lib/datapimp/clients/github.rb
datapimp-1.2.3 lib/datapimp/clients/github.rb
datapimp-1.2.2 lib/datapimp/clients/github.rb
datapimp-1.2.1 lib/datapimp/clients/github.rb
datapimp-1.2.0 lib/datapimp/clients/github.rb
datapimp-1.1.1 lib/datapimp/clients/github.rb
datapimp-1.1.0 lib/datapimp/clients/github.rb