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 +4 -4
- data/lib/redcli/application.rb +39 -5
- data/lib/redcli/version.rb +1 -1
- data/test/redcli/application_test.rb +15 -4
- metadata +1 -1
    
        checksums.yaml
    CHANGED
    
    | @@ -1,7 +1,7 @@ | |
| 1 1 | 
             
            ---
         | 
| 2 2 | 
             
            SHA1:
         | 
| 3 | 
            -
              metadata.gz:  | 
| 4 | 
            -
              data.tar.gz:  | 
| 3 | 
            +
              metadata.gz: ba8f3497d57378e2dc84be412bb42882f29118be
         | 
| 4 | 
            +
              data.tar.gz: 1ca176d79ce680e771ebcad072d7586aa4574a8a
         | 
| 5 5 | 
             
            SHA512:
         | 
| 6 | 
            -
              metadata.gz:  | 
| 7 | 
            -
              data.tar.gz:  | 
| 6 | 
            +
              metadata.gz: 36c4b9d33dd4edc8fce3bb8e88070d7ac69a447b76b92575d98086e282415e869964ff45822332a5a20dd556a589cac0f14b47874e929659b6e7903d4b12123e
         | 
| 7 | 
            +
              data.tar.gz: b0a8771b93804e0f2fb85cc46d602135cd10fdfabb06c247b57abbefb3edf68bd6d1f6b8b471e8745a68f8e9f3c7830bd5fb912714242d44c1bbd9ecc09d69c7
         | 
    
        data/lib/redcli/application.rb
    CHANGED
    
    | @@ -17,14 +17,30 @@ module Redcli | |
| 17 17 | 
             
                def run
         | 
| 18 18 | 
             
                  @links = get_links
         | 
| 19 19 | 
             
                  if @links
         | 
| 20 | 
            -
                     | 
| 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  | 
| 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 |  | 
    
        data/lib/redcli/version.rb
    CHANGED
    
    
| @@ -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. | 
| 21 | 
            -
                  assert_match /1\)/,  | 
| 22 | 
            -
                   | 
| 23 | 
            -
             | 
| 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 |  |