class GitHub::Organization

Public Class Methods

get(login) click to toggle source
# File lib/github-api-client/organization.rb, line 14
def self.get(login)
  o   = GitHub::Organization.find_by_login(login)
  o ||= GitHub::Organization.new(:login => login).get
end

Public Instance Methods

fetch(*things) click to toggle source
# File lib/github-api-client/organization.rb, line 19
def fetch(*things)
  things.each do |thing|
    case thing
      when :self then get
      when :members then get_members
      when :repositories then get_repositories
    end
  end
  self
end
get() click to toggle source
# File lib/github-api-client/organization.rb, line 6
def get
  self.update_attributes(
    GitHub::Base.parse_attributes(:org_get,
      YAML::load(
        GitHub::Browser.get("/organizations/#{self.login}"))['organization']))
  self
end

Private Instance Methods

get_members() click to toggle source
# File lib/github-api-client/organization.rb, line 31
def get_members
  members = YAML::load(GitHub::Browser.get "/organizations/#{login}/public_members")['users']
  puts "Fetching members for #{"organization".color(:magenta).bright} #{self.login.dup.color(:green).bright}"
  i, count = 0, members.count.to_s.color(:green).bright
  self.transaction do
    members.each do |user|
      i += 1
      u = GitHub::User.find_or_create_by_login(user['login'])
      self.association(:members).find_or_create u
      print "\r#{i.to_s.color(:yellow).bright}/#{count}"
    end
  end
  puts nil
  self
end
get_repositories() click to toggle source
# File lib/github-api-client/organization.rb, line 47
def get_repositories
  repos = YAML::load(GitHub::Browser.get "/organizations/#{login}/public_repositories")['repositories']
  puts "Fetching repositories for #{"organization".color(:magenta).bright} #{self.login.dup.color(:green).bright}"
  i, count = 0, repos.count.to_s.color(:green).bright
  self.transaction do
    repos.each do |repo|
      i += 1
      r   = GitHub::Repo.find_by_url(repo[:url])
      r ||= GitHub::Repo.create(GitHub::Base.parse_attributes :org_repo_index, repo)
      print "\r#{i.to_s.color(:yellow).bright}/#{count}"
    end
  end
  puts nil
  self
end