usaidwat 0.1.5 → 0.1.6
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.
- checksums.yaml +4 -4
- data/features/browse.feature +30 -12
- data/lib/usaidwat/application.rb +5 -3
- data/lib/usaidwat/ext/string.rb +4 -0
- data/lib/usaidwat/formatter.rb +10 -0
- data/lib/usaidwat/service.rb +3 -1
- data/lib/usaidwat/version.rb +1 -1
- data/spec/usaidwat/formatter_spec.rb +10 -0
- data/usaidwat.gemspec +6 -5
- metadata +19 -23
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: cb020c71be1b1132ce622e958ce732fd29ef086b
|
4
|
+
data.tar.gz: 629f6f970557e968bab7d850d4ee1c101f1c66a7
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: de40783e531b166a72f99c401a05007383b2f237dbe1717679fbd4ac6ed2750865e66bec4c5520cd25963faf4c4e6bfe0bf703f11fc7860ef712125573c89309
|
7
|
+
data.tar.gz: e825e1c9517ce21aea8ec086c1e23aec34ee2062cdb46ac0bd61f2aeb24c03677a6429d7b4b465eaf13496b5ab931c7273993b9576f3d89a3c5de355af8ed4d7
|
data/features/browse.feature
CHANGED
@@ -3,26 +3,32 @@ Feature: Browse comments
|
|
3
3
|
As a Redditor
|
4
4
|
I want to quickly be able to list another Redditor's comments
|
5
5
|
In order to see what they like to talk about
|
6
|
-
|
6
|
+
|
7
7
|
Scenario: List all comments
|
8
8
|
Given the Reddit service returns comments for the user "mipadi"
|
9
|
-
When I run `usaidwat mipadi
|
9
|
+
When I run `usaidwat mipadi`
|
10
10
|
Then it should pass with:
|
11
11
|
"""
|
12
12
|
wikipedia
|
13
13
|
http://www.reddit.com/r/wikipedia/comments/142t4w/z/c79peed
|
14
|
+
Heisenbug: a software bug that seems to disappear or alter its behavior when one
|
15
|
+
01 Dec 2012, 12:14 PM
|
14
16
|
|
15
17
|
Yep. My first experience with a Heisenbug occurred in a C++ program, and disappeared when I tried to print a variable with printf (only to reappear when that call was removed).
|
16
18
|
|
17
19
|
|
18
20
|
nyc
|
19
21
|
http://www.reddit.com/r/nyc/comments/141zqc/z/c79dxg6
|
22
|
+
NYC taxi roof lights get overhaul - A light simply will mean the cab is availab
|
23
|
+
30 Nov 2012, 04:44 PM
|
20
24
|
|
21
25
|
It has a fare when the lights are *off.*
|
22
26
|
|
23
27
|
|
24
28
|
worldnews
|
25
29
|
http://www.reddit.com/r/worldnews/comments/140mra/z/c797jq4
|
30
|
+
Palestinians win upgraded UN status by wide margin
|
31
|
+
30 Nov 2012, 10:09 AM
|
26
32
|
|
27
33
|
The Judgment of Solomon Accords.
|
28
34
|
"""
|
@@ -34,7 +40,7 @@ Feature: Browse comments
|
|
34
40
|
"""
|
35
41
|
No such user: palorchild
|
36
42
|
"""
|
37
|
-
|
43
|
+
|
38
44
|
Scenario: List all comments when user has no comments
|
39
45
|
Given the Reddit service returns comments for the user "blank"
|
40
46
|
When I run `usaidwat blank`
|
@@ -42,7 +48,7 @@ Feature: Browse comments
|
|
42
48
|
"""
|
43
49
|
blank has no comments.
|
44
50
|
"""
|
45
|
-
|
51
|
+
|
46
52
|
Scenario: Tally comments
|
47
53
|
Given the Reddit service returns comments for the user "mipadi"
|
48
54
|
When I run `usaidwat -t mipadi`
|
@@ -62,7 +68,7 @@ Feature: Browse comments
|
|
62
68
|
wikipedia 1
|
63
69
|
worldnews 2
|
64
70
|
"""
|
65
|
-
|
71
|
+
|
66
72
|
Scenario: Tally comments when user has no comments
|
67
73
|
Given the Reddit service returns comments for the user "blank"
|
68
74
|
When I run `usaidwat -t blank`
|
@@ -70,49 +76,61 @@ Feature: Browse comments
|
|
70
76
|
"""
|
71
77
|
blank has no comments.
|
72
78
|
"""
|
73
|
-
|
79
|
+
|
74
80
|
Scenario: List comments for a particular subreddit
|
75
81
|
Given the Reddit service returns comments for the user "mipadi"
|
76
|
-
When I run `usaidwat mipadi AskReddit
|
82
|
+
When I run `usaidwat mipadi AskReddit`
|
77
83
|
Then it should pass with:
|
78
84
|
"""
|
79
85
|
AskReddit
|
80
86
|
http://www.reddit.com/r/AskReddit/comments/141kt9/z/c795rwz
|
87
|
+
Do colleges actually teach students how to think critically? Or even to think/qu
|
88
|
+
30 Nov 2012, 08:27 AM
|
81
89
|
|
82
90
|
I think it depends on where you go and what you study, but yes, I think they do teach you to think critically, especially in humanities courses and seminars. Maybe it's just because I went to a small, private liberal arts college rather than a huge school, but critical thinking was definitely a part of my education.
|
83
91
|
|
84
92
|
|
85
93
|
AskReddit
|
86
94
|
http://www.reddit.com/r/AskReddit/comments/140t5c/z/c795nw3
|
95
|
+
I'm from Tennessee and most of our jokes are geared toward Mississippi and Alaba
|
96
|
+
30 Nov 2012, 08:20 AM
|
87
97
|
|
88
98
|
You're from New Jersey? Which exit?
|
89
99
|
|
90
100
|
|
91
101
|
AskReddit
|
92
102
|
http://www.reddit.com/r/AskReddit/comments/140h3z/z/c795muo
|
103
|
+
Today I was going 80mph in a 55 when an unmarked police car pulled up next to me
|
104
|
+
30 Nov 2012, 08:19 AM
|
93
105
|
|
94
106
|
You didn't slow down for very long though, did you?
|
95
107
|
"""
|
96
|
-
|
108
|
+
|
97
109
|
Scenario: List comments for a particular subreddit specified with the wrong case
|
98
110
|
Given the Reddit service returns comments for the user "mipadi"
|
99
|
-
When I run `usaidwat mipadi askreddit
|
111
|
+
When I run `usaidwat mipadi askreddit`
|
100
112
|
Then it should pass with:
|
101
113
|
"""
|
102
114
|
AskReddit
|
103
115
|
http://www.reddit.com/r/AskReddit/comments/141kt9/z/c795rwz
|
116
|
+
Do colleges actually teach students how to think critically? Or even to think/qu
|
117
|
+
30 Nov 2012, 08:27 AM
|
104
118
|
|
105
119
|
I think it depends on where you go and what you study, but yes, I think they do teach you to think critically, especially in humanities courses and seminars. Maybe it's just because I went to a small, private liberal arts college rather than a huge school, but critical thinking was definitely a part of my education.
|
106
120
|
|
107
121
|
|
108
122
|
AskReddit
|
109
123
|
http://www.reddit.com/r/AskReddit/comments/140t5c/z/c795nw3
|
124
|
+
I'm from Tennessee and most of our jokes are geared toward Mississippi and Alaba
|
125
|
+
30 Nov 2012, 08:20 AM
|
110
126
|
|
111
127
|
You're from New Jersey? Which exit?
|
112
128
|
|
113
129
|
|
114
130
|
AskReddit
|
115
131
|
http://www.reddit.com/r/AskReddit/comments/140h3z/z/c795muo
|
132
|
+
Today I was going 80mph in a 55 when an unmarked police car pulled up next to me
|
133
|
+
30 Nov 2012, 08:19 AM
|
116
134
|
|
117
135
|
You didn't slow down for very long though, did you?
|
118
136
|
"""
|
@@ -124,7 +142,7 @@ Feature: Browse comments
|
|
124
142
|
"""
|
125
143
|
No comments by mipadi for nsfw.
|
126
144
|
"""
|
127
|
-
|
145
|
+
|
128
146
|
Scenario: Tally comments with subreddit
|
129
147
|
Given the Reddit service returns comments for the user "mipadi"
|
130
148
|
When I run `usaidwat -t mipadi AskReddit`
|
@@ -132,7 +150,7 @@ Feature: Browse comments
|
|
132
150
|
"""
|
133
151
|
Usage: usaidwat [-t] <user> [<subreddit>]
|
134
152
|
"""
|
135
|
-
|
153
|
+
|
136
154
|
Scenario: Pass no arguments
|
137
155
|
Given the Reddit service returns comments for the user "mipadi"
|
138
156
|
When I run `usaidwat`
|
@@ -140,7 +158,7 @@ Feature: Browse comments
|
|
140
158
|
"""
|
141
159
|
Usage: usaidwat [-t] <user> [<subreddit>]
|
142
160
|
"""
|
143
|
-
|
161
|
+
|
144
162
|
Scenario: Pass no arguments when tallying
|
145
163
|
Given the Reddit service returns comments for the user "mipadi"
|
146
164
|
When I run `usaidwat -t`
|
data/lib/usaidwat/application.rb
CHANGED
@@ -9,6 +9,7 @@ module USaidWat
|
|
9
9
|
class Application
|
10
10
|
def initialize(client)
|
11
11
|
@client = client
|
12
|
+
Signal.trap("PIPE", "EXIT")
|
12
13
|
end
|
13
14
|
|
14
15
|
def run(argv)
|
@@ -17,7 +18,7 @@ module USaidWat
|
|
17
18
|
username = args.first
|
18
19
|
@redditor = @client.new(username)
|
19
20
|
begin
|
20
|
-
return tally_comments if opts
|
21
|
+
return tally_comments if opts.tally
|
21
22
|
return list_comments_for_subreddit(args[1]) if args.length == 2
|
22
23
|
return list_all_comments
|
23
24
|
rescue USaidWat::Client::NoSuchUserError
|
@@ -77,12 +78,13 @@ module USaidWat
|
|
77
78
|
|
78
79
|
private
|
79
80
|
def handle_arguments(argv)
|
81
|
+
opts = OpenStruct.new
|
82
|
+
opts.tally = false
|
80
83
|
usage(1) if argv.length == 0
|
81
84
|
usage if argv.first == "--help"
|
82
85
|
version if argv.first == "--version"
|
83
|
-
opts = {:tally => false}
|
84
86
|
if argv.first == "-t"
|
85
|
-
opts
|
87
|
+
opts.tally = true
|
86
88
|
argv.shift
|
87
89
|
usage(1) unless argv.length == 1
|
88
90
|
end
|
data/lib/usaidwat/ext/string.rb
CHANGED
data/lib/usaidwat/formatter.rb
CHANGED
@@ -1,3 +1,5 @@
|
|
1
|
+
require 'date'
|
2
|
+
require 'highline'
|
1
3
|
require 'stringio'
|
2
4
|
require 'rainbow/ext/string'
|
3
5
|
require 'usaidwat/ext/string'
|
@@ -12,10 +14,13 @@ module USaidWat
|
|
12
14
|
end
|
13
15
|
|
14
16
|
def format(comment)
|
17
|
+
cols = HighLine::SystemExtensions.terminal_size[0]
|
15
18
|
out = StringIO.new
|
16
19
|
out.write("\n\n") unless @count == 0
|
17
20
|
out.write("#{comment.subreddit}\n".color(:green))
|
18
21
|
out.write("#{comment_link(comment)}\n".color(:yellow))
|
22
|
+
out.write("#{comment.link_title.strip.truncate(cols)}\n".color(:red))
|
23
|
+
out.write("#{comment_date(comment)}\n".color(:blue))
|
19
24
|
out.write("\n")
|
20
25
|
out.write("#{comment.body.strip.convert_entities}\n")
|
21
26
|
@count += 1
|
@@ -28,6 +33,11 @@ module USaidWat
|
|
28
33
|
link = comment.link_id.split("_")[-1]
|
29
34
|
"http://www.reddit.com/r/#{comment.subreddit}/comments/#{link}/z/#{comment.id}"
|
30
35
|
end
|
36
|
+
|
37
|
+
def comment_date(comment)
|
38
|
+
fmt = ENV['USAIDWAT_TIME_FORMAT'] || '%d %b %Y, %I:%M %p'
|
39
|
+
DateTime.strptime(comment.created_utc.to_s, "%s").to_time.localtime.strftime(fmt)
|
40
|
+
end
|
31
41
|
end
|
32
42
|
end
|
33
43
|
end
|
data/lib/usaidwat/service.rb
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
module USaidWat
|
2
2
|
module Service
|
3
3
|
class MockComment
|
4
|
-
attr_reader :subreddit, :body, :id, :link_id
|
4
|
+
attr_reader :subreddit, :body, :id, :link_id, :created_utc, :link_title
|
5
5
|
|
6
6
|
def initialize(dict)
|
7
7
|
data = dict['data']
|
@@ -9,6 +9,8 @@ module USaidWat
|
|
9
9
|
@body = data['body']
|
10
10
|
@id = data['id']
|
11
11
|
@link_id = data['link_id']
|
12
|
+
@created_utc = data['created_utc']
|
13
|
+
@link_title = data['link_title']
|
12
14
|
end
|
13
15
|
end
|
14
16
|
|
data/lib/usaidwat/version.rb
CHANGED
@@ -11,10 +11,14 @@ module USaidWat
|
|
11
11
|
expect(comment).to receive(:subreddit).twice.and_return("programming")
|
12
12
|
expect(comment).to receive(:link_id).and_return("t3_13f783")
|
13
13
|
expect(comment).to receive(:id).and_return("c73qhxi")
|
14
|
+
expect(comment).to receive(:link_title).and_return("Why Brit Ruby 2013 was cancelled and why this is not ok - Gist")
|
15
|
+
expect(comment).to receive(:created_utc).and_return(1433378314.0)
|
14
16
|
expect(comment).to receive(:body).and_return("Welcome to the wonderful world of Python drama!")
|
15
17
|
expected = <<-EXPECTED
|
16
18
|
programming
|
17
19
|
http://www.reddit.com/r/programming/comments/13f783/z/c73qhxi
|
20
|
+
Why Brit Ruby 2013 was cancelled and why this is not ok - Gist
|
21
|
+
03 Jun 2015, 05:38 PM
|
18
22
|
|
19
23
|
Welcome to the wonderful world of Python drama!
|
20
24
|
EXPECTED
|
@@ -27,11 +31,15 @@ EXPECTED
|
|
27
31
|
expect(comment1).to receive(:subreddit).twice.and_return("programming")
|
28
32
|
expect(comment1).to receive(:link_id).and_return("t3_13f783")
|
29
33
|
expect(comment1).to receive(:id).and_return("c73qhxi")
|
34
|
+
expect(comment1).to receive(:created_utc).and_return(1433378314.0)
|
35
|
+
expect(comment1).to receive(:link_title).and_return("Why Brit Ruby 2013 was cancelled and why this is not ok - Gist")
|
30
36
|
expect(comment1).to receive(:body).and_return("Welcome to the wonderful world of Python drama!")
|
31
37
|
comment2 = double("second comment")
|
32
38
|
expect(comment2).to receive(:subreddit).twice.and_return("programming")
|
33
39
|
expect(comment2).to receive(:link_id).and_return("t3_13f783")
|
34
40
|
expect(comment2).to receive(:id).and_return("c73qhxi")
|
41
|
+
expect(comment2).to receive(:created_utc).and_return(1433378314.0)
|
42
|
+
expect(comment2).to receive(:link_title).and_return("Why Brit Ruby 2013 was cancelled and why this is not ok - Gist")
|
35
43
|
expect(comment2).to receive(:body).and_return("Welcome to the wonderful world of Python drama!")
|
36
44
|
s = formatter.format(comment1)
|
37
45
|
s = formatter.format(comment2)
|
@@ -46,6 +54,8 @@ EXPECTED
|
|
46
54
|
expect(comment).to receive(:subreddit).twice.and_return("test")
|
47
55
|
expect(comment).to receive(:link_id).and_return("t3_13f783")
|
48
56
|
expect(comment).to receive(:id).and_return("c73qhxi")
|
57
|
+
expect(comment).to receive(:created_utc).and_return(1433378314.0)
|
58
|
+
expect(comment).to receive(:link_title).and_return("Why Brit Ruby 2013 was cancelled and why this is not ok - Gist")
|
49
59
|
expect(comment).to receive(:body).and_return("This is a comment.\n\nIt has two lines.\n\n\n")
|
50
60
|
s = formatter.format(comment)
|
51
61
|
lines = s.split("\n")
|
data/usaidwat.gemspec
CHANGED
@@ -18,11 +18,12 @@ Gem::Specification.new do |gem|
|
|
18
18
|
gem.test_files = gem.files.grep(%r{^(test|spec|features)/})
|
19
19
|
gem.require_paths = ["lib"]
|
20
20
|
|
21
|
-
gem.
|
22
|
-
gem.
|
21
|
+
gem.add_runtime_dependency('snooby', '~> 0.1.5')
|
22
|
+
gem.add_runtime_dependency('rainbow', '~> 2.0')
|
23
|
+
gem.add_runtime_dependency('highline', '~> 1.7', '>= 1.7.2')
|
23
24
|
|
24
|
-
gem.add_development_dependency('rspec', '~> 3.2'
|
25
|
-
gem.add_development_dependency('cucumber', '~> 2.0'
|
25
|
+
gem.add_development_dependency('rspec', '~> 3.2')
|
26
|
+
gem.add_development_dependency('cucumber', '~> 2.0')
|
26
27
|
gem.add_development_dependency('aruba', '~> 0.6.2')
|
27
|
-
gem.add_development_dependency('webmock', '~> 1.21'
|
28
|
+
gem.add_development_dependency('webmock', '~> 1.21')
|
28
29
|
end
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: usaidwat
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.1.
|
4
|
+
version: 0.1.6
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Michael Dippery
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2015-
|
11
|
+
date: 2015-06-23 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: snooby
|
@@ -31,19 +31,33 @@ dependencies:
|
|
31
31
|
- - "~>"
|
32
32
|
- !ruby/object:Gem::Version
|
33
33
|
version: '2.0'
|
34
|
+
type: :runtime
|
35
|
+
prerelease: false
|
36
|
+
version_requirements: !ruby/object:Gem::Requirement
|
37
|
+
requirements:
|
38
|
+
- - "~>"
|
39
|
+
- !ruby/object:Gem::Version
|
40
|
+
version: '2.0'
|
41
|
+
- !ruby/object:Gem::Dependency
|
42
|
+
name: highline
|
43
|
+
requirement: !ruby/object:Gem::Requirement
|
44
|
+
requirements:
|
45
|
+
- - "~>"
|
46
|
+
- !ruby/object:Gem::Version
|
47
|
+
version: '1.7'
|
34
48
|
- - ">="
|
35
49
|
- !ruby/object:Gem::Version
|
36
|
-
version:
|
50
|
+
version: 1.7.2
|
37
51
|
type: :runtime
|
38
52
|
prerelease: false
|
39
53
|
version_requirements: !ruby/object:Gem::Requirement
|
40
54
|
requirements:
|
41
55
|
- - "~>"
|
42
56
|
- !ruby/object:Gem::Version
|
43
|
-
version: '
|
57
|
+
version: '1.7'
|
44
58
|
- - ">="
|
45
59
|
- !ruby/object:Gem::Version
|
46
|
-
version:
|
60
|
+
version: 1.7.2
|
47
61
|
- !ruby/object:Gem::Dependency
|
48
62
|
name: rspec
|
49
63
|
requirement: !ruby/object:Gem::Requirement
|
@@ -51,9 +65,6 @@ dependencies:
|
|
51
65
|
- - "~>"
|
52
66
|
- !ruby/object:Gem::Version
|
53
67
|
version: '3.2'
|
54
|
-
- - ">="
|
55
|
-
- !ruby/object:Gem::Version
|
56
|
-
version: 3.2.0
|
57
68
|
type: :development
|
58
69
|
prerelease: false
|
59
70
|
version_requirements: !ruby/object:Gem::Requirement
|
@@ -61,9 +72,6 @@ dependencies:
|
|
61
72
|
- - "~>"
|
62
73
|
- !ruby/object:Gem::Version
|
63
74
|
version: '3.2'
|
64
|
-
- - ">="
|
65
|
-
- !ruby/object:Gem::Version
|
66
|
-
version: 3.2.0
|
67
75
|
- !ruby/object:Gem::Dependency
|
68
76
|
name: cucumber
|
69
77
|
requirement: !ruby/object:Gem::Requirement
|
@@ -71,9 +79,6 @@ dependencies:
|
|
71
79
|
- - "~>"
|
72
80
|
- !ruby/object:Gem::Version
|
73
81
|
version: '2.0'
|
74
|
-
- - ">="
|
75
|
-
- !ruby/object:Gem::Version
|
76
|
-
version: 2.0.0
|
77
82
|
type: :development
|
78
83
|
prerelease: false
|
79
84
|
version_requirements: !ruby/object:Gem::Requirement
|
@@ -81,9 +86,6 @@ dependencies:
|
|
81
86
|
- - "~>"
|
82
87
|
- !ruby/object:Gem::Version
|
83
88
|
version: '2.0'
|
84
|
-
- - ">="
|
85
|
-
- !ruby/object:Gem::Version
|
86
|
-
version: 2.0.0
|
87
89
|
- !ruby/object:Gem::Dependency
|
88
90
|
name: aruba
|
89
91
|
requirement: !ruby/object:Gem::Requirement
|
@@ -105,9 +107,6 @@ dependencies:
|
|
105
107
|
- - "~>"
|
106
108
|
- !ruby/object:Gem::Version
|
107
109
|
version: '1.21'
|
108
|
-
- - ">="
|
109
|
-
- !ruby/object:Gem::Version
|
110
|
-
version: 1.21.0
|
111
110
|
type: :development
|
112
111
|
prerelease: false
|
113
112
|
version_requirements: !ruby/object:Gem::Requirement
|
@@ -115,9 +114,6 @@ dependencies:
|
|
115
114
|
- - "~>"
|
116
115
|
- !ruby/object:Gem::Version
|
117
116
|
version: '1.21'
|
118
|
-
- - ">="
|
119
|
-
- !ruby/object:Gem::Version
|
120
|
-
version: 1.21.0
|
121
117
|
description: View a user's last 100 Reddit comments, organized by subreddit.
|
122
118
|
email:
|
123
119
|
- michael@monkey-robot.com
|