twitterfeed 0.1.2 → 0.1.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.
data/README.md CHANGED
@@ -2,40 +2,25 @@
2
2
 
3
3
  Gem that will retrieve and display tweets from a predetermined set of twitter handles.
4
4
 
5
- == Installation
5
+ ## Installation
6
6
 
7
7
  Add this line to your application's Gemfile:
8
8
 
9
9
  gem 'twitterfeed'
10
10
 
11
- === Rails 3.x with asset pipeline enabled:
12
11
 
13
- Just install and you're good to go!
12
+ ## Usage
14
13
 
15
- === Rails without pipeline asset
14
+ Place helper line anywhere in your project with an array of twitter handles or hashtags:
16
15
 
17
- rails g twitterfeed
18
-
19
- == Usage
20
-
21
- Place helper line anywhere in your project with an array of twitter handles:
22
-
23
- <%= twitterfeed(["mark_cap", "wycats", "ruralocity"]) %>
16
+ <%= twitterfeed(["mark_cap", "wycats", "ruralocity", "#ruby", "#rails"]) %>
24
17
 
25
18
  Enjoy!
26
19
 
27
20
  Twitter API only allows 150 requests per hour, so to help with this, the frequency on which twitterfeed will update is based on how many handles are passed. I.E. 1 handle will be able to be updated 150 times an hour or every 24 seconds, 10 handles will update every 4 minutes, etc. Maximum of 150 handles.
28
21
 
29
- == TODO
22
+ ## TODO
30
23
 
31
24
  - Add authentication to boost limit up to 350
32
25
  - Read a file with twitter handles to initialize
33
26
  - Ability to include searches
34
-
35
- == Contributing
36
-
37
- 1. Fork it
38
- 2. Create your feature branch (`git checkout -b my-new-feature`)
39
- 3. Commit your changes (`git commit -am 'Added some feature'`)
40
- 4. Push to the branch (`git push origin my-new-feature`)
41
- 5. Create new Pull Request
@@ -55,6 +55,7 @@
55
55
  #twitterfeed_pic{
56
56
  float: left;
57
57
  margin-right: 10px;
58
+ margin-top: 5px;
58
59
  height: 100% !important;
59
60
  width: 50px;
60
61
  }
@@ -8,12 +8,12 @@
8
8
  - tweet_array.each do |tweet|
9
9
  #twitterfeed_tweet{:class => cycle('even','odd')}
10
10
  #twitterfeed_pic
11
- = image_tag tweet["pic_url"]
11
+ = link_to image_tag(tweet["pic_url"]), "http://twitter.com/#{tweet['handle']}", :target => '_new'
12
12
  #twitterfeed_handle
13
13
  =link_to tweet["handle"], "http://twitter.com/#{tweet['handle']}", :target => '_new'
14
14
 
15
15
  .twitterfeed_time
16
16
  =tweet_time(tweet["created_at"])
17
17
  #twitterfeed_text
18
- = tweet["text"]
18
+ = linkify_tweet(tweet["text"])
19
19
 
data/lib/twitterfeed.rb CHANGED
@@ -7,16 +7,28 @@ module Twitterfeed
7
7
  def self.update_twitterfeed(twitterfeed_data, name_array)
8
8
  total_tweets = []
9
9
  name_array.first(150).each do |name|
10
- Twitter.user_timeline(name, :include_rts => true).each do |tweet|
11
- total_tweets << tweet
10
+ if name[0] == "#"
11
+ Twitter.search(name, :rpp => 20).each do |tweet|
12
+ total_tweets << tweet
13
+ end
14
+ else
15
+ Twitter.user_timeline(name, :include_rts => true).each do |tweet|
16
+ total_tweets << tweet
17
+ end
12
18
  end
13
19
  end
14
20
 
15
21
  tweet_array = [{"last_update" => Time.now}]
16
22
  total_tweets.sort_by {|x| x.created_at}.reverse.first(20).each do |tweet|
17
- tweet_array << {"handle" => tweet.user.screen_name, "text" => tweet.text, "created_at" => tweet.created_at,
18
- "pic_url" => tweet.user.profile_image_url_https}
23
+ tweet_array << {
24
+ #searches and users have different username methods
25
+ "handle" => tweet.user.nil? ? tweet.from_user : tweet.user.screen_name,
26
+ "text" => tweet.text,
27
+ "created_at" => tweet.created_at,
28
+ "pic_url" => tweet.user.nil? ? tweet.profile_image_url_https : tweet.user.profile_image_url_https
29
+ }
19
30
  end
20
31
  File.open('tmp/twitterfeed.yml', 'w') {|f| f.write(tweet_array.to_yaml) }
21
32
  end
33
+
22
34
  end
@@ -1,3 +1,3 @@
1
1
  module Twitterfeed
2
- VERSION = "0.1.2"
2
+ VERSION = "0.1.3"
3
3
  end
@@ -34,6 +34,26 @@ module Twitterfeed
34
34
  end
35
35
  end
36
36
  end
37
+
38
+ def linkify_tweet(tweet)
39
+ @ats = tweet.scan(/@\w+/)
40
+ @tags = tweet.scan(/#\S+/)
41
+ @links = tweet.scan(/http:\/\/\S+/)
42
+
43
+ @ats.each do |a|
44
+ tweet.gsub!(/#{a}/, "<a href='http://twitter.com/#{a[1..(a.length - 1)]}' target='_blank'>#{a}</a>")
45
+ end
46
+
47
+ @tags.each do |t|
48
+ tweet.gsub!(/#{t}/, "<a href='http://twitter.com/search/%23#{t[1..(t.length - 1)]}' target='_blank'>#{t}</a>")
49
+ end
50
+
51
+ @links.each do |l|
52
+ tweet.gsub!(/#{l}/, "<a href='#{l}' target='_blank'>#{l}</a>")
53
+ end
54
+
55
+ tweet.html_safe
56
+ end
37
57
  end
38
58
  end
39
59
 
metadata CHANGED
@@ -2,7 +2,7 @@
2
2
  name: twitterfeed
3
3
  version: !ruby/object:Gem::Version
4
4
  prerelease:
5
- version: 0.1.2
5
+ version: 0.1.3
6
6
  platform: ruby
7
7
  authors:
8
8
  - Mark Capodagli
@@ -10,7 +10,7 @@ autorequire:
10
10
  bindir: bin
11
11
  cert_chain: []
12
12
 
13
- date: 2012-05-28 00:00:00 Z
13
+ date: 2012-06-04 00:00:00 Z
14
14
  dependencies:
15
15
  - !ruby/object:Gem::Dependency
16
16
  name: twitter