github-api-client 0.1.1.2 → 0.1.1.3
Sign up to get free protection for your applications and to get access to all the features.
- data/db/migrate/001_create_users.rb +1 -1
- data/lib/core_ext/habtm.rb +7 -0
- data/lib/github_api.rb +5 -4
- data/lib/github_api/base.rb +3 -3
- data/lib/github_api/user.rb +6 -7
- metadata +4 -3
@@ -1,7 +1,7 @@
|
|
1
1
|
class CreateUsers < ActiveRecord::Migration
|
2
2
|
def self.up
|
3
3
|
create_table :users, :force => true do |t|
|
4
|
-
%w(login token type name company location blog email language).each do |attr|
|
4
|
+
%w(login token type name company location blog email language permission).each do |attr|
|
5
5
|
t.string attr
|
6
6
|
end
|
7
7
|
|
data/lib/github_api.rb
CHANGED
@@ -1,5 +1,5 @@
|
|
1
1
|
#!/usr/bin/ruby
|
2
|
-
|
2
|
+
#$: << '../'
|
3
3
|
|
4
4
|
require 'rubygems'
|
5
5
|
gem 'github-api-client'
|
@@ -8,6 +8,7 @@ require 'uri'
|
|
8
8
|
require 'yaml'
|
9
9
|
require 'singleton'
|
10
10
|
require 'active_record'
|
11
|
+
require 'core_ext/habtm'
|
11
12
|
|
12
13
|
# General placeholder for all of the GitHub API sweets
|
13
14
|
module GitHub
|
@@ -28,9 +29,9 @@ end
|
|
28
29
|
|
29
30
|
GitHub::Config.setup
|
30
31
|
|
31
|
-
require 'base'
|
32
|
-
require 'user'
|
33
|
-
require 'browser'
|
32
|
+
require 'github_api/base'
|
33
|
+
require 'github_api/user'
|
34
|
+
require 'github_api/browser'
|
34
35
|
require 'rainbow'
|
35
36
|
|
36
37
|
|
data/lib/github_api/base.rb
CHANGED
@@ -33,11 +33,11 @@ module GitHub
|
|
33
33
|
# @param [Hash] attributes GitHub API retrieved attributes to be parsed
|
34
34
|
# @return [Hash] parsed attributes, fully compatibile with local db
|
35
35
|
def self.parse_attributes(attributes)
|
36
|
-
{:name => :login, :username => :login, :fullname => :name, :followers => :followers_count, :repos => :public_repo_count, :created => :nil}.each do |k, v|
|
36
|
+
{:name => :login, :username => :login, :fullname => :name, :followers => :followers_count, :repos => :public_repo_count, :created => :nil, :permission => :nil}.each do |k, v|
|
37
37
|
unless v == :nil
|
38
|
-
attributes[v] = attributes[k.
|
38
|
+
attributes[v.to_sym] = attributes[k.to_sym]
|
39
39
|
end
|
40
|
-
attributes.delete k.
|
40
|
+
attributes.delete k.to_sym
|
41
41
|
end
|
42
42
|
attributes
|
43
43
|
end
|
data/lib/github_api/user.rb
CHANGED
@@ -2,13 +2,14 @@ module GitHub
|
|
2
2
|
# Basic model, stores retrieved user and his associations
|
3
3
|
class User < ActiveRecord::Base
|
4
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 :
|
5
|
+
has_and_belongs_to_many :followings, :foreign_key => 'following_id', :association_foreign_key => 'follower_id', :join_table => 'followings', :class_name => 'User'
|
6
6
|
|
7
7
|
# Fetches info about current_user from GitHub
|
8
8
|
# GitHub::User.new.build(:login => 'asd', :token => 'token').get #=> GitHub::User
|
9
9
|
# @return [GitHub::User] Chainable self object after syncing attributes with GitHub
|
10
10
|
def get
|
11
|
-
self.update_attributes YAML::load(
|
11
|
+
self.update_attributes YAML::load(
|
12
|
+
GitHub::Browser.get("/user/show/#{self.login}"))['user']
|
12
13
|
self
|
13
14
|
end
|
14
15
|
|
@@ -63,17 +64,15 @@ module GitHub
|
|
63
64
|
private
|
64
65
|
def get_followers
|
65
66
|
users = YAML::load(GitHub::Browser.get "/user/show/#{login}/followers")['users']
|
66
|
-
|
67
|
-
ids = []
|
68
67
|
i = 1
|
69
68
|
users.each do |user|
|
70
69
|
puts "#{users.length.to_s} / #{i.to_s} - Fetching followers"
|
71
70
|
i = i + 1
|
72
71
|
u = GitHub::User.find_or_create_by_login(user)
|
73
|
-
|
72
|
+
self.followers.find_or_create u
|
73
|
+
# Realized it was stupid as it's a bi-directional relation :D
|
74
|
+
#u.followings.find_or_create self
|
74
75
|
end
|
75
|
-
|
76
|
-
self.follower_ids = ids
|
77
76
|
self
|
78
77
|
end
|
79
78
|
|
metadata
CHANGED
@@ -6,8 +6,8 @@ version: !ruby/object:Gem::Version
|
|
6
6
|
- 0
|
7
7
|
- 1
|
8
8
|
- 1
|
9
|
-
-
|
10
|
-
version: 0.1.1.
|
9
|
+
- 3
|
10
|
+
version: 0.1.1.3
|
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-11-
|
18
|
+
date: 2010-11-30 00:00:00 +01:00
|
19
19
|
default_executable:
|
20
20
|
dependencies:
|
21
21
|
- !ruby/object:Gem::Dependency
|
@@ -77,6 +77,7 @@ files:
|
|
77
77
|
- lib/github_api/user.rb
|
78
78
|
- db/migrate/002_create_followings.rb
|
79
79
|
- db/migrate/001_create_users.rb
|
80
|
+
- lib/core_ext/habtm.rb
|
80
81
|
has_rdoc: false
|
81
82
|
homepage: http://github.com/farnoy/github-api-client
|
82
83
|
licenses: []
|