Class: Datapimp::Clients::Github

Inherits:
Object
  • Object
show all
Includes:
Singleton
Defined in:
lib/datapimp/clients/github.rb

Class Method Summary collapse

Instance Method Summary collapse

Class Method Details

.client(options = {}) ⇒ Object



14
15
16
17
18
19
20
# File 'lib/datapimp/clients/github.rb', line 14

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

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

.method_missing(meth, *args, &block) ⇒ Object



6
7
8
9
10
11
12
# File 'lib/datapimp/clients/github.rb', line 6

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

  super
end

Instance Method Details

#apiObject



31
32
33
34
35
# File 'lib/datapimp/clients/github.rb', line 31

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

#optionsObject



22
23
24
# File 'lib/datapimp/clients/github.rb', line 22

def options
  @options ||= {}
end

#setup(options = {}) ⇒ Object



37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
# File 'lib/datapimp/clients/github.rb', line 37

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

#with_options(opts = {}) ⇒ Object



26
27
28
29
# File 'lib/datapimp/clients/github.rb', line 26

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