Class: GitHub::Base
- Inherits:
-
Object
- Object
- GitHub::Base
- Defined in:
- lib/github_api/base.rb
Overview
Basic functionality inherited later
Class Method Summary collapse
-
.parse_attributes(resource, attributes) ⇒ Hash
Converts pitfalls from GitHub API differences into normal data.
-
.sync ⇒ Object
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.
Instance Method Summary collapse
-
#build(options = {}) ⇒ Object
Sends key= value signals at object, that inherits it.
-
#to_ary ⇒ Hash
ActiveRecord fix that returns attributes.
Class Method Details
.parse_attributes(resource, attributes) ⇒ Hash
Converts pitfalls from GitHub API differences into normal data
38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 |
# File 'lib/github_api/base.rb', line 38 def self.parse_attributes(resource, attributes) 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 => :public_repo_count, :created => :nil, :permission => :nil} when :repo_get then {:fork => :b_fork} end hash.each do |k, v| unless v == :nil if [:repo_get].include? resource attributes[v.to_s] = attributes[k.to_sym] else attributes[v.to_s] = attributes[k.to_s] end end if [:repo_get].include? resource attributes.delete k.to_sym else attributes.delete k.to_s end end attributes end |
.sync ⇒ Object
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
-
17 18 19 20 21 22 23 24 25 26 27 28 29 30 |
# File 'lib/github_api/base.rb', line 17 def self.sync puts "Synchronizing local database with GitHub" users = GitHub::User.all count = users.count i = 1 users.each do |user| puts "#{count.to_s.color(:green).bright} / #{i.to_s.color(:blue).bright} - Updating records" i = i + 1 # Disabled because of its length #user.get #user.get_followers end nil end |
Instance Method Details
#build(options = {}) ⇒ Object
Sends key= value signals at object, that inherits it
6 7 8 9 10 |
# File 'lib/github_api/base.rb', line 6 def build( = {}) .each_pair do |k, v| self.send "#{k.to_sym}=", v end end |
#to_ary ⇒ Hash
ActiveRecord fix that returns attributes
63 64 65 |
# File 'lib/github_api/base.rb', line 63 def to_ary return self.attributes end |