class GitHub::Base
Basic functionality inherited later
Public Class Methods
parse_attributes(resource, attributes)
click to toggle source
Converts pitfalls from GitHub
API differences into normal data @param [Symbol] resource GitHub
Resource to parse @option [Symbol] resource :user Parse attributes of User
@option [Symbol] resource :repo Parse attributes of Repo
@param [Hash] attributes GitHub
API retrieved attributes to be parsed @return [Hash] parsed attributes, fully compatibile with local db
# File lib/github-api-client/base.rb, line 44 def self.parse_attributes(resource, attributes) return {} unless attributes # Guard against empty results hash = case resource when :user_get then {:public_repo_count => :nil, :public_gist_count => :nil, :created => :nil, :permission => :nil, :followers_count => :nil, :following_count => :nil} when :user_search then {:name => :login, :username => :login, :fullname => :name, :followers => :nil, :repos => :nil, :created => :nil, :permission => :nil} when :repo_get then {:fork => :b_fork, :watchers => nil, :owner => :owner_login, :forks => nil, :followers_count => nil, :forks_count => nil, :master_branch => nil} when :org_get then {:public_gist_count => nil, :public_repo_count => nil, :following_count => :nil, :followers_count => :nil} when :org_repo_index then {:owner => nil, :open_issues => nil, :has_issues => nil, :watchers => nil, :forks => nil, :fork => :b_fork, :gravatar_id => nil, :organization => :organization_login, :master_branch => nil} when :org_repo_get then {:owner => nil, :open_issues => nil, :has_issues => nil, :watchers => nil, :forks => nil, :fork => :b_fork, :gravatar_id => nil, :organization => :organization_login} else raise "Unknown resource #{resource.inspect} with attributes #{attributes.inspect}" end # Provides abstraction layer between YAML :keys and 'keys' returned by Hub symbolized_resources = [:repo_get, :org_repo_index, :org_repo_get] hash.each do |k, v| unless v == :nil || v == nil if v.class != Symbol attributes[k.to_s] = v else if symbolized_resources.include? resource attributes[v.to_s] = attributes[k.to_sym] else attributes[v.to_s] = attributes[k.to_s] end end end if symbolized_resources.include? resource attributes.delete k.to_sym else attributes.delete k.to_s end end attributes end
sync()
click to toggle source
Synchronizes every information from local database with GitHub
VERY DANGEROUS AND EVIL¶ ↑
Recursively gets all* GitHub
Users, takes years to fetch
-
all that have at least one follower
-
@return nil
# File lib/github-api-client/base.rb, line 17 def self.sync puts "Synchronizing local database with GitHub" users = GitHub::User.all repos = GitHub::Repo.all puts "Updating Records of all #{"users".color(:yellow).bright}" #progress = ProgressBar.new("Updating records", users.count) users.each do |user| # Disabled because of its length user.fetch(:self) #progress.inc end progress.finish #progress = ProgressBar.new("Updating records", repos.count) repos.each do |repo| repo.fetch(:self, :watchers) #progress.inc end #progress.finish nil end
Public Instance Methods
build(options = {})
click to toggle source
Sends key= value signals at object, that inherits it @param [Hash] options to assign for an object
# File lib/github-api-client/base.rb, line 6 def build(options = {}) options.each_pair do |k, v| self.send "#{k.to_sym}=", v end end
to_ary()
click to toggle source
ActiveRecord fix that returns attributes @return [Hash] Attributes of the object
# File lib/github-api-client/base.rb, line 80 def to_ary return self.attributes end