stars 0.4.0 → 0.5.0
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.
- data/Gemfile +2 -0
 - data/Gemfile.lock +26 -0
 - data/README.markdown +48 -62
 - data/Rakefile +130 -35
 - data/bin/stars +1 -3
 - data/lib/stars/client.rb +79 -62
 - data/lib/stars/config.rb +41 -0
 - data/lib/stars/core_ext/string.rb +6 -0
 - data/lib/stars/post.rb +57 -0
 - data/lib/stars/services/convore.rb +40 -0
 - data/lib/stars/services/favstar.rb +79 -0
 - data/lib/stars/services/service.rb +32 -0
 - data/lib/stars.rb +37 -6
 - data/stars.gemspec +85 -65
 - data/test/examples/stars.yml +1 -0
 - data/test/helper.rb +10 -27
 - data/test/test_client.rb +18 -35
 - data/test/test_config.rb +29 -0
 - data/test/test_favstar.rb +19 -7
 - data/test/test_post.rb +30 -0
 - metadata +57 -22
 - data/.document +0 -5
 - data/.gitignore +0 -21
 - data/VERSION +0 -1
 - data/lib/stars/favstar.rb +0 -33
 - data/lib/stars/formatter.rb +0 -70
 - data/test/test_formatter.rb +0 -66
 - data/test/test_stars.rb +0 -9
 
    
        data/.gitignore
    DELETED
    
    
    
        data/VERSION
    DELETED
    
    | 
         @@ -1 +0,0 @@ 
     | 
|
| 
       1 
     | 
    
         
            -
            0.4.0
         
     | 
    
        data/lib/stars/favstar.rb
    DELETED
    
    | 
         @@ -1,33 +0,0 @@ 
     | 
|
| 
       1 
     | 
    
         
            -
            # encoding: utf-8
         
     | 
| 
       2 
     | 
    
         
            -
             
     | 
| 
       3 
     | 
    
         
            -
            require 'nokogiri'
         
     | 
| 
       4 
     | 
    
         
            -
            module Stars
         
     | 
| 
       5 
     | 
    
         
            -
              class Favstar
         
     | 
| 
       6 
     | 
    
         
            -
                include HTTParty
         
     | 
| 
       7 
     | 
    
         
            -
                base_uri 'favstar.fm'
         
     | 
| 
       8 
     | 
    
         
            -
                proxy_url = URI.parse(ENV['http_proxy']) if ENV['http_proxy']
         
     | 
| 
       9 
     | 
    
         
            -
                http_proxy proxy_url.host,proxy_url.port if proxy_url
         
     | 
| 
       10 
     | 
    
         
            -
             
     | 
| 
       11 
     | 
    
         
            -
                def recent(username)
         
     | 
| 
       12 
     | 
    
         
            -
                  self.class.get("/users/#{username}/rss",
         
     | 
| 
       13 
     | 
    
         
            -
                                  :format => :xml)['rss']['channel']['item']
         
     | 
| 
       14 
     | 
    
         
            -
                end
         
     | 
| 
       15 
     | 
    
         
            -
                
         
     | 
| 
       16 
     | 
    
         
            -
                def show(url)
         
     | 
| 
       17 
     | 
    
         
            -
                  # hardcode 17 to strip favstar domain for now
         
     | 
| 
       18 
     | 
    
         
            -
                  html = self.class.get(url[17..200], :format => :html)
         
     | 
| 
       19 
     | 
    
         
            -
             
     | 
| 
       20 
     | 
    
         
            -
                  output = ''
         
     | 
| 
       21 
     | 
    
         
            -
             
     | 
| 
       22 
     | 
    
         
            -
                  Nokogiri::HTML(html).css('div[id^="faved_by_others"] img').collect do |img|
         
     | 
| 
       23 
     | 
    
         
            -
                    output << "    ★   #{img.attributes['alt'].value}\n"
         
     | 
| 
       24 
     | 
    
         
            -
                  end
         
     | 
| 
       25 
     | 
    
         
            -
             
     | 
| 
       26 
     | 
    
         
            -
                  Nokogiri::HTML(html).css('div[id^="rt_by_others"] img').collect do |img|
         
     | 
| 
       27 
     | 
    
         
            -
                    output << "    RT  #{img.attributes['alt'].value}\n"
         
     | 
