-
-
Notifications
You must be signed in to change notification settings - Fork 1.3k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Updated specs a bit. Added #timeline to CLI. Add #source, #truncated,…
… #in_reply_to_status_id, #in_reply_to_user_id, #favorited to Twitter::Status. Added #protected to Twitter::User.
- Loading branch information
1 parent
35dccbe
commit d02d233
Showing
7 changed files
with
143 additions
and
83 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,3 +1,20 @@ | ||
class Tweet < ActiveRecord::Base | ||
belongs_to :account | ||
|
||
def self.create_from_tweet(account, s) | ||
tweet = account.tweets.find_or_initialize_by_twitter_id(s.id) | ||
tweet.body = s.text | ||
tweet.occurred_at = s.created_at | ||
|
||
%w[truncated favorited in_reply_to_status_id in_reply_to_user_id source].each do |m| | ||
tweet.send("#{m}=", s.send(m)) | ||
end | ||
|
||
%w[id followers_count name screen_name location description | ||
profile_image_url url protected].each do |m| | ||
tweet.send("user_#{m}=", s.user.send(m)) | ||
end | ||
tweet.save! | ||
tweet | ||
end | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,38 +1,37 @@ | ||
module Twitter | ||
class User | ||
class User | ||
include EasyClassMaker | ||
|
||
attributes :id, :name, :screen_name, :status, :location, :description, :url, | ||
:profile_image_url, :profile_background_color, :profile_text_color, :profile_link_color, | ||
:profile_sidebar_fill_color, :profile_sidebar_border_color, :friends_count, :followers_count, | ||
:favourites_count, :statuses_count, :utc_offset | ||
:favourites_count, :statuses_count, :utc_offset , :protected | ||
|
||
class << self | ||
# Creates a new user from a piece of xml | ||
def new_from_xml(xml) | ||
User.new do |u| | ||
u.id = (xml).at('id').innerHTML | ||
u.name = (xml).at('name').innerHTML | ||
u.screen_name = (xml).at('screen_name').innerHTML | ||
u.location = (xml).at('location').innerHTML | ||
u.description = (xml).at('description').innerHTML | ||
u.url = (xml).at('url').innerHTML | ||
u.profile_image_url = (xml).at('profile_image_url').innerHTML | ||
|
||
# optional, not always present | ||
u.profile_background_color = (xml).at('profile_background_color').innerHTML if (xml).at('profile_background_color') | ||
u.profile_text_color = (xml).at('profile_text_color').innerHTML if (xml).at('profile_text_color') | ||
u.profile_link_color = (xml).at('profile_link_color').innerHTML if (xml).at('profile_link_color') | ||
u.profile_sidebar_fill_color = (xml).at('profile_sidebar_fill_color').innerHTML if (xml).at('profile_sidebar_fill_color') | ||
u.profile_sidebar_border_color = (xml).at('profile_sidebar_border_color').innerHTML if (xml).at('profile_sidebar_border_color') | ||
u.friends_count = (xml).at('friends_count').innerHTML if (xml).at('friends_count') | ||
u.followers_count = (xml).at('followers_count').innerHTML if (xml).at('followers_count') | ||
u.favourites_count = (xml).at('favourites_count').innerHTML if (xml).at('favourites_count') | ||
u.statuses_count = (xml).at('statuses_count').innerHTML if (xml).at('statuses_count') | ||
u.utc_offset = (xml).at('utc_offset').innerHTML if (xml).at('utc_offset') | ||
u.status = Status.new_from_xml(xml) if (xml).at('status') | ||
end | ||
end | ||
# Creates a new user from a piece of xml | ||
def self.new_from_xml(xml) | ||
u = new | ||
u.id = (xml).at('id').innerHTML | ||
u.name = (xml).at('name').innerHTML | ||
u.screen_name = (xml).at('screen_name').innerHTML | ||
u.location = (xml).at('location').innerHTML | ||
u.description = (xml).at('description').innerHTML | ||
u.url = (xml).at('url').innerHTML | ||
u.profile_image_url = (xml).at('profile_image_url').innerHTML | ||
|
||
# optional, not always present | ||
u.profile_background_color = (xml).at('profile_background_color').innerHTML if (xml).at('profile_background_color') | ||
u.profile_text_color = (xml).at('profile_text_color').innerHTML if (xml).at('profile_text_color') | ||
u.profile_link_color = (xml).at('profile_link_color').innerHTML if (xml).at('profile_link_color') | ||
u.profile_sidebar_fill_color = (xml).at('profile_sidebar_fill_color').innerHTML if (xml).at('profile_sidebar_fill_color') | ||
u.profile_sidebar_border_color = (xml).at('profile_sidebar_border_color').innerHTML if (xml).at('profile_sidebar_border_color') | ||
u.friends_count = (xml).at('friends_count').innerHTML if (xml).at('friends_count') | ||
u.followers_count = (xml).at('followers_count').innerHTML if (xml).at('followers_count') | ||
u.favourites_count = (xml).at('favourites_count').innerHTML if (xml).at('favourites_count') | ||
u.statuses_count = (xml).at('statuses_count').innerHTML if (xml).at('statuses_count') | ||
u.utc_offset = (xml).at('utc_offset').innerHTML if (xml).at('utc_offset') | ||
u.protected = (xml).at('protected').innerHTML == 'false' ? false : true if (xml).at('protected') | ||
u.status = Status.new_from_xml(xml.at('status')) if (xml).at('status') | ||
u | ||
end | ||
end | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,23 +1,40 @@ | ||
require File.dirname(__FILE__) + '/spec_helper.rb' | ||
|
||
describe "Twitter::Status" do | ||
describe Twitter::Status do | ||
it "should create new status from xml doc" do | ||
xml = <<EOF | ||
<status> | ||
<created_at>Sat Mar 31 06:33:21 +0000 2007</created_at> | ||
<id>16440221</id> | ||
<text>Back from underground sushi with b/c/g/j/m. Hope jack and britt get in to ratatat, too!</text> | ||
</status> | ||
<created_at>Sun May 04 21:59:52 +0000 2008</created_at> | ||
<id>803435310</id> | ||
<text>Writing tests (rspec) for the twitter gem that all can run. Wish I would have done this when I wrote it years back.</text> | ||
<source><a href="http://iconfactory.com/software/twitterrific">twitterrific</a></source> | ||
<truncated>false</truncated> | ||
<in_reply_to_status_id></in_reply_to_status_id> | ||
<in_reply_to_user_id></in_reply_to_user_id> | ||
<favorited>false</favorited> | ||
<user> | ||
<id>4243</id> | ||
<name>John Nunemaker</name> | ||
<screen_name>jnunemaker</screen_name> | ||
<location>Indiana</location> | ||
<description>Loves his wife, ruby, notre dame football and iu basketball</description> | ||
<profile_image_url>http://s3.amazonaws.com/twitter_production/profile_images/52619256/ruby_enterprise_shirt_normal.jpg</profile_image_url> | ||
<url>http://addictedtonew.com</url> | ||
<protected>false</protected> | ||
<followers_count>363</followers_count> | ||
</user> | ||
</status> | ||
EOF | ||
s = Twitter::Status.new do |s| | ||
s.created_at = 'Sat Mar 31 06:33:21 +0000 2007' | ||
s.id = '16440221' | ||
s.text = 'Back from underground sushi with b/c/g/j/m. Hope jack and britt get in to ratatat, too!' | ||
end | ||
s2 = Twitter::Status.new_from_xml(Hpricot.XML(xml)) | ||
|
||
s.id.should == s2.id | ||
s.created_at.should == s2.created_at | ||
s.text.should == s2.text | ||
s = Twitter::Status.new_from_xml(Hpricot.XML(xml)) | ||
s.id.should == '803435310' | ||
s.created_at.should == 'Sun May 04 21:59:52 +0000 2008' | ||
s.text.should == 'Writing tests (rspec) for the twitter gem that all can run. Wish I would have done this when I wrote it years back.' | ||
s.source.should == '<a href="http://iconfactory.com/software/twitterrific">twitterrific</a>' | ||
s.truncated.should == false | ||
s.in_reply_to_status_id.should == '' | ||
s.in_reply_to_user_id.should == '' | ||
s.favorited.should == false | ||
s.user.id.should == '4243' | ||
s.user.name.should == 'John Nunemaker' | ||
end | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,36 +1,42 @@ | ||
require File.dirname(__FILE__) + '/spec_helper.rb' | ||
|
||
describe "Twitter::User" do | ||
describe Twitter::User do | ||
it "should create new user from xml doc" do | ||
xml = <<EOF | ||
<user> | ||
<id>18713</id> | ||
<name>Alex Payne</name> | ||
<screen_name>al3x</screen_name> | ||
<location>Arlington, VA</location> | ||
<description>A description</description> | ||
<profile_image_url>http://static.twitter.com/system/user/profile_image/18713/normal/361219175_c11b881657.jpg?1171954960</profile_image_url> | ||
<url>http://www.al3x.net</url> | ||
<id>18713</id> | ||
<name>Alex Payne</name> | ||
<screen_name>al3x</screen_name> | ||
<location>San Francisco, CA</location> | ||
<description>Oh, hi. No, I just work here.</description> | ||
<profile_image_url>http://s3.amazonaws.com/twitter_production/profile_images/51961745/al3x_normal.jpg</profile_image_url> | ||
<url>http://www.al3x.net</url> | ||
<protected>false</protected> | ||
<followers_count>2889</followers_count> | ||
<status> | ||
<created_at>Sun May 04 22:38:39 +0000 2008</created_at> | ||
<id>803453211</id> | ||
<text>@5dots Yes. Give me about 8 hours. *sigh*</text> | ||
<source><a href="http://iconfactory.com/software/twitterrific">twitterrific</a></source> | ||
<truncated>false</truncated> | ||
<in_reply_to_status_id>803450314</in_reply_to_status_id> | ||
<in_reply_to_user_id>618923</in_reply_to_user_id> | ||
<favorited>false</favorited> | ||
</status> | ||
</user> | ||
EOF | ||
u = Twitter::User.new do |u| | ||
u.id = '18713' | ||
u.name = 'Alex Payne' | ||
u.screen_name = 'al3x' | ||
u.location = 'Arlington, VA' | ||
u.description = 'A description' | ||
u.profile_image_url = 'http://static.twitter.com/system/user/profile_image/18713/normal/361219175_c11b881657.jpg?1171954960' | ||
u.url = 'http://www.al3x.net' | ||
end | ||
|
||
u2 = Twitter::User.new_from_xml(Hpricot.XML(xml)) | ||
|
||
u.id.should == u2.id | ||
u.name.should == u2.name | ||
u.screen_name.should == u2.screen_name | ||
u.location.should == u2.location | ||
u.description.should == u2.description | ||
u.profile_image_url.should == u2.profile_image_url | ||
u.url.should == u2.url | ||
u = Twitter::User.new_from_xml(Hpricot.XML(xml)) | ||
u.id.should == '18713' | ||
u.name.should =='Alex Payne' | ||
u.screen_name.should == 'al3x' | ||
u.location.should == 'San Francisco, CA' | ||
u.description.should == 'Oh, hi. No, I just work here.' | ||
u.profile_image_url.should == 'http://s3.amazonaws.com/twitter_production/profile_images/51961745/al3x_normal.jpg' | ||
u.url.should == 'http://www.al3x.net' | ||
u.protected.should == false | ||
u.followers_count.should == '2889' | ||
u.status.text.should == '@5dots Yes. Give me about 8 hours. *sigh*' | ||
end | ||
end |