tweetwall 0.0.1 → 0.0.2

Sign up to get free protection for your applications and to get access to all the features.
data/README.md CHANGED
@@ -1,6 +1,7 @@
1
1
  # Tweetwall
2
2
 
3
- TODO: Write a gem description
3
+ This Gem makes it very wasy to add a Tweet Wall of Twitter feeds for a particular Twitter user
4
+ on your web application.
4
5
 
5
6
  ## Installation
6
7
 
@@ -18,7 +19,12 @@ Or install it yourself as:
18
19
 
19
20
  ## Usage
20
21
 
21
- TODO: Write usage instructions here
22
+ The print_tweets method returns an HTML division of Tweets.
23
+ Simply call the print_tweets method like so:
24
+ Tweetwall.print_tweets("oceancucumber")
25
+
26
+ Optionally, you can specify they number of tweets:
27
+ Tweetwall.print_tweets("oceancucumber", 10)
22
28
 
23
29
  ## Contributing
24
30
 
@@ -1,3 +1,3 @@
1
1
  module Tweetwall
2
- VERSION = "0.0.1"
2
+ VERSION = "0.0.2"
3
3
  end
data/lib/tweetwall.rb CHANGED
@@ -3,19 +3,45 @@ require "twitter"
3
3
 
4
4
  module Tweetwall
5
5
  def self.print_tweets(twitter_user, number_of_tweets=5)
6
- tweet_wall_html = ""
7
- twitter_feed = Twitter.user_timeline(twitter_user)[0..number_of_tweets]
8
- twitter_image = Twitter.user(twitter_user).profile_image_url
6
+ tweet_html = String.new
7
+ tweet_wall_html = String.new
8
+ twitter_image = String.new
9
+ twitter_feed = Array.new
9
10
 
10
- tweet_wall_html = tweet_wall_html + '<div id="tweet_wall">'
11
- twitter_feed.each do |tweet|
12
- tweet_wall_html = tweet_wall_html + '<div class="tweet_image">'
13
- tweet_wall_html = tweet_wall_html + '<img src="' + twitter_image + '" alt="" class="tweet_image" /> '
14
- tweet_wall_html = tweet_wall_html + '<span class="tweet_text">' + tweet.text + '</span><br />'
11
+ begin
12
+ # Get the tweets from the feed
13
+ twitter_feed = Twitter.user_timeline(twitter_user)[0..number_of_tweets]
14
+
15
+ # Get the twitter user's profile picture
16
+ twitter_image = Twitter.user(twitter_user).profile_image_url
17
+
18
+ tweet_wall_html = tweet_wall_html + '<div id="tweet_wall">'
19
+ twitter_feed.each do |tweet|
20
+ tweet_html = tweet.text
21
+
22
+ # if there's a hyperlink, make it clickable
23
+ words = tweet_html.split(" ")
24
+ words.each do |word|
25
+ if word.start_with?("http://") or word.start_with?("https://")
26
+ tweet_html = tweet_html.gsub(word, '<a href="' + word + '" target="_blank">' + word + '</a>')
27
+ end
28
+ end
29
+
30
+ tweet_wall_html = tweet_wall_html + '<div class="tweet_line">'
31
+ tweet_wall_html = tweet_wall_html + '<img src="' + twitter_image + '" alt="" class="tweet_image" /> '
32
+ tweet_wall_html = tweet_wall_html + '<span class="tweet_text">' + tweet_html + '</span><br />'
33
+ tweet_wall_html = tweet_wall_html + '</div>'
34
+ end
15
35
  tweet_wall_html = tweet_wall_html + '</div>'
16
- end
17
- tweet_wall_html = tweet_wall_html + '</div>'
18
36
 
19
- tweet_wall_html
37
+ tweet_wall_html
38
+ rescue
39
+ "Unable to fetch tweets."
40
+ ensure
41
+ twitter_feed = nil
42
+ twitter_image = nil
43
+ tweet_wall_html = nil
44
+ tweet_html = nil
45
+ end
20
46
  end
21
47
  end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: tweetwall
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.0.1
4
+ version: 0.0.2
5
5
  prerelease:
6
6
  platform: ruby
7
7
  authors: