usaidwat 0.1.3 → 0.1.4
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 +7 -0
- data/Gemfile +4 -0
- data/LICENSE.txt +1 -1
- data/Rakefile +8 -0
- data/features/browse.feature +13 -13
- data/lib/usaidwat/application.rb +19 -13
- data/lib/usaidwat/client.rb +20 -12
- data/lib/usaidwat/service.rb +34 -0
- data/lib/usaidwat/version.rb +1 -1
- data/spec/spec_helper.rb +1 -0
- data/spec/usaidwat/service_spec.rb +57 -0
- data/usaidwat.gemspec +0 -1
- metadata +23 -52
- data/features/server/reddit.rb +0 -14
checksums.yaml
ADDED
@@ -0,0 +1,7 @@
|
|
1
|
+
---
|
2
|
+
SHA1:
|
3
|
+
metadata.gz: 9f557c3aa3e4261f4f2c28783728e17c5043fdca
|
4
|
+
data.tar.gz: 9fa6307833d5f28c44425e9cd2469b46a67229d4
|
5
|
+
SHA512:
|
6
|
+
metadata.gz: bcda2502165ff5d8c73dbfa11ae4c593856c874514b88ae36c6c651bd568a8e1afcaabc746f7e74639f060a7b3f66bb840484a7544f71ae57a021dac8d4f4126
|
7
|
+
data.tar.gz: 4d2f7b4c5e44fd2025de35c64c6d68dd3fe40b8a22fe23a9a15bcb234442a1f672424630594dc15173997e417b243b80796b3461eea97c0caceb0134644fff2c
|
data/Gemfile
CHANGED
data/LICENSE.txt
CHANGED
data/Rakefile
CHANGED
@@ -3,4 +3,12 @@ require "bundler/gem_tasks"
|
|
3
3
|
desc "Clean built products"
|
4
4
|
task :clean do
|
5
5
|
rm_rf "pkg", :verbose => true
|
6
|
+
rm Dir.glob("*.gem"), :verbose => true
|
7
|
+
end
|
8
|
+
|
9
|
+
namespace :test do
|
10
|
+
desc "Run the fake web service"
|
11
|
+
task :server do
|
12
|
+
system "bundle exec ruby features/server/reddit.rb"
|
13
|
+
end
|
6
14
|
end
|
data/features/browse.feature
CHANGED
@@ -40,19 +40,19 @@ Feature: Browse comments
|
|
40
40
|
When I run `usaidwat -t mipadi`
|
41
41
|
Then it should pass with:
|
42
42
|
"""
|
43
|
-
apple
|
44
|
-
AskReddit
|
45
|
-
battlefield3
|
46
|
-
books
|
47
|
-
django
|
48
|
-
Games
|
49
|
-
nyc
|
50
|
-
personalfinance
|
51
|
-
photography
|
52
|
-
programming
|
53
|
-
redditcasual
|
54
|
-
wikipedia
|
55
|
-
worldnews
|
43
|
+
apple 6
|
44
|
+
AskReddit 61
|
45
|
+
battlefield3 2
|
46
|
+
books 2
|
47
|
+
django 1
|
48
|
+
Games 1
|
49
|
+
nyc 1
|
50
|
+
personalfinance 1
|
51
|
+
photography 1
|
52
|
+
programming 20
|
53
|
+
redditcasual 1
|
54
|
+
wikipedia 1
|
55
|
+
worldnews 2
|
56
56
|
"""
|
57
57
|
|
58
58
|
Scenario: Tally comments when user has no comments
|
data/lib/usaidwat/application.rb
CHANGED
@@ -1,40 +1,46 @@
|
|
1
1
|
module USaidWat
|
2
2
|
class << self
|
3
3
|
def application
|
4
|
-
|
4
|
+
client = ENV['USAIDWAT_ENV'] == 'cucumber' ? USaidWat::Client::TestRedditor : USaidWat::Client::Redditor
|
5
|
+
@application ||= USaidWat::Application.new(client)
|
5
6
|
end
|
6
7
|
end
|
7
|
-
|
8
|
+
|
8
9
|
class Application
|
10
|
+
def initialize(client)
|
11
|
+
@client = client
|
12
|
+
end
|
13
|
+
|
9
14
|
def run(argv)
|
10
|
-
|
11
|
-
|
12
|
-
|
15
|
+
trap("INT") { puts; exit 0 }
|
16
|
+
opts, args = handle_arguments(argv)
|
17
|
+
@redditor = @client.new(args.first)
|
18
|
+
return tally_comments if opts[:tally]
|
13
19
|
return list_comments_for_subreddit(args[1]) if args.length == 2
|
14
20
|
return list_all_comments
|
15
21
|
end
|
16
|
-
|
22
|
+
|
17
23
|
def usage(code=0)
|
18
24
|
puts "Usage: usaidwat [-t] <user> [<subreddit>]"
|
19
25
|
exit code
|
20
26
|
end
|
21
|
-
|
27
|
+
|
22
28
|
def version(code=0)
|
23
29
|
puts "usaidwat v#{USaidWat::VERSION}"
|
24
30
|
exit 0
|
25
31
|
end
|
26
|
-
|
32
|
+
|
27
33
|
def quit(message, code=0)
|
28
34
|
puts message
|
29
35
|
exit code
|
30
36
|
end
|
31
|
-
|
37
|
+
|
32
38
|
def list_all_comments
|
33
39
|
quit "#{@redditor.username} has no comments." if @redditor.comments.empty?
|
34
40
|
formatter = USaidWat::CLI::CommentFormatter.new
|
35
41
|
@redditor.comments.each { |c| print formatter.format(c) }
|
36
42
|
end
|
37
|
-
|
43
|
+
|
38
44
|
def list_comments_for_subreddit(subreddit)
|
39
45
|
comments = @redditor.comments
|
40
46
|
comments = comments.reject { |c| c.subreddit != subreddit }
|
@@ -42,7 +48,7 @@ module USaidWat
|
|
42
48
|
formatter = USaidWat::CLI::CommentFormatter.new
|
43
49
|
comments.each { |c| print formatter.format(c) }
|
44
50
|
end
|
45
|
-
|
51
|
+
|
46
52
|
def tally_comments
|
47
53
|
quit "#{@redditor.username} has no comments." if @redditor.comments.empty?
|
48
54
|
# Unfortunately Snooby cannot return comments for a specific
|
@@ -58,11 +64,11 @@ module USaidWat
|
|
58
64
|
subreddits = buckets.keys.sort { |a,b| a.downcase <=> b.downcase }
|
59
65
|
subreddits.each do |subreddit|
|
60
66
|
tally = buckets[subreddit]
|
61
|
-
printf "%-*s %
|
67
|
+
printf "%-*s %3d\n", longest_subreddit, subreddit, tally
|
62
68
|
end
|
63
69
|
exit 0
|
64
70
|
end
|
65
|
-
|
71
|
+
|
66
72
|
private
|
67
73
|
def handle_arguments(argv)
|
68
74
|
usage(1) if argv.length == 0
|
data/lib/usaidwat/client.rb
CHANGED
@@ -1,32 +1,40 @@
|
|
1
1
|
require 'snooby'
|
2
|
+
require 'usaidwat/service'
|
2
3
|
|
3
4
|
module USaidWat
|
4
5
|
module Client
|
5
6
|
class ReachabilityError < RuntimeError; end
|
6
|
-
|
7
|
-
class
|
7
|
+
|
8
|
+
class BaseRedditor
|
8
9
|
attr_reader :username
|
9
|
-
|
10
|
+
|
10
11
|
def initialize(username)
|
11
|
-
enable_test_urls if ENV['USAIDWAT_ENV'] == 'cucumber'
|
12
12
|
@username = username
|
13
|
-
@service = Snooby::Client.new("usaidwat v#{USaidWat::VERSION}")
|
14
13
|
end
|
15
|
-
|
14
|
+
|
16
15
|
def comments
|
17
16
|
@service.user(username).comments(100)
|
18
17
|
rescue TypeError
|
19
18
|
raise ReachabilityError, "Reddit unreachable"
|
20
19
|
end
|
21
|
-
|
20
|
+
|
22
21
|
def to_s
|
23
22
|
"#{username}"
|
24
23
|
end
|
25
|
-
|
26
|
-
|
27
|
-
|
28
|
-
|
29
|
-
|
24
|
+
end
|
25
|
+
|
26
|
+
class Redditor < BaseRedditor
|
27
|
+
def initialize(username)
|
28
|
+
@service = Snooby::Client.new("usaidwat v#{USaidWat::VERSION}")
|
29
|
+
super
|
30
|
+
end
|
31
|
+
end
|
32
|
+
|
33
|
+
class TestRedditor < BaseRedditor
|
34
|
+
def initialize(username)
|
35
|
+
@service = USaidWat::Service::MockService.new
|
36
|
+
super
|
37
|
+
end
|
30
38
|
end
|
31
39
|
end
|
32
40
|
end
|
@@ -0,0 +1,34 @@
|
|
1
|
+
module USaidWat
|
2
|
+
module Service
|
3
|
+
class MockComment
|
4
|
+
attr_reader :subreddit, :body, :id, :link_id
|
5
|
+
|
6
|
+
def initialize(dict)
|
7
|
+
data = dict['data']
|
8
|
+
@subreddit = data['subreddit']
|
9
|
+
@body = data['body']
|
10
|
+
@id = data['id']
|
11
|
+
@link_id = data['link_id']
|
12
|
+
end
|
13
|
+
end
|
14
|
+
|
15
|
+
class MockUser
|
16
|
+
def initialize(username)
|
17
|
+
@username = username
|
18
|
+
end
|
19
|
+
|
20
|
+
def comments(n)
|
21
|
+
path = File.join(File.dirname(__FILE__), "..", "..", "features", "fixtures", "#{@username}.json")
|
22
|
+
json = IO.read(path)
|
23
|
+
json = JSON.parse(json)
|
24
|
+
json['data']['children'].map { |d| MockComment.new(d) }
|
25
|
+
end
|
26
|
+
end
|
27
|
+
|
28
|
+
class MockService
|
29
|
+
def user(username)
|
30
|
+
MockUser.new(username)
|
31
|
+
end
|
32
|
+
end
|
33
|
+
end
|
34
|
+
end
|
data/lib/usaidwat/version.rb
CHANGED
data/spec/spec_helper.rb
CHANGED
@@ -0,0 +1,57 @@
|
|
1
|
+
require 'spec_helper'
|
2
|
+
|
3
|
+
module USaidWat
|
4
|
+
module Service
|
5
|
+
describe MockService do
|
6
|
+
let (:service) { MockService.new }
|
7
|
+
|
8
|
+
describe "#user" do
|
9
|
+
it "returns a mock user" do
|
10
|
+
service.user("mipadi").should respond_to(:comments)
|
11
|
+
end
|
12
|
+
end
|
13
|
+
end
|
14
|
+
|
15
|
+
describe MockUser do
|
16
|
+
let (:user) { MockUser.new("mipadi") }
|
17
|
+
|
18
|
+
describe "#comments" do
|
19
|
+
it "should return an array of comments" do
|
20
|
+
user.comments(100).should respond_to(:count)
|
21
|
+
user.comments(100).should respond_to(:reject)
|
22
|
+
user.comments(100).should respond_to(:empty?)
|
23
|
+
user.comments(100).should respond_to(:each)
|
24
|
+
user.comments(100).count.should == 100
|
25
|
+
end
|
26
|
+
end
|
27
|
+
end
|
28
|
+
|
29
|
+
describe MockComment do
|
30
|
+
let (:comment) { MockUser.new("mipadi").comments(100).first }
|
31
|
+
|
32
|
+
describe "#subreddit" do
|
33
|
+
it "should return a string denoting what subreddit it belongs to" do
|
34
|
+
comment.subreddit.should == "wikipedia"
|
35
|
+
end
|
36
|
+
end
|
37
|
+
|
38
|
+
describe "#body" do
|
39
|
+
it "should return the comment's body" do
|
40
|
+
comment.body.should == "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)."
|
41
|
+
end
|
42
|
+
end
|
43
|
+
|
44
|
+
describe "#id" do
|
45
|
+
it "should return an ID" do
|
46
|
+
comment.id.should == "c79peed"
|
47
|
+
end
|
48
|
+
end
|
49
|
+
|
50
|
+
describe "#link_id" do
|
51
|
+
it "should return a link ID" do
|
52
|
+
comment.link_id.should == "t3_142t4w"
|
53
|
+
end
|
54
|
+
end
|
55
|
+
end
|
56
|
+
end
|
57
|
+
end
|
data/usaidwat.gemspec
CHANGED
metadata
CHANGED
@@ -1,128 +1,99 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: usaidwat
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.1.
|
5
|
-
prerelease:
|
4
|
+
version: 0.1.4
|
6
5
|
platform: ruby
|
7
6
|
authors:
|
8
7
|
- Michael Dippery
|
9
8
|
autorequire:
|
10
9
|
bindir: bin
|
11
10
|
cert_chain: []
|
12
|
-
date:
|
11
|
+
date: 2014-04-18 00:00:00.000000000 Z
|
13
12
|
dependencies:
|
14
13
|
- !ruby/object:Gem::Dependency
|
15
14
|
name: snooby
|
16
15
|
requirement: !ruby/object:Gem::Requirement
|
17
|
-
none: false
|
18
16
|
requirements:
|
19
|
-
- - ~>
|
17
|
+
- - "~>"
|
20
18
|
- !ruby/object:Gem::Version
|
21
19
|
version: 0.1.5
|
22
20
|
type: :runtime
|
23
21
|
prerelease: false
|
24
22
|
version_requirements: !ruby/object:Gem::Requirement
|
25
|
-
none: false
|
26
23
|
requirements:
|
27
|
-
- - ~>
|
24
|
+
- - "~>"
|
28
25
|
- !ruby/object:Gem::Version
|
29
26
|
version: 0.1.5
|
30
27
|
- !ruby/object:Gem::Dependency
|
31
28
|
name: rainbow
|
32
29
|
requirement: !ruby/object:Gem::Requirement
|
33
|
-
none: false
|
34
30
|
requirements:
|
35
|
-
- - ~>
|
31
|
+
- - "~>"
|
36
32
|
- !ruby/object:Gem::Version
|
37
33
|
version: 1.1.4
|
38
34
|
type: :runtime
|
39
35
|
prerelease: false
|
40
36
|
version_requirements: !ruby/object:Gem::Requirement
|
41
|
-
none: false
|
42
37
|
requirements:
|
43
|
-
- - ~>
|
38
|
+
- - "~>"
|
44
39
|
- !ruby/object:Gem::Version
|
45
40
|
version: 1.1.4
|
46
41
|
- !ruby/object:Gem::Dependency
|
47
42
|
name: rspec
|
48
43
|
requirement: !ruby/object:Gem::Requirement
|
49
|
-
none: false
|
50
44
|
requirements:
|
51
|
-
- - ~>
|
45
|
+
- - "~>"
|
52
46
|
- !ruby/object:Gem::Version
|
53
47
|
version: 2.12.0
|
54
48
|
type: :development
|
55
49
|
prerelease: false
|
56
50
|
version_requirements: !ruby/object:Gem::Requirement
|
57
|
-
none: false
|
58
51
|
requirements:
|
59
|
-
- - ~>
|
52
|
+
- - "~>"
|
60
53
|
- !ruby/object:Gem::Version
|
61
54
|
version: 2.12.0
|
62
55
|
- !ruby/object:Gem::Dependency
|
63
56
|
name: cucumber
|
64
57
|
requirement: !ruby/object:Gem::Requirement
|
65
|
-
none: false
|
66
58
|
requirements:
|
67
|
-
- - ~>
|
59
|
+
- - "~>"
|
68
60
|
- !ruby/object:Gem::Version
|
69
61
|
version: 1.2.1
|
70
62
|
type: :development
|
71
63
|
prerelease: false
|
72
64
|
version_requirements: !ruby/object:Gem::Requirement
|
73
|
-
none: false
|
74
65
|
requirements:
|
75
|
-
- - ~>
|
66
|
+
- - "~>"
|
76
67
|
- !ruby/object:Gem::Version
|
77
68
|
version: 1.2.1
|
78
69
|
- !ruby/object:Gem::Dependency
|
79
70
|
name: aruba
|
80
71
|
requirement: !ruby/object:Gem::Requirement
|
81
|
-
none: false
|
82
72
|
requirements:
|
83
|
-
- - ~>
|
73
|
+
- - "~>"
|
84
74
|
- !ruby/object:Gem::Version
|
85
75
|
version: 0.5.1
|
86
76
|
type: :development
|
87
77
|
prerelease: false
|
88
78
|
version_requirements: !ruby/object:Gem::Requirement
|
89
|
-
none: false
|
90
79
|
requirements:
|
91
|
-
- - ~>
|
80
|
+
- - "~>"
|
92
81
|
- !ruby/object:Gem::Version
|
93
82
|
version: 0.5.1
|
94
83
|
- !ruby/object:Gem::Dependency
|
95
84
|
name: webmock
|
96
85
|
requirement: !ruby/object:Gem::Requirement
|
97
|
-
none: false
|
98
86
|
requirements:
|
99
|
-
- - ~>
|
87
|
+
- - "~>"
|
100
88
|
- !ruby/object:Gem::Version
|
101
89
|
version: 1.9.0
|
102
90
|
type: :development
|
103
91
|
prerelease: false
|
104
92
|
version_requirements: !ruby/object:Gem::Requirement
|
105
|
-
none: false
|
106
93
|
requirements:
|
107
|
-
- - ~>
|
94
|
+
- - "~>"
|
108
95
|
- !ruby/object:Gem::Version
|
109
96
|
version: 1.9.0
|
110
|
-
- !ruby/object:Gem::Dependency
|
111
|
-
name: sinatra
|
112
|
-
requirement: !ruby/object:Gem::Requirement
|
113
|
-
none: false
|
114
|
-
requirements:
|
115
|
-
- - ~>
|
116
|
-
- !ruby/object:Gem::Version
|
117
|
-
version: 1.3.1
|
118
|
-
type: :development
|
119
|
-
prerelease: false
|
120
|
-
version_requirements: !ruby/object:Gem::Requirement
|
121
|
-
none: false
|
122
|
-
requirements:
|
123
|
-
- - ~>
|
124
|
-
- !ruby/object:Gem::Version
|
125
|
-
version: 1.3.1
|
126
97
|
description: View a user's last 100 Reddit comments, organized by subreddit.
|
127
98
|
email:
|
128
99
|
- michael@monkey-robot.com
|
@@ -131,7 +102,7 @@ executables:
|
|
131
102
|
extensions: []
|
132
103
|
extra_rdoc_files: []
|
133
104
|
files:
|
134
|
-
- .gitignore
|
105
|
+
- ".gitignore"
|
135
106
|
- Gemfile
|
136
107
|
- LICENSE.txt
|
137
108
|
- README.textile
|
@@ -141,50 +112,50 @@ files:
|
|
141
112
|
- features/fixtures/blank.json
|
142
113
|
- features/fixtures/mipadi.json
|
143
114
|
- features/help.feature
|
144
|
-
- features/server/reddit.rb
|
145
115
|
- features/step_definitions/reddit_steps.rb
|
146
116
|
- features/support/aruba.rb
|
147
117
|
- lib/usaidwat.rb
|
148
118
|
- lib/usaidwat/application.rb
|
149
119
|
- lib/usaidwat/client.rb
|
150
120
|
- lib/usaidwat/formatter.rb
|
121
|
+
- lib/usaidwat/service.rb
|
151
122
|
- lib/usaidwat/version.rb
|
152
123
|
- spec/spec_helper.rb
|
153
124
|
- spec/usaidwat/client_spec.rb
|
154
125
|
- spec/usaidwat/formatter_spec.rb
|
126
|
+
- spec/usaidwat/service_spec.rb
|
155
127
|
- usaidwat.gemspec
|
156
128
|
homepage: https://github.com/mdippery/usaidwat
|
157
129
|
licenses: []
|
130
|
+
metadata: {}
|
158
131
|
post_install_message:
|
159
132
|
rdoc_options: []
|
160
133
|
require_paths:
|
161
134
|
- lib
|
162
135
|
required_ruby_version: !ruby/object:Gem::Requirement
|
163
|
-
none: false
|
164
136
|
requirements:
|
165
|
-
- -
|
137
|
+
- - ">="
|
166
138
|
- !ruby/object:Gem::Version
|
167
139
|
version: '0'
|
168
140
|
required_rubygems_version: !ruby/object:Gem::Requirement
|
169
|
-
none: false
|
170
141
|
requirements:
|
171
|
-
- -
|
142
|
+
- - ">="
|
172
143
|
- !ruby/object:Gem::Version
|
173
144
|
version: '0'
|
174
145
|
requirements: []
|
175
146
|
rubyforge_project:
|
176
|
-
rubygems_version:
|
147
|
+
rubygems_version: 2.2.2
|
177
148
|
signing_key:
|
178
|
-
specification_version:
|
149
|
+
specification_version: 4
|
179
150
|
summary: Answers the age-old question, "Where does a Redditor comment the most?"
|
180
151
|
test_files:
|
181
152
|
- features/browse.feature
|
182
153
|
- features/fixtures/blank.json
|
183
154
|
- features/fixtures/mipadi.json
|
184
155
|
- features/help.feature
|
185
|
-
- features/server/reddit.rb
|
186
156
|
- features/step_definitions/reddit_steps.rb
|
187
157
|
- features/support/aruba.rb
|
188
158
|
- spec/spec_helper.rb
|
189
159
|
- spec/usaidwat/client_spec.rb
|
190
160
|
- spec/usaidwat/formatter_spec.rb
|
161
|
+
- spec/usaidwat/service_spec.rb
|
data/features/server/reddit.rb
DELETED
@@ -1,14 +0,0 @@
|
|
1
|
-
require 'sinatra/base'
|
2
|
-
|
3
|
-
class Reddit < Sinatra::Base
|
4
|
-
get '/user/*/comments.json' do
|
5
|
-
user = params[:splat].first
|
6
|
-
puts user
|
7
|
-
root = File.expand_path('../../', __FILE__)
|
8
|
-
json = File.read(File.join(root, 'fixtures', "#{user}.json"))
|
9
|
-
content_type :json
|
10
|
-
json
|
11
|
-
end
|
12
|
-
|
13
|
-
run! if app_file == $0
|
14
|
-
end
|