usaidwat 0.0.2 → 0.0.3

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.
data/README.textile ADDED
@@ -0,0 +1,51 @@
1
+ h1(#usaidwat). usaidwat
2
+
3
+ Are you a Redditor? Do you use Ruby? Do you want to view the subreddits in which a particular user commonly posts? If you answered "yes" to all three of these questions, then *usaidwat* is the gem for you!
4
+
5
+ h2(#install). Installation
6
+
7
+ *usaidwat* can be installed via RubyGems:
8
+
9
+ bc. $ gem install usaidwat
10
+
11
+ h2(#usage). Usage
12
+
13
+ A @usaidwat@ binary is installed with the gem. @usaidwat@ will analyze a user's last 100 comments and provide statistics.
14
+
15
+ To list a count of subreddits in which a user has posted, simply plug in a username:
16
+
17
+ bc. # usaidwat jedberg
18
+
19
+ You will see output like the following:
20
+
21
+ bc. jedberg
22
+ -------
23
+ blog 26
24
+ funny 15
25
+ unitedkingdom 12
26
+ Random_Acts_Of_Pizza 11
27
+ AskReddit 7
28
+ entertainment 4
29
+ politics 4
30
+ TheoryOfReddit 3
31
+ Frugal 3
32
+ technology 2
33
+ fffffffuuuuuuuuuuuu 2
34
+ wikipedia 2
35
+ pics 1
36
+ programming 1
37
+ sex 1
38
+ space 1
39
+ movies 1
40
+ geek 1
41
+ comics 1
42
+ videos 1
43
+ apple 1
44
+
45
+ Which indicates that jedberg has commented in @/r/funny@ 15 times (out of his last 100 comments).
46
+
47
+ To see the comments for a specific subreddit, tack on that subreddit:
48
+
49
+ bc. $ usaidwat jedberg funny
50
+
51
+ All the comments for the given subreddit will be printed.
data/bin/usaidwat CHANGED
@@ -3,24 +3,36 @@
3
3
  require 'usaidwat'
4
4
 
5
5
 
6
+ VERSION = "usaidwat v#{USaidWat::VERSION}"
7
+ USAGE = "Usage: #{File.basename $0} <user> [<subreddit>]"
8
+
6
9
  def die(code=1)
7
- $stderr.puts "Usage: #{File.basename $0} <user> [<subreddit>]"
10
+ $stderr.puts VERSION
11
+ $stderr.puts USAGE
8
12
  exit code
9
13
  end
10
14
 
11
- die if $*.length < 1 or $*.length > 2
15
+ die if ARGV.length < 1 or ARGV.length > 2
16
+
17
+ if ARGV.first == '--help' or ARGV.first == '-h'
18
+ puts USAGE
19
+ exit 0
20
+ end
21
+
22
+ if ARGV.first == '--version' or ARGV.first == '-V'
23
+ puts VERSION
24
+ exit 0
25
+ end
12
26
 
13
- subreddit = $*.length == 2 ? $*.last : nil
14
- reddit_user = USaidWat::RedditUser.new $*.first
15
- unless subreddit
27
+ reddit_user = USaidWat::RedditUser.new ARGV.shift
28
+ if ARGV.length == 0
16
29
  comments = reddit_user.retrieve_comments
17
30
  exit 2 unless comments
18
31
  max_key = 1
19
- puts reddit_user.username
20
- puts '-' * reddit_user.username.length
21
32
  comments.each { |c| max_key = c.first.length if c.first.length > max_key }
22
33
  comments.each { |c| printf "%-*s %s\n", max_key, c.first, c.last }
23
34
  else
35
+ subreddit = ARGV.shift
24
36
  comments = reddit_user.comments_for_subreddit subreddit
25
37
  is_first = true
26
38
  width = `tput cols`.to_i rescue 80
@@ -82,8 +82,8 @@ module USaidWat
82
82
  def fetch_comments(count)
83
83
  comments = Array.new
84
84
  after = nil
85
- last_page = count / COMMENTS_PER_PAGE
86
- (1..last_page).each do |i|
85
+ pages = count / COMMENTS_PER_PAGE
86
+ pages.times do |i|
87
87
  query = i == 1 ? '' : {:count => COMMENTS_PER_PAGE, :after => after}.to_query
88
88
  url = "#{self.comments_url}.json?#{query}"
89
89
  resp = Net::HTTP.get_response 'www.reddit.com', url
@@ -1,3 +1,3 @@
1
1
  module USaidWat
2
- VERSION = "0.0.2"
2
+ VERSION = "0.0.3"
3
3
  end
data/lib/usaidwat.rb CHANGED
@@ -4,4 +4,11 @@ require 'usaidwat/reddit'
4
4
 
5
5
  module USaidWat
6
6
  BASE_CACHE_DIR = File.join File.expand_path('~'), '.usaidwat'
7
+
8
+ module Commands extend self
9
+ def damn(message, exit_code=1)
10
+ $stderr.puts message
11
+ exit exit_code
12
+ end
13
+ end
7
14
  end
data/usaidwat.gemspec CHANGED
@@ -8,7 +8,7 @@ Gem::Specification.new do |s|
8
8
  s.authors = ["Michael Dippery"]
9
9
  s.email = ["michael@monkey-robot.com"]
10
10
  s.homepage = ""
11
- s.summary = %q{View a user's last 100 Reddit comments}
11
+ s.summary = %q{Answers the age-old question, "Where does a Redditor comment the most?"}
12
12
  s.description = %q{View a user's last 100 Reddit comments, organized by subreddit.}
13
13
 
14
14
  s.rubyforge_project = "usaidwat"
@@ -18,5 +18,5 @@ Gem::Specification.new do |s|
18
18
  s.executables = `git ls-files -- bin/*`.split("\n").map{ |f| File.basename(f) }
19
19
  s.require_paths = ["lib"]
20
20
 
21
- s.add_runtime_dependency 'json'
21
+ s.add_runtime_dependency 'json', '>= 1.6.5'
22
22
  end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: usaidwat
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.0.2
4
+ version: 0.0.3
5
5
  prerelease:
6
6
  platform: ruby
7
7
  authors:
@@ -9,19 +9,19 @@ authors:
9
9
  autorequire:
10
10
  bindir: bin
11
11
  cert_chain: []
12
- date: 2012-01-24 00:00:00.000000000 Z
12
+ date: 2012-01-30 00:00:00.000000000 Z
13
13
  dependencies:
14
14
  - !ruby/object:Gem::Dependency
15
15
  name: json
16
- requirement: &70183205314920 !ruby/object:Gem::Requirement
16
+ requirement: &70163077554900 !ruby/object:Gem::Requirement
17
17
  none: false
18
18
  requirements:
19
19
  - - ! '>='
20
20
  - !ruby/object:Gem::Version
21
- version: '0'
21
+ version: 1.6.5
22
22
  type: :runtime
23
23
  prerelease: false
24
- version_requirements: *70183205314920
24
+ version_requirements: *70163077554900
25
25
  description: View a user's last 100 Reddit comments, organized by subreddit.
26
26
  email:
27
27
  - michael@monkey-robot.com
@@ -32,6 +32,7 @@ extra_rdoc_files: []
32
32
  files:
33
33
  - .gitignore
34
34
  - Gemfile
35
+ - README.textile
35
36
  - Rakefile
36
37
  - bin/usaidwat
37
38
  - lib/usaidwat.rb
@@ -61,5 +62,5 @@ rubyforge_project: usaidwat
61
62
  rubygems_version: 1.8.11
62
63
  signing_key:
63
64
  specification_version: 3
64
- summary: View a user's last 100 Reddit comments
65
+ summary: Answers the age-old question, "Where does a Redditor comment the most?"
65
66
  test_files: []