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.
Files changed (4) hide show
  1. data/README.md +6 -0
  2. data/bin/rg_stats +45 -35
  3. data/lib/rg_stats/version.rb +1 -1
  4. 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
- if user_name.nil?
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
- 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
- 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
- stat = Statistic.new
45
- stat.load data_as_json
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
- puts ""
48
- puts "\e[32m#{user_name}\e[0m"
49
- puts "-" *(stat.max_gem_name_size + 30)
50
- stat.gem_infos.each do |gem_info|
51
- broj_izmjena = gem_info[1] - (old_map[gem_info[0]].nil? ? 0 : old_map[gem_info[0]])
52
- diff_from_last_time = broj_izmjena == 0 ? "" : " (+\e[32m#{broj_izmjena}\e[0m)"
53
- puts "%-#{stat.max_gem_name_size + 1}s=> %6d %6s" % [ gem_info[0] , gem_info[1], diff_from_last_time ]
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
- end
56
- puts ""
57
- PersistDataBetweenSessions.save(stat.gem_infos)
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
@@ -1,3 +1,3 @@
1
1
  module RgStats
2
- VERSION = "1.0.2"
2
+ VERSION = "1.1.0"
3
3
  end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: rg_stats
3
3
  version: !ruby/object:Gem::Version
4
- version: 1.0.2
4
+ version: 1.1.0
5
5
  prerelease:
6
6
  platform: ruby
7
7
  authors: