Class: Mygithub::GithubAccessor

Inherits:
Object
  • Object
show all
Defined in:
lib/mygithub/github_accessor.rb

Defined Under Namespace

Classes: Repository

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(username, token) ⇒ GithubAccessor

Returns a new instance of GithubAccessor.



15
16
17
18
19
20
21
22
23
24
25
26
27
28
# File 'lib/mygithub/github_accessor.rb', line 15

def initialize(username, token)
  @username = username
  @token    = token

  @github = Github.new(:oauth_token => @token)
  # @memo SSL証明書絡みでエラーが出たらこちら
  # @github = Github.new do |config|
  #   config.endpoint    = 'https://api.github.com/'
  #   config.user        = username
  #   config.oauth_token = token                      # @memo 何故か'@token'にすると動かない
  #   config.adapter     = :net_http
  #   config.ssl         = {:verify => false}
  # end      
end

Instance Attribute Details

#tokenObject (readonly)

Returns the value of attribute token.



13
14
15
# File 'lib/mygithub/github_accessor.rb', line 13

def token
  @token
end

Instance Method Details

#avatar_urlObject



61
62
63
# File 'lib/mygithub/github_accessor.rb', line 61

def avatar_url
  @github.users.get(username).avatar_url      
end

#repo_namesObject



43
44
45
46
47
48
49
50
51
52
53
54
55
# File 'lib/mygithub/github_accessor.rb', line 43

def repo_names
  repos = []
  page       = 1

  while (true)
    r = @github.repos.list(:per_page => 100, :page => page).map {|r| Repository.new(r)}
    break if r.empty?
    repos += r
    page += 1
  end

  repos.sort_by{|r| r.pushed_at}.map{|r| r.full_name}
end

#usernameObject



57
58
59
# File 'lib/mygithub/github_accessor.rb', line 57

def username
  @username
end