| 
       28 
     | 
    
         
            -
                  end
         
     | 
| 
       29 
     | 
    
         
            -
             
     | 
| 
       30 
     | 
    
         
            -
                  output
         
     | 
| 
       31 
     | 
    
         
            -
                end
         
     | 
| 
       32 
     | 
    
         
            -
              end
         
     | 
| 
       33 
     | 
    
         
            -
            end
         
     | 
    
        data/lib/stars/formatter.rb
    DELETED
    
    | 
         @@ -1,70 +0,0 @@ 
     | 
|
| 
       1 
     | 
    
         
            -
            require 'terminal-table/import'
         
     | 
| 
       2 
     | 
    
         
            -
             
     | 
| 
       3 
     | 
    
         
            -
            module Stars
         
     | 
| 
       4 
     | 
    
         
            -
              class Formatter
         
     | 
| 
       5 
     | 
    
         
            -
                
         
     | 
| 
       6 
     | 
    
         
            -
                attr_accessor :tweets
         
     | 
| 
       7 
     | 
    
         
            -
             
     | 
| 
       8 
     | 
    
         
            -
                def initialize(tweets)
         
     | 
| 
       9 
     | 
    
         
            -
                  @tweets = tweets
         
     | 
| 
       10 
     | 
    
         
            -
                end
         
     | 
| 
       11 
     | 
    
         
            -
              
         
     | 
| 
       12 
     | 
    
         
            -
                # I hate clients that don't retain line breaks, but in this case I'm boss.
         
     | 
| 
       13 
     | 
    
         
            -
                def trim(text)
         
     | 
| 
       14 
     | 
    
         
            -
                  truncated = text.gsub("\n"," ")[0..50]
         
     | 
| 
       15 
     | 
    
         
            -
                  truncated + (truncated.size == text.size ? '' : '...')
         
     | 
| 
       16 
     | 
    
         
            -
                end
         
     | 
| 
       17 
     | 
    
         
            -
              
         
     | 
| 
       18 
     | 
    
         
            -
                def format(i, tweet)
         
     | 
| 
       19 
     | 
    
         
            -
                  stars,text = split_stars(tweet['title'])
         
     | 
| 
       20 
     | 
    
         
            -
                  [i,stars,relative_time(tweet['pubDate']),text]
         
     | 
| 
       21 
     | 
    
         
            -
                end
         
     | 
| 
       22 
     | 
    
         
            -
              
         
     | 
| 
       23 
     | 
    
         
            -
                def split_stars(text)
         
     | 
| 
       24 
     | 
    
         
            -
                  stars = text.match(/[\d+]./)[0].to_i
         
     | 
| 
       25 
     | 
    
         
            -
                  strip_point = text.index(':') + 2
         
     | 
| 
       26 
     | 
    
         
            -
                  text  = text[strip_point..text.size] 
         
     | 
| 
       27 
     | 
    
         
            -
                  [characterize(stars),trim(text)]
         
     | 
| 
       28 
     | 
    
         
            -
                end
         
     | 
| 
       29 
     | 
    
         
            -
              
         
     | 
| 
       30 
     | 
    
         
            -
                def characterize(number)
         
     | 
| 
       31 
     | 
    
         
            -
                  if number > 5
         
     | 
| 
       32 
     | 
    
         
            -
                    "* x #{number}"
         
     | 
| 
       33 
     | 
    
         
            -
                  else
         
     | 
| 
       34 
     | 
    
         
            -
                    (1..number).collect{'*'}.join(' ')
         
     | 
| 
       35 
     | 
    
         
            -
                  end
         
     | 
| 
       36 
     | 
    
         
            -
                end
         
     | 
| 
       37 
     | 
    
         
            -
              
         
     | 
| 
       38 
     | 
    
         
            -
                def line_break
         
     | 
| 
       39 
     | 
    
         
            -
                  "\n"
         
     | 
| 
       40 
     | 
    
         
            -
                end
         
     | 
| 
       41 
     | 
    
         
            -
              
         
     | 
| 
       42 
     | 
    
         
            -
                def to_s
         
     | 
| 
       43 
     | 
    
         
            -
                  tweets = @tweets.collect_with_index{|tweet,i| format(i+1,tweet)}
         
     | 
| 
       44 
     | 
    
         
            -
                  table(['#','Stars','Time','Your Funnies'], *tweets).render
         
     | 
