redditsherpa 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.
@@ -0,0 +1,7 @@
1
+ ---
2
+ SHA1:
3
+ metadata.gz: 3b943c599a328f19d464436a023f0e82ff535912
4
+ data.tar.gz: 1d16854942f52ec0aee435f71b639a036e11bb44
5
+ SHA512:
6
+ metadata.gz: f13aa1a7fda58a08133dfdda514a66c918e0bcf548e49ed85851ed74174a0675dfa5fc672d34cec86513961872975685fb48f17673b290a2da3666c7d7e7fc75
7
+ data.tar.gz: 9adaf513bfa637e6aa5edc566c86627671d327153d0d09545f242b267f1fcf235322f8610aa8cf980314dbc0e97a414b250f72ef72f71fe9322922950246e836
@@ -0,0 +1,14 @@
1
+ /.bundle/
2
+ /.yardoc
3
+ /Gemfile.lock
4
+ /_yardoc/
5
+ /coverage/
6
+ /doc/
7
+ /pkg/
8
+ /spec/reports/
9
+ /tmp/
10
+ *.bundle
11
+ *.so
12
+ *.o
13
+ *.a
14
+ mkmf.log
data/Gemfile ADDED
@@ -0,0 +1,4 @@
1
+ source 'https://rubygems.org'
2
+
3
+ # Specify your gem's dependencies in redditsherpa.gemspec
4
+ gemspec
@@ -0,0 +1,22 @@
1
+ Copyright (c) 2015 Annie Lydens
2
+
3
+ MIT License
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining
6
+ a copy of this software and associated documentation files (the
7
+ "Software"), to deal in the Software without restriction, including
8
+ without limitation the rights to use, copy, modify, merge, publish,
9
+ distribute, sublicense, and/or sell copies of the Software, and to
10
+ permit persons to whom the Software is furnished to do so, subject to
11
+ the following conditions:
12
+
13
+ The above copyright notice and this permission notice shall be
14
+ included in all copies or substantial portions of the Software.
15
+
16
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
17
+ EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
18
+ MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
19
+ NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
20
+ LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
21
+ OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
22
+ WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
@@ -0,0 +1,23 @@
1
+ # Redditsherpa
2
+
3
+ Read reddit from the command line.
4
+
5
+ ## Installation
6
+
7
+ Currently this tool is command line only. To install, run:
8
+
9
+ $ gem install redditsherpa
10
+
11
+ ## Usage
12
+
13
+ For help, run:
14
+
15
+ $ redditsherpa help
16
+
17
+ ## Contributing
18
+
19
+ 1. Fork it ( https://github.com/[my-github-username]/redditsherpa/fork )
20
+ 2. Create your feature branch (`git checkout -b my-new-feature`)
21
+ 3. Commit your changes (`git commit -am 'Add some feature'`)
22
+ 4. Push to the branch (`git push origin my-new-feature`)
23
+ 5. Create a new Pull Request
@@ -0,0 +1,2 @@
1
+ require "bundler/gem_tasks"
2
+
@@ -0,0 +1,4 @@
1
+ #!/usr/bin/env ruby -wU
2
+ require 'redditsherpa'
3
+
4
+ Redditsherpa::CLI.start( ARGV )
@@ -0,0 +1,6 @@
1
+ require "redditsherpa/version"
2
+ require "redditsherpa/cli"
3
+
4
+ module Redditsherpa
5
+
6
+ end
@@ -0,0 +1,195 @@
1
+ require 'redditsherpa/client'
2
+ require 'launchy'
3
+ require 'rainbow/ext/string'
4
+
5
+ module Redditsherpa
6
+ class CLI
7
+ include Launchy
8
+
9
+ def search(topic)
10
+ response = client.search(topic)
11
+ result = response[:data][:children]
12
+ puts "***********************************"
13
+ puts ("Search Results:").color(:magenta).underline.bright
14
+ result.each_with_index do |hash, i|
15
+ unless i == 0
16
+ puts Rainbow(hash[:data][:title]).bright
17
+ puts (hash[:data][:description])
18
+ puts "_____________________________________________"
19
+ end
20
+ end
21
+ puts ("Search for something else or read a subreddit! Type 'read SUBREDDIT' with a specific subreddit or 'surprise me' for a random subreddit. Or type help for more.").color(:cyan)
22
+ end
23
+
24
+ def read(subreddit)
25
+ puts "reading subreddit..."
26
+ response = client.get_posts(subreddit)
27
+ posts = response[:data][:children]
28
+ i = 1
29
+ @array = []
30
+ posts.take(25).each do |post|
31
+ post = post[:data]
32
+ post_id = post[:id]
33
+ @array << "http://www.reddit.com/r/#{subreddit}/comments/#{post_id}/"
34
+ puts ("#{i}. " + post[:title]).bright
35
+ puts "#{post[:url]}"
36
+ puts "____________________________________________________________"
37
+ puts ("Upvotes: #{post[:ups]}").color(:green) + "|" + Rainbow("Downvotes: #{post[:downs]}").color(:red) + "| Number of Comments #{post[:num_comments]}"
38
+ puts
39
+ i += 1
40
+ end
41
+ puts ("To look at comments for a specific topic in the console, type 'comments TOPICNUMBER'. Ex. 'comments 25'").color(:cyan)
42
+ puts ("To open a link in the browser, type 'open TOPICNUMBER'. Ex. 'open 12'").color(:cyan)
43
+ puts ("Done browsing? Type 'exit' or 'x' to quit redditsherpa").color(:cyan)
44
+ end
45
+
46
+ def comments(topicnumber)
47
+ comments_url = @array[topicnumber.to_i - 1] +".json"
48
+ response2 = Faraday.get comments_url
49
+ json_response2 = JSON.parse(response2.body)
50
+
51
+ thread = json_response2[0]["data"]["children"][0]
52
+ puts
53
+ puts "***************************COMMENTS***************************"
54
+ puts
55
+ puts "______________________________________________________________"
56
+ puts Rainbow("Title: #{thread["data"]["title"]}").magenta.bright
57
+ puts "Author: #{thread["data"]["author"]}"
58
+ puts "Number of Comments: #{thread["data"]["num_comments"]}"
59
+ puts "______________________________________________________________"
60
+
61
+ top_level_comments = json_response2[1]["data"]["children"]
62
+ top_level_comments.each do |comment|
63
+ print_subcomments_recursively(comment)
64
+ end
65
+ puts ("Read another subreddit! Type 'read SUBREDDIT' with a specific subreddit or 'surprise me' for a random subreddit.").color(:cyan)
66
+ end
67
+
68
+ def open_up(topicnumber)
69
+ target_url = @array[topicnumber.to_i - 1]
70
+ puts "Opening #{target_url}..."
71
+ Launchy.open(target_url)
72
+ end
73
+
74
+ private
75
+
76
+ def client
77
+ @client ||= Redditsherpa::Client.new
78
+ end
79
+
80
+ def print_subcomments_recursively(comment, depth=0)
81
+ puts "\t"*depth + Rainbow("Level #{depth}: ").bright + "#{comment["data"]["body"]} -- by #{comment["data"]["author"]}\n\n"
82
+ if comment["data"]["replies"] == "" or !comment["data"].has_key?("replies")
83
+ puts "-------------------------END THREAD-------------------------\n"
84
+ else
85
+ sub_comments = comment["data"]["replies"]["data"]["children"]
86
+ sub_comments.each do |subcomment|
87
+ print_subcomments_recursively(subcomment, depth + 1)
88
+ end
89
+ end
90
+ end
91
+ end
92
+ end
93
+
94
+ #loop
95
+ cli = Redditsherpa::CLI.new
96
+
97
+ puts "Redditsherpa"
98
+ puts "*"*50
99
+ puts "If you ever get lost, type help to see a list of commands."
100
+
101
+ while true
102
+ begin
103
+ input = STDIN.gets.chomp
104
+ if input == 'help'
105
+ puts ("Useful redditsherpa commands").color(:cyan)
106
+ puts ("-" * 20).color(:cyan)
107
+ puts ("search WORD - search reddit for stuff").color(:cyan)
108
+ puts ("read SUBREDDIT - read a specific subreddit").color(:cyan)
109
+ puts ("x or exit - quit redditsherpa").color(:cyan)
110
+ puts ("surprise me - read a randomly selected subreddit").color(:cyan)
111
+ puts "-" * 20
112
+
113
+ elsif input.include?('search')
114
+ topic = input.gsub('search ', '').strip
115
+ cli.search(topic)
116
+
117
+ elsif input.include?('read')
118
+ subreddit = input.gsub('read ', '').strip
119
+ cli.read(subreddit)
120
+
121
+ elsif input.include?('comments')
122
+ topicnumber = input.gsub('comments ', '').strip
123
+ cli.comments(topicnumber)
124
+
125
+ elsif input == 'surprise me'
126
+ subreddits = ["funny", "AdviceAnimals", "todayilearned", "WTF", "leagueoflegends", "aww", "AskReddit", "mildlyinteresting"]
127
+ subreddit = subreddits.sample
128
+ cli.read(subreddit)
129
+
130
+ elsif input.include?('open')
131
+ topicnumber = input.gsub('open ', '').strip
132
+ cli.open_up(topicnumber)
133
+
134
+ elsif input == 'x' || input == 'exit'
135
+ exit
136
+
137
+ else
138
+ puts ("Your command is not recognized. Please type help to see a list of approved commands.").color(:red)
139
+ end
140
+ rescue
141
+ puts "
142
+ ............................................. . . ... . . . . . ....
143
+ ........................................... . ... . . . . . ..
144
+ ..........................................$Z+. .... ?ZZZZZZ, . .... . ..
145
+ ......YOU DONE MESSED UP................ $ZZZZZZZZZ+.ZZZ. .,ZZ?. ..... . .. . .
146
+ ....... . .. .... . . .......... ......ZZ .. .,IZZZZZ . .ZZ. ..... .. . .. .
147
+ .Type help to see a list of accepted ...7Z$ ........=ZZ ....ZZ.................
148
+ ..... commands!!!! . ZZ..... .... ZZ7 .. ZZ7 ................
149
+ ... $Z$ ...........$ZZZZZZ+ ................
150
+ . ...Stop breaking shit. ZZ .............,==.... .... .........
151
+ 7ZZ .................... ................
152
+ . . . . $ZZZZZZZZZZ$ZI:. ..................................
153
+ ... ZZZI$ZZZZ=ZZZZZZZZZZZZZZZZZ~..............................
154
+ ............. +ZZ= :ZZZZZZ,77. .=.. . .. 7ZZZZZ+. . ,IZ7, ................
155
+ ..... . . .:ZZZZZZZZZZ$7=...77...?7$.... .........+ZZZZ$ZZZZZZZ$ ..............
156
+ ..... . . $ZZ. ,ZZZZZ.:777.=77I.I77,.... ............+ZZZ,....$ZZ..............
157
+ ..... .ZZ ?ZZ.. $77777777777....+ ..............,ZZZ....+ZZ.............
158
+ ....... ..+ZZ :ZZ.777=..7777777777..+777+....... ........+ZZ:...ZZ ............
159
+ ......... ZZ.ZZZ .77777777777777777777.....77777.........,ZZ,.=ZZ ............
160
+ ..... . ...ZZZZZ .I777777777777777......7777777.........:ZZIZZ..............
161
+ ........... $ZZZ. . ..777777777777,.......7777777......... $ZZZ,..............
162
+ ..... .. .. ZZI ...:7$7777777777777$77.....777777I..........=ZZ ...............
163
+ ..... . . . ZZ: ..7777777777777777777777?...~777............,ZZ................
164
+ ..... . ?ZZ . ..I7777$.. .........................+Z$................
165
+ .......... . .ZZ ..777I... ... .....................ZZ:................
166
+ .......... . .$ZZ ..777.... ........................$Z$.................
167
+ ..... . .ZZ$ ...777.... .....=: ...............7ZZ .................
168
+ ..... . .. . 7ZZ. ..77.. IZZZZZZZZZZ$ ......... OZ$...................
169
+ ............ .. ~ZZO... .....+ZZZZZZ.,$ZZ ..$ZZ... . ,ZZZ, . .. . ..... ..
170
+ ... ........ ... . $ZZZ.......ZZ .$ZZ ...... . .... =ZZZ? . . .. . ..... ...
171
+ ............ . . .ZZZZZ $Z$...ZZ............,ZZZZZ. . ...... . ......
172
+ .......................:ZZZZZZZZ~. ? ..~$ZZZZZ$~. . . . .
173
+ . . ....................=ZZZ.~ZZZZZZZZZZZZZZZZZ= ZZZZ . .
174
+ ...................... ZZZZZ............... . ZZ+ZZ$. . . .
175
+ ......................ZZ7:ZZ................... .IZI OZZ. . . .... . .........
176
+ ... ....... . . . ZZI =ZZ.... .. . ..... . .+ZZ .ZZ~ . .
177
+ ............ . . ....ZZ .IZI....... . ......... .+ZZ . ZZ . .... ..........
178
+ ....................7ZI .IZI................ .+ZZ . ZZ, .. . ... .
179
+ ... ...............ZZ:..+ZZ............... . +ZZ . ZZ. . . .
180
+ ... ................ZZ+..:ZZ................... .$Z? . ZZ. . .. . ......
181
+ ....................~Z$ . ZZ................. .ZZ: . ZZ .. .
182
+ . . .... .. ... ZZ...ZZ............... ZZ .ZZ7 . .
183
+ ......................ZZ..ZZ:.............. ZZ .$ZZ. .
184
+ ............. . . .=ZZ~IZZ...... ............?ZZ.ZZZ. . . ....... . ......
185
+ ... ....... . . . . ZZZZZ ..... ....... ... ZZZZZ7 . . .. . . ... .
186
+ ............. ... . . .$$Z+.. .... ... .....,ZZZI.. . . . . . .. . ........
187
+ ........................... ZZ ................ZZ:. ... . . .. ...........
188
+ . . . . $ZZ. . . . . 7ZZ . . . .
189
+ ..... ... .. . . . 7ZZZZZZ= .. ..........ZZZZZZ$. . . . .. . . ......
190
+ ............ .. .. . ZZZZ... ZZ... ........ ZZ,...ZZZZ. . . .. ..........
191
+ ..... . . . . .. $ZZ . . ZZ7. . . .=ZZ. .....IZZ. . . . .. . ..... ..
192
+ ............ . . .ZZ.........ZZZ...... ZZO. ZZ. . .. . ... ..
193
+ ... ... .. . .. .ZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZ........................"
194
+ end
195
+ end
@@ -0,0 +1,26 @@
1
+ require 'faraday'
2
+ require 'json'
3
+
4
+ module Redditsherpa
5
+ class Client
6
+ include Faraday
7
+ def initialize
8
+ @conn = Faraday.new(:url => 'http://www.reddit.com/')
9
+ end
10
+
11
+ def search(query)
12
+ params = { 'q' => query }
13
+ response = @conn.get "subreddits/search/.json", params
14
+ JSON.parse(response.body, symbolize_names: true)
15
+ end
16
+
17
+ def get_posts(subreddit)
18
+ response = @conn.get do |req|
19
+ req.url "r/#{subreddit}/.json"
20
+ req.headers['Content-Type'] = 'application/json'
21
+ end
22
+ JSON.parse(response.body, symbolize_names: true)
23
+ end
24
+
25
+ end
26
+ end
@@ -0,0 +1,3 @@
1
+ module Redditsherpa
2
+ VERSION = "0.0.3"
3
+ end
Binary file
@@ -0,0 +1,27 @@
1
+ # coding: utf-8
2
+ lib = File.expand_path('../lib', __FILE__)
3
+ $LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
4
+ require 'redditsherpa/version'
5
+
6
+ Gem::Specification.new do |spec|
7
+ spec.name = "redditsherpa"
8
+ spec.version = Redditsherpa::VERSION
9
+ spec.authors = ["Annie Lydens"]
10
+ spec.email = ["aelydens@gmail.com"]
11
+ spec.summary = %q{Read reddit from the command line.}
12
+ spec.description = %q{Read reddit from the command line.}
13
+ spec.homepage = ""
14
+ spec.license = "MIT"
15
+
16
+ spec.files = `git ls-files -z`.split("\x0")
17
+ spec.executables = spec.files.grep(%r{^bin/}) { |f| File.basename(f) }
18
+ spec.test_files = spec.files.grep(%r{^(test|spec|features)/})
19
+ spec.require_paths = ["lib"]
20
+
21
+ spec.add_dependency 'faraday'
22
+ spec.add_dependency 'launchy'
23
+ spec.add_dependency 'rainbow'
24
+
25
+ spec.add_development_dependency "bundler", "~> 1.7"
26
+ spec.add_development_dependency "rake", "~> 10.0"
27
+ end
metadata ADDED
@@ -0,0 +1,127 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: redditsherpa
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.0.3
5
+ platform: ruby
6
+ authors:
7
+ - Annie Lydens
8
+ autorequire:
9
+ bindir: bin
10
+ cert_chain: []
11
+ date: 2015-04-09 00:00:00.000000000 Z
12
+ dependencies:
13
+ - !ruby/object:Gem::Dependency
14
+ name: faraday
15
+ requirement: !ruby/object:Gem::Requirement
16
+ requirements:
17
+ - - ">="
18
+ - !ruby/object:Gem::Version
19
+ version: '0'
20
+ type: :runtime
21
+ prerelease: false
22
+ version_requirements: !ruby/object:Gem::Requirement
23
+ requirements:
24
+ - - ">="
25
+ - !ruby/object:Gem::Version
26
+ version: '0'
27
+ - !ruby/object:Gem::Dependency
28
+ name: launchy
29
+ requirement: !ruby/object:Gem::Requirement
30
+ requirements:
31
+ - - ">="
32
+ - !ruby/object:Gem::Version
33
+ version: '0'
34
+ type: :runtime
35
+ prerelease: false
36
+ version_requirements: !ruby/object:Gem::Requirement
37
+ requirements:
38
+ - - ">="
39
+ - !ruby/object:Gem::Version
40
+ version: '0'
41
+ - !ruby/object:Gem::Dependency
42
+ name: rainbow
43
+ requirement: !ruby/object:Gem::Requirement
44
+ requirements:
45
+ - - ">="
46
+ - !ruby/object:Gem::Version
47
+ version: '0'
48
+ type: :runtime
49
+ prerelease: false
50
+ version_requirements: !ruby/object:Gem::Requirement
51
+ requirements:
52
+ - - ">="
53
+ - !ruby/object:Gem::Version
54
+ version: '0'
55
+ - !ruby/object:Gem::Dependency
56
+ name: bundler
57
+ requirement: !ruby/object:Gem::Requirement
58
+ requirements:
59
+ - - "~>"
60
+ - !ruby/object:Gem::Version
61
+ version: '1.7'
62
+ type: :development
63
+ prerelease: false
64
+ version_requirements: !ruby/object:Gem::Requirement
65
+ requirements:
66
+ - - "~>"
67
+ - !ruby/object:Gem::Version
68
+ version: '1.7'
69
+ - !ruby/object:Gem::Dependency
70
+ name: rake
71
+ requirement: !ruby/object:Gem::Requirement
72
+ requirements:
73
+ - - "~>"
74
+ - !ruby/object:Gem::Version
75
+ version: '10.0'
76
+ type: :development
77
+ prerelease: false
78
+ version_requirements: !ruby/object:Gem::Requirement
79
+ requirements:
80
+ - - "~>"
81
+ - !ruby/object:Gem::Version
82
+ version: '10.0'
83
+ description: Read reddit from the command line.
84
+ email:
85
+ - aelydens@gmail.com
86
+ executables:
87
+ - redditsherpa
88
+ extensions: []
89
+ extra_rdoc_files: []
90
+ files:
91
+ - ".gitignore"
92
+ - Gemfile
93
+ - LICENSE.txt
94
+ - README.md
95
+ - Rakefile
96
+ - bin/redditsherpa
97
+ - lib/redditsherpa.rb
98
+ - lib/redditsherpa/cli.rb
99
+ - lib/redditsherpa/client.rb
100
+ - lib/redditsherpa/version.rb
101
+ - redditsherpa-0.0.2.gem
102
+ - redditsherpa.gemspec
103
+ homepage: ''
104
+ licenses:
105
+ - MIT
106
+ metadata: {}
107
+ post_install_message:
108
+ rdoc_options: []
109
+ require_paths:
110
+ - lib
111
+ required_ruby_version: !ruby/object:Gem::Requirement
112
+ requirements:
113
+ - - ">="
114
+ - !ruby/object:Gem::Version
115
+ version: '0'
116
+ required_rubygems_version: !ruby/object:Gem::Requirement
117
+ requirements:
118
+ - - ">="
119
+ - !ruby/object:Gem::Version
120
+ version: '0'
121
+ requirements: []
122
+ rubyforge_project:
123
+ rubygems_version: 2.4.5
124
+ signing_key:
125
+ specification_version: 4
126
+ summary: Read reddit from the command line.
127
+ test_files: []