rg_stats 1.0.2 → 1.1.0
Sign up to get free protection for your applications and to get access to all the features.
- data/README.md +6 -0
- data/bin/rg_stats +45 -35
- data/lib/rg_stats/version.rb +1 -1
- metadata +1 -1
data/README.md
CHANGED
@@ -10,6 +10,12 @@ Get download statistic of your gems on RubyGems with a push of a button and stop
|
|
10
10
|
|
11
11
|
$ rg_stats your_user_name
|
12
12
|
|
13
|
+
You can use it for multiple accounts
|
14
|
+
|
15
|
+
$ rg_stats drKreso rsim
|
16
|
+
|
17
|
+
It will remember number of downloads since the last time you've checked. So you can spy on your competition...
|
18
|
+
|
13
19
|
## Caveat
|
14
20
|
|
15
21
|
User name is case sensitive for example mine is
|
data/bin/rg_stats
CHANGED
@@ -4,8 +4,6 @@ require 'yaml'
|
|
4
4
|
|
5
5
|
require_relative '../lib/rg_stats/statistic'
|
6
6
|
|
7
|
-
user_name = ARGV[0]
|
8
|
-
|
9
7
|
class PersistDataBetweenSessions
|
10
8
|
|
11
9
|
STORAGE_NAME = "/tmp/ruby_gems_sync.yaml"
|
@@ -18,41 +16,53 @@ class PersistDataBetweenSessions
|
|
18
16
|
end
|
19
17
|
end
|
20
18
|
|
21
|
-
|
22
|
-
puts ""
|
23
|
-
puts "Type username on RubyGems as argument: rg_stats user_name"
|
24
|
-
puts ""
|
25
|
-
exit
|
26
|
-
end
|
19
|
+
ARGV.each do |user_name|
|
27
20
|
|
28
|
-
|
29
|
-
|
30
|
-
|
31
|
-
|
32
|
-
|
33
|
-
|
34
|
-
rescue OpenURI::HTTPError => e
|
35
|
-
puts "User #{user_name} has not been found. (#{e.message})"
|
36
|
-
exit
|
37
|
-
end
|
38
|
-
old_data = PersistDataBetweenSessions.load
|
39
|
-
old_map = {}
|
40
|
-
old_data.each do |old_gem_info|
|
41
|
-
old_map[old_gem_info[0]] = old_gem_info[1]
|
42
|
-
end
|
21
|
+
if user_name.nil?
|
22
|
+
puts ""
|
23
|
+
puts "Type username on RubyGems as argument: rg_stats user_name"
|
24
|
+
puts ""
|
25
|
+
exit
|
26
|
+
end
|
43
27
|
|
44
|
-
|
45
|
-
|
28
|
+
url = "https://rubygems.org/api/v1/owners/#{user_name}/gems.json"
|
29
|
+
begin
|
30
|
+
data_as_json = open(url)
|
31
|
+
rescue SocketError => e
|
32
|
+
puts "It seems connection is not available. (#{e.message})"
|
33
|
+
exit
|
34
|
+
rescue OpenURI::HTTPError => e
|
35
|
+
puts "User #{user_name} has not been found. (#{e.message})"
|
36
|
+
exit
|
37
|
+
end
|
38
|
+
loaded_data = PersistDataBetweenSessions.load
|
39
|
+
if loaded_data.class == Array
|
40
|
+
all_data = {}
|
41
|
+
all_data[user_name] = loaded_data
|
42
|
+
else
|
43
|
+
all_data = loaded_data
|
44
|
+
end
|
46
45
|
|
47
|
-
|
48
|
-
|
49
|
-
|
50
|
-
|
51
|
-
|
52
|
-
|
53
|
-
|
46
|
+
old_data = all_data[user_name].nil? ? [] : all_data[user_name]
|
47
|
+
old_map = {}
|
48
|
+
old_data.each do |old_gem_info|
|
49
|
+
old_map[old_gem_info[0]] = old_gem_info[1]
|
50
|
+
end
|
51
|
+
|
52
|
+
stat = Statistic.new
|
53
|
+
stat.load data_as_json
|
54
|
+
|
55
|
+
puts ""
|
56
|
+
puts "\e[32m#{user_name}\e[0m"
|
54
57
|
puts "-" *(stat.max_gem_name_size + 30)
|
55
|
-
|
56
|
-
|
57
|
-
|
58
|
+
stat.gem_infos.each do |gem_info|
|
59
|
+
broj_izmjena = gem_info[1] - (old_map[gem_info[0]].nil? ? 0 : old_map[gem_info[0]])
|
60
|
+
diff_from_last_time = broj_izmjena == 0 ? "" : " (+\e[32m#{broj_izmjena}\e[0m)"
|
61
|
+
puts "%-#{stat.max_gem_name_size + 1}s=> %6d %6s" % [ gem_info[0] , gem_info[1], diff_from_last_time ]
|
62
|
+
puts "-" *(stat.max_gem_name_size + 30)
|
63
|
+
end
|
64
|
+
all_data[user_name] = stat.gem_infos
|
65
|
+
puts ""
|
66
|
+
PersistDataBetweenSessions.save(all_data)
|
58
67
|
|
68
|
+
end
|
data/lib/rg_stats/version.rb
CHANGED