github-api-client 0.1.3.0 → 0.1.3.2

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -10,6 +10,7 @@ require 'singleton'
10
10
  require 'active_record'
11
11
  require 'core_ext/habtm'
12
12
  require 'rainbow'
13
+ require 'progressbar'
13
14
  require 'github_api/config'
14
15
 
15
16
  GitHub::Config.setup
@@ -17,15 +17,21 @@ module GitHub
17
17
  def self.sync
18
18
  puts "Synchronizing local database with GitHub"
19
19
  users = GitHub::User.all
20
- count = users.count
21
- i = 1
20
+ repos = GitHub::Repo.all
21
+ puts "Updating Records of all #{"users".color(:yellow).bright}"
22
+ progress = ProgressBar.new("Updating records", users.count)
22
23
  users.each do |user|
23
- puts "#{count.to_s.color(:green).bright} / #{i.to_s.color(:blue).bright} - Updating records"
24
- i = i + 1
25
24
  # Disabled because of its length
26
- #user.get
27
- #user.get_followers
25
+ user.fetch(:self)
26
+ progress.inc
28
27
  end
28
+ progress.finish
29
+ progress = ProgressBar.new("Updating records", repos.count)
30
+ repos.each do |repo|
31
+ repo.fetch(:self, :watchers)
32
+ progress.inc
33
+ end
34
+ progress.finish
29
35
  nil
30
36
  end
31
37
 
@@ -14,7 +14,7 @@ module GitHub
14
14
  # @return [String] request result
15
15
  def self.get(uri)
16
16
  uri = uri.gsub(" ","+")
17
- puts "Requesting #{URI.parse(self.base_uri + uri)}"
17
+ puts "Requesting #{URI.parse(self.base_uri + uri)}" if GitHub::Config::Options[:verbose]
18
18
  Net::HTTP.get URI.parse(self.base_uri + uri)
19
19
  end
20
20
 
@@ -23,7 +23,7 @@ module GitHub
23
23
  # @return [String] request result
24
24
  def self.post(uri, options = {})
25
25
  uri = uri.gsub(" ","+")
26
- puts "Requesting #{URI.parse(self.base_uri + uri)} with options: #{options}"
26
+ puts "Requesting #{URI.parse(self.base_uri + uri)} with options: #{options}" if GitHub::Config::Options[:verbose]
27
27
  Net::HTTP.post_form URI.parse(self.base_uri + uri), options
28
28
  end
29
29
  end
@@ -23,6 +23,8 @@ You have two ways of defining your user to have authenticated access to your API
23
23
  end
24
24
  Secrets ||= nil
25
25
 
26
+ Options = {:verbose => false}
27
+
26
28
  # Sets up the database and migrates it
27
29
  # @return [nil]
28
30
  def self.setup
@@ -34,15 +34,16 @@ module GitHub
34
34
  private
35
35
  def get_watchers
36
36
  watchers = YAML::load(GitHub::Browser.get("/repos/show/#{self.permalink}/watchers"))['watchers']
37
- i = 1
37
+ puts "Fetching watchers for #{"repo".color(:blue).bright} #{self.permalink.color(:green).bright}"
38
+ progress = ProgressBar.new("progress", watchers.count)
38
39
  self.transaction do
39
40
  watchers.each do |watcher|
40
- puts "#{watchers.length.to_s.color(:green).bright} / #{i.to_s.color(:blue).bright} - Fetching watchers"
41
- i = i + 1
42
41
  attr = {:login => watcher}
43
42
  self.watchers.find_or_create(GitHub::User.find_or_create_by_login(attr))
43
+ progress.inc
44
44
  end
45
45
  end
46
+ progress.finish
46
47
  self
47
48
  end
48
49
 
@@ -73,29 +73,31 @@ module GitHub
73
73
  private
74
74
  def get_followers
75
75
  users = YAML::load(GitHub::Browser.get "/user/show/#{login}/followers")['users']
76
- i = 1
76
+ puts "Fetching followers for #{"user".color(:yellow).bright} #{self.login.color(:green).bright}"
77
+ progress = ProgressBar.new("progress", users.count)
77
78
  self.transaction do
78
79
  users.each do |user|
79
- puts "#{users.length.to_s.color(:green).bright} / #{i.to_s.color(:blue).bright} - Fetching followers"
80
- i = i + 1
81
80
  u = GitHub::User.find_or_create_by_login(user)
82
81
  self.followers.find_or_create u
82
+ progress.inc
83
83
  end
84
84
  end
85
+ progress.finish
85
86
  self
86
87
  end
87
88
 
88
89
  def get_followings
89
90
  users = YAML::load(GitHub::Browser.get "/user/show/#{login}/following")['users']
90
- i = 1
91
+ puts "Fetching followings for #{"user".color(:yellow).bright} #{self.login.color(:green).bright}"
92
+ progress = ProgressBar.new("progress", users.count)
91
93
  self.transaction do
92
94
  users.each do |user|
93
- puts "#{users.length.to_s.color(:green).bright} / #{i.to_s.color(:blue).bright} - Fetching followings"
94
- i = i + 1
95
95
  u = GitHub::User.find_or_create_by_login(user)
96
96
  self.followings.find_or_create u
97
+ progress.inc
97
98
  end
98
99
  end
100
+ progress.finish
99
101
  self
100
102
  end
101
103
 
metadata CHANGED
@@ -6,8 +6,8 @@ version: !ruby/object:Gem::Version
6
6
  - 0
7
7
  - 1
8
8
  - 3
9
- - 0
10
- version: 0.1.3.0
9
+ - 2
10
+ version: 0.1.3.2
11
11
  platform: ruby
12
12
  authors:
13
13
  - "Jakub Oko\xC5\x84ski"
@@ -15,7 +15,7 @@ autorequire:
15
15
  bindir: bin
16
16
  cert_chain: []
17
17
 
18
- date: 2010-12-03 00:00:00 +01:00
18
+ date: 2010-12-04 00:00:00 +01:00
19
19
  default_executable:
20
20
  dependencies:
21
21
  - !ruby/object:Gem::Dependency