| 
       45 
     | 
    
         
            -
                end
         
     | 
| 
       46 
     | 
    
         
            -
              
         
     | 
| 
       47 
     | 
    
         
            -
                def relative_time(time)
         
     | 
| 
       48 
     | 
    
         
            -
                  post_date = Time.parse(time)
         
     | 
| 
       49 
     | 
    
         
            -
                  timespan = Time.now - Time.parse(time)
         
     | 
| 
       50 
     | 
    
         
            -
             
     | 
| 
       51 
     | 
    
         
            -
                  case timespan
         
     | 
| 
       52 
     | 
    
         
            -
                  when 0..59
         
     | 
| 
       53 
     | 
    
         
            -
                    "just now"
         
     | 
| 
       54 
     | 
    
         
            -
                  when 60..(3600-1)
         
     | 
| 
       55 
     | 
    
         
            -
                    "#{pluralize((timespan/60).to_i, 'minute', 'minutes')} ago"
         
     | 
| 
       56 
     | 
    
         
            -
                  when 3600..(3600*24-1)
         
     | 
| 
       57 
     | 
    
         
            -
                    "#{pluralize((timespan/3600).to_i, 'hour', 'hours')} ago"
         
     | 
| 
       58 
     | 
    
         
            -
                  when (3600*24)..(3600*24*30)
         
     | 
| 
       59 
     | 
    
         
            -
                    "#{pluralize((timespan/(3600*24)).to_i, 'day', 'days')} ago"
         
     | 
| 
       60 
     | 
    
         
            -
                  else
         
     | 
| 
       61 
     | 
    
         
            -
                    post_date.strftime("%m/%d/%Y")
         
     | 
| 
       62 
     | 
    
         
            -
                  end
         
     | 
| 
       63 
     | 
    
         
            -
                end
         
     | 
| 
       64 
     | 
    
         
            -
              
         
     | 
| 
       65 
     | 
    
         
            -
                # ActiveSupport pluralize
         
     | 
| 
       66 
     | 
    
         
            -
                def pluralize(count, singular, plural = nil)
         
     | 
| 
       67 
     | 
    
         
            -
                  "#{count || 0} " + ((count == 1 || count == '1') ? singular : (plural || singular.pluralize))
         
     | 
| 
       68 
     | 
    
         
            -
                end
         
     | 
| 
       69 
     | 
    
         
            -
              end
         
     | 
| 
       70 
     | 
    
         
            -
            end
         
     | 
    
        data/test/test_formatter.rb
    DELETED
    
    | 
         @@ -1,66 +0,0 @@ 
     | 
|
| 
       1 
     | 
    
         
            -
            require 'helper'
         
     | 
| 
       2 
     | 
    
         
            -
             
     | 
| 
       3 
     | 
    
         
            -
            class TestFormatter < Test::Unit::TestCase
         
     | 
| 
       4 
     | 
    
         
            -
             
     | 
| 
       5 
     | 
    
         
            -
              def setup
         
     | 
| 
       6 
     | 
    
         
            -
                @formatter = Stars::Formatter.new(favstar_tweet_hash)
         
     | 
| 
       7 
     | 
    
         
            -
              end
         
     | 
| 
       8 
     | 
    
         
            -
             
     | 
| 
       9 
     | 
    
         
            -
              def test_trim_breaks
         
     | 
| 
       10 
     | 
    
         
            -
                tweet = "Line breaks\nare for lovers"
         
     | 
| 
       11 
     | 
    
         
            -
                assert_equal @formatter.trim(tweet), 'Line breaks are for lovers'
         
     | 
| 
       12 
     | 
    
         
            -
              end
         
     | 
| 
       13 
     | 
    
         
            -
              
         
     | 
| 
       14 
     | 
    
         
            -
              def test_trim_length
         
     | 
| 
       15 
     | 
    
         
            -
                tweet = "This is a tweet that is long enough to certainly "+
         
     | 
| 
       16 
     | 
    
         
            -
                        "need at least SOME truncating lol lol sigh."
         
     | 
| 
       17 
     | 
    
         
            -
                assert_equal @formatter.trim(tweet), 
         
     | 
| 
       18 
     | 
    
         
            -
                             'This is a tweet that is long enough to certainly ne...'
         
     | 
