twitterfeed 0.0.2 → 0.1.0

Sign up to get free protection for your applications and to get access to all the features.
data/README.md CHANGED
@@ -1,6 +1,6 @@
1
1
  # Twitterfeed
2
2
 
3
- TODO: Write a gem description
3
+ Gem that will retrieve and display tweets from a predetermined set of twitter handles.
4
4
 
5
5
  ## Installation
6
6
 
@@ -8,17 +8,22 @@ Add this line to your application's Gemfile:
8
8
 
9
9
  gem 'twitterfeed'
10
10
 
11
- And then execute:
12
11
 
13
- $ bundle
12
+ ## Usage
14
13
 
15
- Or install it yourself as:
14
+ Place helper line anywhere in your project with an array of twitter handles:
16
15
 
17
- $ gem install twitterfeed
16
+ <%= twitterfeed(["mark_cap", "wycats", "ruralocity"]) %>
18
17
 
19
- ## Usage
18
+ Enjoy!
19
+
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.
21
+
22
+ ## TODO
20
23
 
21
- TODO: Write usage instructions here
24
+ - Add authentication to boost limit up to 350
25
+ - Read a file with twitter handles to initialize
26
+ - Ability to include searches
22
27
 
23
28
  ## Contributing
24
29
 
@@ -0,0 +1,64 @@
1
+ #twitterfeed {
2
+
3
+ margin: 20px;
4
+ width: 300px;
5
+ float: right;
6
+ font: Helvetica;
7
+ font-size: 13px;
8
+ }
9
+
10
+ #twitterfeed_header {
11
+ font-size: 11px;
12
+ font-weight: bold;
13
+ }
14
+
15
+ #twitterfeed_content {
16
+ height: 300px;
17
+ overflow: scroll;
18
+ overflow-x:hidden;
19
+ border: 1px solid black;
20
+ -webkit-border-radius: 5px;
21
+ -moz-border-radius: 5px;
22
+ }
23
+
24
+ #twitterfeed_tweet {
25
+ border-bottom: 1px solid;
26
+ padding: 10px;
27
+ padding-left: 5px;
28
+ min-height: 50px;
29
+
30
+ }
31
+ .even {
32
+ background-color: white;
33
+ }
34
+
35
+ .odd {
36
+ background-color: #efedee;
37
+ }
38
+
39
+ #twitterfeed_handle {
40
+ margin-bottom: 5px;
41
+ }
42
+
43
+ #twitterfeed_handle a{
44
+ font-weight: bold;
45
+ color: blue;
46
+ }
47
+
48
+ .twitterfeed_time{
49
+ float: right;
50
+ font-size: 10px;
51
+ font-weight: bold;
52
+ color: red;
53
+ }
54
+
55
+ #twitterfeed_pic{
56
+ float: left;
57
+ margin-right: 10px;
58
+ height: 100% !important;
59
+ width: 50px;
60
+ }
61
+
62
+ #twitterfeed_text {
63
+ margin-left: 60px;
64
+ }
@@ -0,0 +1,19 @@
1
+ =stylesheet_link_tag "twitterfeed"
2
+
3
+ #twitterfeed
4
+
5
+ #twitterfeed_header
6
+ TwitterFeed
7
+ #twitterfeed_content
8
+ - tweet_array.each do |tweet|
9
+ #twitterfeed_tweet{:class => cycle('even','odd')}
10
+ #twitterfeed_pic
11
+ = image_tag tweet["pic_url"]
12
+ #twitterfeed_handle
13
+ =link_to tweet["handle"], "http://twitter.com/#{tweet['handle']}", :target => '_new'
14
+
15
+ .twitterfeed_time
16
+ =tweet_time(tweet["created_at"])
17
+ #twitterfeed_text
18
+ = tweet["text"]
19
+
@@ -1,7 +1,7 @@
1
1
  require 'twitterfeed/view_helpers'
2
2
 
3
3
  module Twitterfeed
4
- class Railtie < Rails::Railtie
4
+ class Engine < ::Rails::Engine
5
5
  initializer "application_controller.initialize_twitterfeed" do
6
6
  ActiveSupport.on_load(:action_controller) do
7
7
  include Twitterfeed
@@ -1,3 +1,3 @@
1
1
  module Twitterfeed
2
- VERSION = "0.0.2"
2
+ VERSION = "0.1.0"
3
3
  end
