github-api-client 0.1.2.6 → 0.1.3.0
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.
- data/lib/github_api/repo.rb +39 -6
- data/lib/github_api/user.rb +14 -10
- metadata +3 -3
data/lib/github_api/repo.rb
CHANGED
@@ -4,21 +4,49 @@ module GitHub
|
|
4
4
|
belongs_to :parent, :class_name => 'GitHub::Repo'
|
5
5
|
has_and_belongs_to_many :watchers, :class_name => 'GitHub::User', :join_table => 'repo_watchings', :foreign_key => 'repo_id', :association_foreign_key => 'watcher_id'
|
6
6
|
|
7
|
+
def get
|
8
|
+
self.update_attributes GitHub::Base.parse_attributes(:repo_get,
|
9
|
+
YAML::load(
|
10
|
+
GitHub::Browser.get("/repos/show/#{self.permalink}"))['repository'])
|
11
|
+
self
|
12
|
+
end
|
13
|
+
|
7
14
|
def self.get(information)
|
8
15
|
#FIXME: permalink column must be present, comparing url's is surely not the most efficient way for the db
|
9
|
-
GitHub::
|
10
|
-
|
11
|
-
|
16
|
+
conditions = {:name => information.split('/').last, :owner_id => GitHub::User.find_or_create_by_login(information.split('/').first).id}
|
17
|
+
if r = GitHub::Repo.where(conditions).first
|
18
|
+
r.get
|
19
|
+
else
|
20
|
+
r = GitHub::Repo.new(conditions).get
|
21
|
+
end
|
22
|
+
end
|
23
|
+
|
24
|
+
def fetch(*things)
|
25
|
+
things.each do |thing|
|
26
|
+
case thing
|
27
|
+
when :self then get
|
28
|
+
when :watchers then get_watchers
|
29
|
+
end
|
30
|
+
end
|
31
|
+
self
|
12
32
|
end
|
13
33
|
|
34
|
+
private
|
14
35
|
def get_watchers
|
15
|
-
YAML::load(GitHub::Browser.get("/repos/show/#{self.permalink}/watchers"))['watchers']
|
16
|
-
|
17
|
-
|
36
|
+
watchers = YAML::load(GitHub::Browser.get("/repos/show/#{self.permalink}/watchers"))['watchers']
|
37
|
+
i = 1
|
38
|
+
self.transaction do
|
39
|
+
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
|
+
attr = {:login => watcher}
|
43
|
+
self.watchers.find_or_create(GitHub::User.find_or_create_by_login(attr))
|
44
|
+
end
|
18
45
|
end
|
19
46
|
self
|
20
47
|
end
|
21
48
|
|
49
|
+
public
|
22
50
|
def owner=(user)
|
23
51
|
self.owner_id = GitHub::User.find_or_create_by_login(user).id if user.class == String
|
24
52
|
if user.class == GitHub::User
|
@@ -38,6 +66,11 @@ module GitHub
|
|
38
66
|
"#{owner.login}/#{name}"
|
39
67
|
end
|
40
68
|
|
69
|
+
# For future, when sql will be find_or_create_by_permalink
|
70
|
+
def permalink=(anything)
|
71
|
+
@permalink = permalink
|
72
|
+
end
|
73
|
+
|
41
74
|
def fork?
|
42
75
|
b_fork
|
43
76
|
end
|
data/lib/github_api/user.rb
CHANGED
@@ -74,11 +74,13 @@ module GitHub
|
|
74
74
|
def get_followers
|
75
75
|
users = YAML::load(GitHub::Browser.get "/user/show/#{login}/followers")['users']
|
76
76
|
i = 1
|
77
|
-
|
78
|
-
|
79
|
-
|
80
|
-
|
81
|
-
|
77
|
+
self.transaction do
|
78
|
+
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
|
+
u = GitHub::User.find_or_create_by_login(user)
|
82
|
+
self.followers.find_or_create u
|
83
|
+
end
|
82
84
|
end
|
83
85
|
self
|
84
86
|
end
|
@@ -86,11 +88,13 @@ module GitHub
|
|
86
88
|
def get_followings
|
87
89
|
users = YAML::load(GitHub::Browser.get "/user/show/#{login}/following")['users']
|
88
90
|
i = 1
|
89
|
-
|
90
|
-
|
91
|
-
|
92
|
-
|
93
|
-
|
91
|
+
self.transaction do
|
92
|
+
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
|
+
u = GitHub::User.find_or_create_by_login(user)
|
96
|
+
self.followings.find_or_create u
|
97
|
+
end
|
94
98
|
end
|
95
99
|
self
|
96
100
|
end
|