github-api-client 0.1.2.4 → 0.1.2.6

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.
@@ -0,0 +1,12 @@
1
+ class CreateUserFollowings < ActiveRecord::Migration
2
+ def self.up
3
+ create_table :user_followings, :id => false, :force => true do |t|
4
+ t.references :follower
5
+ t.references :following
6
+ end
7
+ end
8
+
9
+ def self.down
10
+ drop_table :user_followings
11
+ end
12
+ end
@@ -0,0 +1,12 @@
1
+ class CreateRepoWatchings < ActiveRecord::Migration
2
+ def self.up
3
+ create_table :repo_watchings, :id => false, :force => true do |t|
4
+ t.references :watcher
5
+ t.references :repo
6
+ end
7
+ end
8
+
9
+ def self.down
10
+ drop_table :repo_watchings
11
+ end
12
+ end
@@ -38,8 +38,8 @@ module GitHub
38
38
  def self.parse_attributes(resource, attributes)
39
39
  hash = case resource
40
40
  when :user_get then {:public_repo_count => :nil, :public_gist_count => :nil, :created => :nil, :permission => :nil, :followers_count => :nil, :following_count => :nil}
41
- when :user_search then {:name => :login, :username => :login, :fullname => :name, :followers => :nil, :repos => :public_repo_count, :created => :nil, :permission => :nil}
42
- when :repo_get then {:fork => :b_fork}
41
+ when :user_search then {:name => :login, :username => :login, :fullname => :name, :followers => :nil, :repos => :nil, :created => :nil, :permission => :nil}
42
+ when :repo_get then {:fork => :b_fork, :watchers => :nil}
43
43
  end
44
44
  hash.each do |k, v|
45
45
  unless v == :nil
@@ -2,6 +2,7 @@ module GitHub
2
2
  class Repo < ActiveRecord::Base
3
3
  belongs_to :owner, :class_name => 'GitHub::User'
4
4
  belongs_to :parent, :class_name => 'GitHub::Repo'
5
+ has_and_belongs_to_many :watchers, :class_name => 'GitHub::User', :join_table => 'repo_watchings', :foreign_key => 'repo_id', :association_foreign_key => 'watcher_id'
5
6
 
6
7
  def self.get(information)
7
8
  #FIXME: permalink column must be present, comparing url's is surely not the most efficient way for the db
@@ -10,6 +11,13 @@ module GitHub
10
11
  YAML::load(GitHub::Browser.get("/repos/show/#{information}"))['repository']))
11
12
  end
12
13
 
14
+ def get_watchers
15
+ YAML::load(GitHub::Browser.get("/repos/show/#{self.permalink}/watchers"))['watchers'].each do |watcher|
16
+ attr = {:login => watcher}
17
+ self.watchers.find_or_create(GitHub::User.find_or_create_by_login(attr))
18
+ end
19
+ self
20
+ end
13
21
 
14
22
  def owner=(user)
15
23
  self.owner_id = GitHub::User.find_or_create_by_login(user).id if user.class == String
@@ -30,7 +38,7 @@ module GitHub
30
38
  "#{owner.login}/#{name}"
31
39
  end
32
40
 
33
- define_method(:fork?) do
41
+ def fork?
34
42
  b_fork
35
43
  end
36
44
  end
@@ -1,8 +1,8 @@
1
1
  module GitHub
2
2
  # Basic model, stores retrieved user and his associations
3
3
  class User < ActiveRecord::Base
4
- has_and_belongs_to_many :followers, :foreign_key => 'follower_id', :association_foreign_key => 'following_id', :join_table => 'followings', :class_name => 'User'
5
- has_and_belongs_to_many :followings, :foreign_key => 'following_id', :association_foreign_key => 'follower_id', :join_table => 'followings', :class_name => 'User'
4
+ has_and_belongs_to_many :followers, :foreign_key => 'follower_id', :association_foreign_key => 'following_id', :join_table => 'user_followings', :class_name => 'User'
5
+ has_and_belongs_to_many :followings, :foreign_key => 'following_id', :association_foreign_key => 'follower_id', :join_table => 'user_followings', :class_name => 'User'
6
6
  has_many :repos, :class_name => 'GitHub::Repo', :foreign_key => 'owner_id'
7
7
 
8
8
  # Fetches info about current_user from GitHub
@@ -35,7 +35,7 @@ module GitHub
35
35
  def self.search(login)
36
36
  users = []
37
37
  YAML::load(GitHub::Browser.get("/user/search/#{login}"))['users'].each do |user|
38
- users << GitHub::User.find_or_create_by_login(GitHub::Base.parse_attributes(:user, user))
38
+ users << GitHub::User.find_or_create_by_login(GitHub::Base.parse_attributes(:user_search, user))
39
39
  end
40
40
  users
41
41
  end
@@ -79,8 +79,6 @@ module GitHub
79
79
  i = i + 1
80
80
  u = GitHub::User.find_or_create_by_login(user)
81
81
  self.followers.find_or_create u
82
- # Realized it was stupid as it's a bi-directional relation :D
83
- #u.followings.find_or_create self
84
82
  end
85
83
  self
86
84
  end
metadata CHANGED
@@ -6,8 +6,8 @@ version: !ruby/object:Gem::Version
6
6
  - 0
7
7
  - 1
8
8
  - 2
9
- - 4
10
- version: 0.1.2.4
9
+ - 6
10
+ version: 0.1.2.6
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-02 00:00:00 +01:00
18
+ date: 2010-12-03 00:00:00 +01:00
19
19
  default_executable:
20
20
  dependencies:
21
21
  - !ruby/object:Gem::Dependency
@@ -77,8 +77,9 @@ files:
77
77
  - lib/github_api/browser.rb
78
78
  - lib/github_api/config.rb
79
79
  - lib/github_api/user.rb
80
+ - db/migrate/004_create_repo_watchings.rb
80
81
  - db/migrate/003_create_repos.rb
81
- - db/migrate/002_create_followings.rb
82
+ - db/migrate/002_create_user_followings.rb
82
83
  - db/migrate/001_create_users.rb
83
84
  - lib/core_ext/habtm.rb
84
85
  has_rdoc: false
@@ -1,12 +0,0 @@
1
- class CreateFollowings < ActiveRecord::Migration
2
- def self.up
3
- create_table :followings, :id => false, :force => true do |t|
4
- t.references :follower
5
- t.references :following
6
- end
7
- end
8
-
9
- def self.down
10
- drop_table :followings
11
- end
12
- end