@@ -1,9 +1,39 @@
1
+ require 'twitter'
2
+
1
3
  module Twitterfeed
2
4
  module ViewHelpers
3
- def twitterfeed(user)
4
- Twitter.user_timeline(user).each do |tweet|
5
- content_tag :pre, tweet.text
5
+ def twitterfeed(name_array)
6
+
7
+ twitterfeed_data = YAML.load(File.open("twitterfeed.yml"))
8
+
9
+ #initializing cron type system. This will determine how often data is retrieved from twitter to not go over
10
+ #Twitter API's 150 request per hour limit. The frequency is determined from how many twitter handles are being
11
+ #retrieved. 1 handle will be retrieved maximum of 150 times per hour etc.
12
+
13
+ if twitterfeed_data.first["last_update"] < (Time.now - (60.0 * (60.0/(150.0/name_array.size))))
14
+ Twitterfeed.update_twitterfeed(twitterfeed_data, name_array)
15
+ end
16
+
17
+ twitterfeed_data = YAML.load(File.open("twitterfeed.yml"))
18
+ #removing update time from array
19
+ twitterfeed_data.slice!(0)
20
+ render :partial => "twitterfeed/twitterfeed_box", :locals => { :tweet_array => twitterfeed_data}
21
+
22
+ end
23
+
24
+ def tweet_time(time)
25
+ #displays the time for a tweet i.e. 36m, 12h, May 5
26
+ if time < (Time.now - (3600 * 24))
27
+ time.strftime("%b %-d")
28
+ else
29
+ time_ago = Time.now - time
30
+ if time_ago < 3600
31
+ "#{(time_ago / 60).to_i}m"
32
+ else
33
+ "#{(time_ago / 3600).to_i}h"
34
+ end
6
35
  end
7
36
  end
8
37
  end
9
38
  end
39
+
data/lib/twitterfeed.rb CHANGED
@@ -1,12 +1,22 @@
1
+ require 'twitter'
1
2
 
2
3
  module Twitterfeed
3
4
 
4
- require 'twitterfeed/railtie' if defined?(Rails)
5
-
6
-
7
-
8
- def self.ung(string)
9
- "hello hi #{string}"
10
- end
5
+ require 'twitterfeed/engine' if defined?(Rails)
11
6
 
7
+ def self.update_twitterfeed(twitterfeed_data, name_array)
8
+ total_tweets = []
9
+ name_array.first(150).each do |name|
10
+ Twitter.user_timeline(name, :include_rts => true).each do |tweet|
11
+ total_tweets << tweet
12
+ end
13
+ end
14
+
15
+ tweet_array = [{"last_update" => Time.now}]
16
+ 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}
19
+ end
20
+ File.open('twitterfeed.yml', 'w') {|f| f.write(tweet_array.to_yaml) }
21
+ end
12
22
  end
metadata CHANGED
@@ -5,9 +5,9 @@ version: !ruby/object:Gem::Version
5
5
  prerelease:
6
6
  segments:
7
7
  - 0
8
+ - 1
8
9
  - 0
9
- - 2
10
- version: 0.0.2
10
+ version: 0.1.0
11
11
  platform: ruby
12
12
  authors:
13
13
  - Mark Capodagli
@@ -15,7 +15,7 @@ autorequire:
15
15
  bindir: bin
16
16
  cert_chain: []
17
17
 
18
- date: 2012-05-03 00:00:00 Z
18
+ date: 2012-05-09 00:00:00 Z
19
19
  dependencies:
20
20
  - !ruby/object:Gem::Dependency
21
21
  name: twitter
@@ -48,9 +48,10 @@ files:
48
48
  - LICENSE
49
49
  - README.md
50
50
  - Rakefile
51
+ - app/assets/stylesheets/twitterfeed.css
52
+ - app/views/twitterfeed/_twitterfeed_box.html.haml
51
53
  - lib/twitterfeed.rb
52
- - lib/twitterfeed/_lolz.html.haml
53
- - lib/twitterfeed/railtie.rb
54
+ - lib/twitterfeed/engine.rb
54
55
  - lib/twitterfeed/version.rb
55
56
  - lib/twitterfeed/view_helpers.rb
56
57
  - twitterfeed.gemspec
@@ -1 +0,0 @@
1
- = "hello gents"