twitter_feed 1.0.0 → 1.0.1
Sign up to get free protection for your applications and to get access to all the features.
- data/lib/twitter_feed.rb +34 -6
- data/lib/twitter_feed/tweet.rb +48 -0
- data/lib/twitter_feed/user.rb +48 -0
- metadata +5 -3
data/lib/twitter_feed.rb
CHANGED
@@ -3,6 +3,10 @@ require 'rexml/document'
|
|
3
3
|
|
4
4
|
class Twitter
|
5
5
|
FEED_URL="http://api.twitter.com/1/statuses/user_timeline.xml?screen_name="
|
6
|
+
COUNT_PARAM="&count="
|
7
|
+
SINCEID_PARAM="&since_id="
|
8
|
+
MAXID_PARAM="&max_id="
|
9
|
+
PAGE_PARAM="&page="
|
6
10
|
@contenido
|
7
11
|
@tweets
|
8
12
|
|
@@ -11,15 +15,39 @@ class Twitter
|
|
11
15
|
@contenido=Net::HTTP.get(uri)
|
12
16
|
end
|
13
17
|
|
14
|
-
def getFeed(username)
|
15
|
-
|
18
|
+
def getFeed(username,count=20,sinceId=nil,maxId=nil,page=nil)
|
19
|
+
if count >200
|
20
|
+
count=20
|
21
|
+
end
|
22
|
+
url=FEED_URL+username+COUNT_PARAM+count.to_s()
|
23
|
+
if sinceId != nil
|
24
|
+
url=url+SINCEID_PARAM+sinceId
|
25
|
+
end
|
26
|
+
if maxId != nil
|
27
|
+
url=url+MAXID_PARAM+maxId
|
28
|
+
end
|
29
|
+
|
30
|
+
if page != nil
|
31
|
+
url=url+PAGE_PARAM+page.to_s()
|
32
|
+
end
|
33
|
+
|
34
|
+
getContent(url)
|
16
35
|
doc = REXML::Document.new @contenido
|
36
|
+
|
17
37
|
@tweets= Array.new
|
18
|
-
doc.elements.each("statuses/status
|
19
|
-
|
20
|
-
|
38
|
+
doc.elements.each("statuses/status") { |element|
|
39
|
+
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)
|
40
|
+
temp.setUser(element.elements["user"])
|
41
|
+
@tweets.push(temp)
|
21
42
|
}
|
22
|
-
|
43
|
+
puts @tweets.size
|
44
|
+
end
|
45
|
+
|
46
|
+
def getTweet(index=0)
|
47
|
+
@tweets[index]
|
23
48
|
end
|
24
49
|
|
25
50
|
end
|
51
|
+
|
52
|
+
require 'twitter_feed/tweet'
|
53
|
+
require 'twitter_feed/user'
|
@@ -0,0 +1,48 @@
|
|
1
|
+
class Twitter::Tweet
|
2
|
+
@id
|
3
|
+
@text
|
4
|
+
@retweetCount
|
5
|
+
@favorited
|
6
|
+
@user
|
7
|
+
@created
|
8
|
+
|
9
|
+
def initialize(id,text,rtc,fv,date)
|
10
|
+
@id=id
|
11
|
+
@text=text
|
12
|
+
@retweetCount=rtc
|
13
|
+
@favorited=fv
|
14
|
+
@created=date
|
15
|
+
@user=nil
|
16
|
+
end
|
17
|
+
|
18
|
+
def getId
|
19
|
+
@id
|
20
|
+
end
|
21
|
+
|
22
|
+
def getText
|
23
|
+
@text
|
24
|
+
end
|
25
|
+
|
26
|
+
def getRTCount
|
27
|
+
@retweetCount
|
28
|
+
end
|
29
|
+
|
30
|
+
def isFavorited
|
31
|
+
@favorited
|
32
|
+
end
|
33
|
+
|
34
|
+
def getUser
|
35
|
+
@user
|
36
|
+
end
|
37
|
+
|
38
|
+
def setUser (user)
|
39
|
+
temp=User.new(user.elements["id"].text,user.elements["name"].text,user.elements["screen_name"].text,user.elements["profile_image_url"].text,user.elements["url"].text,user.elements["description"].text,user.elements["protected"].text,user.elements["followers_count"].text)
|
40
|
+
@user=temp
|
41
|
+
end
|
42
|
+
|
43
|
+
def getCreated
|
44
|
+
@created
|
45
|
+
end
|
46
|
+
|
47
|
+
|
48
|
+
end
|
@@ -0,0 +1,48 @@
|
|
1
|
+
class Twitter::Tweet::User
|
2
|
+
@id
|
3
|
+
@name
|
4
|
+
@screenName
|
5
|
+
@profileImgURL
|
6
|
+
@url
|
7
|
+
@description
|
8
|
+
@protected
|
9
|
+
@followersCount
|
10
|
+
|
11
|
+
def initialize(id,name,sName,imgUrl,url='',desc='',prtd='',fwc='')
|
12
|
+
@id=id
|
13
|
+
@name=name
|
14
|
+
@screenName=sName
|
15
|
+
@profileImgURL=imgUrl
|
16
|
+
@url=url
|
17
|
+
@description=desc
|
18
|
+
@protected=prtd
|
19
|
+
@followersCount=fwc
|
20
|
+
end
|
21
|
+
|
22
|
+
|
23
|
+
def getId
|
24
|
+
@id
|
25
|
+
end
|
26
|
+
def getName
|
27
|
+
@name
|
28
|
+
end
|
29
|
+
def getScreenName
|
30
|
+
@screenName
|
31
|
+
end
|
32
|
+
def getProfileImgUrl
|
33
|
+
@profileImgUrl
|
34
|
+
end
|
35
|
+
def getUrl
|
36
|
+
@url
|
37
|
+
end
|
38
|
+
def getDesc
|
39
|
+
@description
|
40
|
+
end
|
41
|
+
def isProtected
|
42
|
+
@protected
|
43
|
+
end
|
44
|
+
def getFollowersCount
|
45
|
+
@followersCount
|
46
|
+
end
|
47
|
+
|
48
|
+
end
|
metadata
CHANGED
@@ -1,13 +1,13 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: twitter_feed
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
hash:
|
4
|
+
hash: 21
|
5
5
|
prerelease:
|
6
6
|
segments:
|
7
7
|
- 1
|
8
8
|
- 0
|
9
|
-
-
|
10
|
-
version: 1.0.
|
9
|
+
- 1
|
10
|
+
version: 1.0.1
|
11
11
|
platform: ruby
|
12
12
|
authors:
|
13
13
|
- Oscar Garcia
|
@@ -28,6 +28,8 @@ extra_rdoc_files: []
|
|
28
28
|
|
29
29
|
files:
|
30
30
|
- lib/twitter_feed.rb
|
31
|
+
- lib/twitter_feed/tweet.rb
|
32
|
+
- lib/twitter_feed/user.rb
|
31
33
|
homepage: http://elclubdelprogramador.com
|
32
34
|
licenses: []
|
33
35
|
|