redcli 0.1.1 → 0.2.1

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 CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: fc34625627f01989b8e5d0368f981bab4dcb6e5d
4
- data.tar.gz: 0da08e9dfa50c7eedb43242d45afe36a972fa583
3
+ metadata.gz: ba8f3497d57378e2dc84be412bb42882f29118be
4
+ data.tar.gz: 1ca176d79ce680e771ebcad072d7586aa4574a8a
5
5
  SHA512:
6
- metadata.gz: 8ee85ccc1d85c12d3d5510bd57f2c0526461c41b8dff70cd8f5a640a46c522ec234f2e15463b80693b56acb4401151708e5a91d90d00476b1b4f75bc4a8774f3
7
- data.tar.gz: a0e5f5647ca87a50a0648a428e7357ba4137235281fffb2dc06608b0d77751221526c4f97cc46b9d98c721b1980cd1c4dacef2b3b13c067b7f60c2ad0d9e2968
6
+ metadata.gz: 36c4b9d33dd4edc8fce3bb8e88070d7ac69a447b76b92575d98086e282415e869964ff45822332a5a20dd556a589cac0f14b47874e929659b6e7903d4b12123e
7
+ data.tar.gz: b0a8771b93804e0f2fb85cc46d602135cd10fdfabb06c247b57abbefb3edf68bd6d1f6b8b471e8745a68f8e9f3c7830bd5fb912714242d44c1bbd9ecc09d69c7
@@ -17,14 +17,30 @@ module Redcli
17
17
  def run
18
18
  @links = get_links
19
19
  if @links
20
- display_links
21
- prompt_action
22
- act_on_input
20
+ links
23
21
  else
24
22
  signal_failure
25
23
  end
26
24
  end
27
25
 
26
+ def links
27
+ display_links
28
+ prompt_links_input
29
+ act_on_input
30
+ end
31
+
32
+ def link(link_index)
33
+ @current_link = @links[link_index]
34
+ display_topic(link_index)
35
+ prompt_link_input
36
+ act_on_input
37
+ end
38
+
39
+ def open_current_link
40
+ url = @current_link["data"]["url"]
41
+ `open #{url}`
42
+ end
43
+
28
44
  private
29
45
 
30
46
  def url
@@ -44,20 +60,38 @@ module Redcli
44
60
  end
45
61
 
46
62
  def display_links
63
+ @stdout.puts "\n"
47
64
  @links.each_with_index do |link, i|
48
65
  title = link.fetch("data", { "title" => "No Title"}).fetch("title")
49
66
  @stdout.puts "#{i+1}) #{title}".send(COLORS[i%2])
50
67
  end
68
+ @stdout.puts "\n"
69
+ end
70
+
71
+ def display_topic(topic_index)
72
+ @stdout.puts "\n\n\n"
73
+ @stdout.puts @links[topic_index].fetch("data", { "selftext" => "No Information Available" }).fetch("selftext")
74
+ @stdout.puts "\n"
75
+ end
76
+
77
+ def prompt_links_input
78
+ @stdout.puts "(1-10) | (q)uit"
51
79
  end
52
80
 
53
- def prompt_action
54
- @stdout.puts "(q)uit"
81
+ def prompt_link_input
82
+ @stdout.puts "(b)ack | (q)uit | (o)pen in browser"
55
83
  end
56
84
 
57
85
  def act_on_input
58
86
  input = @stdin.gets.chomp
59
87
  if input =~ /q/
60
88
  return
89
+ elsif input =~ /[0-9]/
90
+ link(input.to_i - 1)
91
+ elsif input =~ /b/
92
+ links
93
+ elsif input =~ /o/
94
+ open_current_link
61
95
  end
62
96
  end
63
97
 
@@ -1,3 +1,3 @@
1
1
  module Redcli
2
- VERSION = "0.1.1"
2
+ VERSION = "0.2.1"
3
3
  end
@@ -17,10 +17,21 @@ class ApplicationTest < Minitest::Test
17
17
  stdin = StringIO.new("q\n")
18
18
  app = Redcli::Application.new(subreddit: 'test', stdout: stdout, stdin: stdin)
19
19
  app.run
20
- stdout.rewind
21
- assert_match /1\)/, stdout.each_line.first
22
- 9.times { stdout.each_line.next }
23
- assert_match /\(q\)uit/, stdout.each_line.next
20
+ output = stdout.string.split("\n")
21
+ assert_match /1\)/, output[1]
22
+ assert_match /\(q\)uit/, output.last
23
+ end
24
+ end
25
+
26
+ def test_viewing_a_subreddit_topic
27
+ VCR.use_cassette("test") do
28
+ stdout = StringIO.new
29
+ stdin = StringIO.new("1\nq\n")
30
+ app = Redcli::Application.new(subreddit: 'test', stdout: stdout, stdin: stdin)
31
+ app.run
32
+ last_line = stdout.string.split("\n").last
33
+ assert_match /\(b\)ack/, last_line
34
+ assert_match /\(q\)uit/, last_line
24
35
  end
25
36
  end
26
37
 
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: redcli
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.1.1
4
+ version: 0.2.1
5
5
  platform: ruby
6
6
  authors:
7
7
  - Kavinder Dhaliwal