vain 0.0.8 → 0.0.9
Sign up to get free protection for your applications and to get access to all the features.
- data/lib/vain/cli.rb +9 -9
- data/lib/vain/github.rb +38 -0
- data/lib/vain/version.rb +1 -1
- metadata +39 -20
data/lib/vain/cli.rb
CHANGED
@@ -1,16 +1,16 @@
|
|
1
|
+
require 'rubygems'
|
2
|
+
require 'columnizer'
|
3
|
+
require 'vain/github'
|
4
|
+
|
1
5
|
module Vain
|
2
6
|
|
3
7
|
class CLI
|
4
8
|
|
5
|
-
require 'rubygems'
|
6
|
-
require 'columnizer'
|
7
|
-
require 'hubruby'
|
8
|
-
|
9
9
|
# Some colors used in the output
|
10
|
-
NameColor
|
10
|
+
NameColor = "\e[33m"
|
11
11
|
CommandColor = "\e[36m"
|
12
12
|
DefaultColor = "\e[0m"
|
13
|
-
ErrorColor
|
13
|
+
ErrorColor = "\e[31m"
|
14
14
|
|
15
15
|
# Get the commands from the command line
|
16
16
|
# (Somewhat primitive, will be expanded) TODO
|
@@ -21,11 +21,11 @@ module Vain
|
|
21
21
|
private
|
22
22
|
|
23
23
|
def status(user_handle)
|
24
|
-
user =
|
25
|
-
return failtown("Unknown user: #{user_handle}") if user.
|
24
|
+
user = Vain::Github::User.get(user_handle)
|
25
|
+
return failtown("Unknown user: #{user_handle}") if user.nil?
|
26
26
|
puts "#{CommandColor}#{user.login}#{DefaultColor} - #{user.followers_count} followers - #{user.public_repo_count} public repositories"
|
27
27
|
# get the repositories sorted by watcher count
|
28
|
-
repositories =
|
28
|
+
repositories = Vain::Github::Repo.all(user_handle).sort_by { |r| 1.0 / r.watchers }
|
29
29
|
data = repositories.map do |repo|
|
30
30
|
[
|
31
31
|
NameColor + repo.name + DefaultColor,
|
data/lib/vain/github.rb
ADDED
@@ -0,0 +1,38 @@
|
|
1
|
+
require 'restclient'
|
2
|
+
require 'json'
|
3
|
+
require 'hashie'
|
4
|
+
|
5
|
+
module Vain
|
6
|
+
|
7
|
+
module Github
|
8
|
+
|
9
|
+
# Try to get a user - return nil if they're not found
|
10
|
+
class User < Hashie::Mash
|
11
|
+
def self.get(user_name)
|
12
|
+
begin
|
13
|
+
response = RestClient.get("http://github.com/api/v2/json/user/show/#{user_name}")
|
14
|
+
User.new(JSON.parse(response)["user"])
|
15
|
+
rescue RestClient::ResourceNotFound
|
16
|
+
nil
|
17
|
+
end
|
18
|
+
end
|
19
|
+
end
|
20
|
+
|
21
|
+
# Get all repositories for a user
|
22
|
+
class Repo < Hashie::Mash
|
23
|
+
def self.all(user_name)
|
24
|
+
all_repos = []
|
25
|
+
page = 1
|
26
|
+
begin
|
27
|
+
response = RestClient.get("http://github.com/api/v2/json/repos/show/#{user_name}?page=#{page}")
|
28
|
+
repos = JSON.parse(response)["repositories"]
|
29
|
+
all_repos.concat repos.map { |hash| Repo.new(hash) }
|
30
|
+
page += 1
|
31
|
+
end while repos.size == 30
|
32
|
+
all_repos
|
33
|
+
end
|
34
|
+
end
|
35
|
+
|
36
|
+
end
|
37
|
+
|
38
|
+
end
|
data/lib/vain/version.rb
CHANGED
metadata
CHANGED
@@ -1,13 +1,13 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: vain
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
hash:
|
4
|
+
hash: 13
|
5
5
|
prerelease: false
|
6
6
|
segments:
|
7
7
|
- 0
|
8
8
|
- 0
|
9
|
-
-
|
10
|
-
version: 0.0.
|
9
|
+
- 9
|
10
|
+
version: 0.0.9
|
11
11
|
platform: ruby
|
12
12
|
authors:
|
13
13
|
- John Crepezzi
|
@@ -15,53 +15,71 @@ autorequire:
|
|
15
15
|
bindir: bin
|
16
16
|
cert_chain: []
|
17
17
|
|
18
|
-
date: 2011-01-
|
18
|
+
date: 2011-01-29 00:00:00 -05:00
|
19
19
|
default_executable:
|
20
20
|
dependencies:
|
21
21
|
- !ruby/object:Gem::Dependency
|
22
|
-
name:
|
22
|
+
name: columnizer
|
23
23
|
prerelease: false
|
24
24
|
requirement: &id001 !ruby/object:Gem::Requirement
|
25
25
|
none: false
|
26
26
|
requirements:
|
27
|
-
- - "
|
27
|
+
- - "="
|
28
28
|
- !ruby/object:Gem::Version
|
29
|
-
hash:
|
29
|
+
hash: 25
|
30
30
|
segments:
|
31
31
|
- 0
|
32
|
-
|
33
|
-
|
32
|
+
- 0
|
33
|
+
- 3
|
34
|
+
version: 0.0.3
|
35
|
+
type: :runtime
|
34
36
|
version_requirements: *id001
|
35
37
|
- !ruby/object:Gem::Dependency
|
36
|
-
name:
|
38
|
+
name: rest-client
|
37
39
|
prerelease: false
|
38
40
|
requirement: &id002 !ruby/object:Gem::Requirement
|
39
41
|
none: false
|
40
42
|
requirements:
|
41
|
-
- -
|
43
|
+
- - ~>
|
42
44
|
- !ruby/object:Gem::Version
|
43
45
|
hash: 3
|
44
46
|
segments:
|
45
|
-
-
|
46
|
-
|
47
|
+
- 1
|
48
|
+
- 6
|
49
|
+
version: "1.6"
|
47
50
|
type: :runtime
|
48
51
|
version_requirements: *id002
|
49
52
|
- !ruby/object:Gem::Dependency
|
50
|
-
name:
|
53
|
+
name: json_pure
|
51
54
|
prerelease: false
|
52
55
|
requirement: &id003 !ruby/object:Gem::Requirement
|
53
56
|
none: false
|
54
57
|
requirements:
|
55
|
-
- -
|
58
|
+
- - ~>
|
56
59
|
- !ruby/object:Gem::Version
|
57
|
-
hash:
|
60
|
+
hash: 11
|
58
61
|
segments:
|
59
|
-
-
|
60
|
-
-
|
61
|
-
-
|
62
|
-
version:
|
62
|
+
- 1
|
63
|
+
- 4
|
64
|
+
- 6
|
65
|
+
version: 1.4.6
|
63
66
|
type: :runtime
|
64
67
|
version_requirements: *id003
|
68
|
+
- !ruby/object:Gem::Dependency
|
69
|
+
name: hashie
|
70
|
+
prerelease: false
|
71
|
+
requirement: &id004 !ruby/object:Gem::Requirement
|
72
|
+
none: false
|
73
|
+
requirements:
|
74
|
+
- - ~>
|
75
|
+
- !ruby/object:Gem::Version
|
76
|
+
hash: 15
|
77
|
+
segments:
|
78
|
+
- 1
|
79
|
+
- 0
|
80
|
+
version: "1.0"
|
81
|
+
type: :runtime
|
82
|
+
version_requirements: *id004
|
65
83
|
description: View information about a GitHub account
|
66
84
|
email: john@crepezzi.com
|
67
85
|
executables:
|
@@ -72,6 +90,7 @@ extra_rdoc_files: []
|
|
72
90
|
|
73
91
|
files:
|
74
92
|
- lib/vain/cli.rb
|
93
|
+
- lib/vain/github.rb
|
75
94
|
- lib/vain/version.rb
|
76
95
|
- lib/vain.rb
|
77
96
|
- bin/vain
|