Class: Metahub::GithubService

Inherits:
Object
  • Object
show all
Defined in:
lib/metahub/github.rb

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initializeGithubService

Returns a new instance of GithubService.



11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
# File 'lib/metahub/github.rb', line 11

def initialize
  client_options = { :login => Auth.username, 
              :password => Auth.password,
              :auto_traversal => true
            }
  token_options  = { :scopes => ["repo"], 
              :client_id => "099bb3db6bf979a92391",
              :client_secret => "ad2cbeac50c2d19478b1d9041b72fd7b9a3b0d26",
              :idempotent => true
            }

  simple = Octokit::Client.new(client_options)
  begin
    token = simple.create_authorization(token_options)
    @client = Octokit::Client.new(:access_token => token[:token])
  rescue Octokit::OneTimePasswordRequired => e
    token = simple.create_authorization(token_options.merge(:headers => { "X-GitHub-OTP" => Auth.otp_code }))
    @client = Octokit::Client.new(:access_token => token[:token])
  end
  # puts @client.ratelimit_remaining
end

Instance Attribute Details

#clientObject (readonly)

Returns the value of attribute client.



10
11
12
# File 'lib/metahub/github.rb', line 10

def client
  @client
end

Class Method Details

.ownerObject



6
7
8
# File 'lib/metahub/github.rb', line 6

def self.owner
  @owner ||= self.new
end

Instance Method Details

#repositoriesObject



33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
# File 'lib/metahub/github.rb', line 33

def repositories
  repos = []

  client.repositories.each do |hash|
    repos << hash.full_name
  end

  self.organizations(client.).each do |org_name|
    client.organization_repositories(org_name).each do |hash|
      repos << hash.full_name
    end
  end

  # return these, ignoring requested ones
  repos.compact.uniq
end