Class: GithubApi::User

Inherits:
Object
  • Object
show all
Defined in:
lib/unofficial-github-api/github_api.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(user_name) ⇒ User

Returns a new instance of User.



8
9
10
# File 'lib/unofficial-github-api/github_api.rb', line 8

def initialize(user_name)
  @name = user_name
end

Instance Attribute Details

#nameObject (readonly)

Returns the value of attribute name.



7
8
9
# File 'lib/unofficial-github-api/github_api.rb', line 7

def name
  @name
end

Instance Method Details

#commits_sizeObject



33
34
35
# File 'lib/unofficial-github-api/github_api.rb', line 33

def commits_size
  Nokogiri::HTML(open("https://github.com/#{name}")).xpath('//*[@id="contributions-calendar"]/div[3]/div[1]/span[1]').text.split(' ').first.gsub(/\,/,'').to_i
end

#created_atObject



25
26
27
# File 'lib/unofficial-github-api/github_api.rb', line 25

def created_at
  Chronic.parse(Nokogiri::HTML(open("https://github.com/#{name}")).css('span.join-date').text)
end

#followersObject



12
13
14
15
16
17
18
19
20
21
22
23
# File 'lib/unofficial-github-api/github_api.rb', line 12

def followers
  wq = WorkQueue.new 5
  list = {}
  pages = get_number_of_followers_pages
  (1..pages).to_a.each do |i|
    wq.enqueue_b do
      list[i] = FollowersPage.new(name, i).followers_list
    end
  end
  wq.join
  list.values.flatten
end

#followers_sizeObject



29
30
31
# File 'lib/unofficial-github-api/github_api.rb', line 29

def followers_size
  Nokogiri::HTML(open("https://github.com/#{name}/followers")).xpath('//*[@id="site-container"]/div[1]/div/ul/li/span/span/a[2]').text.gsub(/\,/,'').to_i
end

#get_number_of_followers_pagesObject



37
38
39
# File 'lib/unofficial-github-api/github_api.rb', line 37

def get_number_of_followers_pages
  (followers_size.to_f/51).ceil
end