| 
       19 
     | 
    
         
            -
              end
         
     | 
| 
       20 
     | 
    
         
            -
              
         
     | 
| 
       21 
     | 
    
         
            -
              def test_format
         
     | 
| 
       22 
     | 
    
         
            -
                format = @formatter.format(1,favstar_tweet_hash[0])
         
     | 
| 
       23 
     | 
    
         
            -
                assert_equal format.size, 4
         
     | 
| 
       24 
     | 
    
         
            -
                assert_equal 1,format[0], '* *'
         
     | 
| 
       25 
     | 
    
         
            -
              end
         
     | 
| 
       26 
     | 
    
         
            -
             
     | 
| 
       27 
     | 
    
         
            -
              def test_split_stars
         
     | 
| 
       28 
     | 
    
         
            -
                tweet = "12 stars: A short tweet. Hey, a number: 5."
         
     | 
| 
       29 
     | 
    
         
            -
                assert_equal @formatter.split_stars(tweet),
         
     | 
| 
       30 
     | 
    
         
            -
                             ['* x 12', 'A short tweet. Hey, a number: 5.']
         
     | 
| 
       31 
     | 
    
         
            -
              end
         
     | 
| 
       32 
     | 
    
         
            -
              
         
     | 
| 
       33 
     | 
    
         
            -
              def test_characterize_with_lots_of_stars
         
     | 
| 
       34 
     | 
    
         
            -
                assert_equal @formatter.characterize(12),
         
     | 
| 
       35 
     | 
    
         
            -
                             '* x 12'
         
     | 
| 
       36 
     | 
    
         
            -
              end
         
     | 
| 
       37 
     | 
    
         
            -
              
         
     | 
| 
       38 
     | 
    
         
            -
              def test_characterize_with_a_few_stars
         
     | 
| 
       39 
     | 
    
         
            -
                assert_equal @formatter.characterize(4),
         
     | 
| 
       40 
     | 
    
         
            -
                             '* * * *'
         
     | 
| 
       41 
     | 
    
         
            -
              end
         
     | 
| 
       42 
     | 
    
         
            -
              
         
     | 
| 
       43 
     | 
    
         
            -
              def test_line_break
         
     | 
| 
       44 
     | 
    
         
            -
                assert_equal @formatter.line_break, "\n"
         
     | 
| 
       45 
     | 
    
         
            -
              end
         
     | 
| 
       46 
     | 
    
         
            -
              
         
     | 
| 
       47 
     | 
    
         
            -
              def test_to_s
         
     | 
| 
       48 
     | 
    
         
            -
                # just make sure it doesn't blow up for now
         
     | 
| 
       49 
     | 
    
         
            -
                @formatter.to_s
         
     | 
| 
       50 
     | 
    
         
            -
              end
         
     | 
| 
       51 
     | 
    
         
            -
              
         
     | 
| 
       52 
     | 
    
         
            -
              def test_relative_time
         
     | 
| 
       53 
     | 
    
         
            -
                assert_equal @formatter.relative_time((Time.now - 2).to_s),
         
     | 
| 
       54 
     | 
    
         
            -
                             "just now"
         
     | 
| 
       55 
     | 
    
         
            -
                assert_equal @formatter.relative_time((Time.now - 360).to_s),
         
     | 
| 
       56 
     | 
    
         
            -
                             "6 minutes ago"
         
     | 
| 
       57 
     | 
    
         
            -
                assert_equal @formatter.relative_time((Time.now - 10000).to_s),
         
     | 
| 
       58 
     | 
    
         
            -
                             "2 hours ago"
         
     | 
| 
       59 
     | 
    
         
            -
              end
         
     | 
| 
       60 
     | 
    
         
            -
              
         
     | 
| 
       61 
     | 
    
         
            -
              def test_pluralizer
         
     | 
| 
       62 
     | 
    
         
            -
                assert_equal @formatter.pluralize(1, 'day', 'day'), '1 day'
         
     | 
| 
       63 
     | 
    
         
            -
                assert_equal @formatter.pluralize(2, 'day', 'days'), '2 days'
         
     | 
| 
       64 
     | 
    
         
            -
              end
         
     | 
| 
       65 
     | 
    
         
            -
             
     | 
| 
       66 
     | 
    
         
            -
            end
         
     |