Class: Twitter

Inherits:
Object
  • Object
show all
Defined in:
lib/twitter_feed.rb

Defined Under Namespace

Classes: Tweet

Constant Summary collapse

FEED_URL =
"http://api.twitter.com/1/statuses/user_timeline.xml?screen_name="
COUNT_PARAM =
"&count="
SINCEID_PARAM =
"&since_id="
MAXID_PARAM =
"&max_id="
PAGE_PARAM =
"&page="

Instance Method Summary collapse

Instance Method Details

#getContent(url) ⇒ Object



13
14
15
16
# File 'lib/twitter_feed.rb', line 13

def getContent(url) 
  uri = URI.parse(url)
  @contenido=Net::HTTP.get(uri)
end

#getFeed(username, count = 20, sinceId = nil, maxId = nil, page = nil) ⇒ Object



18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
# File 'lib/twitter_feed.rb', line 18

def getFeed(username,count=20,sinceId=nil,maxId=nil,page=nil)
 if count >200
   count=20
 end
 url=FEED_URL+username+COUNT_PARAM+count.to_s()
 if sinceId != nil
  url=url+SINCEID_PARAM+sinceId
 end  
 if maxId != nil
  url=url+MAXID_PARAM+maxId
 end
 
 if page != nil
  url=url+PAGE_PARAM+page.to_s()
 end
 
 getContent(url)
 doc = REXML::Document.new @contenido
 
 @tweets= Array.new
 doc.elements.each("statuses/status") { |element|
   temp=Tweet.new(element.elements["id"].text,element.elements["text"].text,element.elements["retweet_count"].text,element.elements["favorited"].text,element.elements["created_at"].text)
   temp.setUser(element.elements["user"])
   @tweets.push(temp) 
 }
 puts @tweets.size
end

#getTweet(index = 0) ⇒ Object



46
47
48
# File 'lib/twitter_feed.rb', line 46

def getTweet(index=0)
 @tweets[index]
end