Permalink
Browse files

Add Twitter::Status#full_text method

  • Loading branch information...
1 parent 5991fa3 commit a03eb945df6a58f92cc832f5ffc1c8973c57339e @sferik committed May 9, 2012
Showing with 27 additions and 5 deletions.
  1. +6 −0 lib/twitter/status.rb
  2. +1 −0 spec/fixtures/retweeted_status.json
  3. +20 −5 spec/twitter/status_spec.rb
@@ -43,6 +43,12 @@ def from_user
@attrs['from_user'] || self.user && self.user.screen_name
end
+ # @return [String]
+ # @note May be > 140 characters.
+ def full_text
+ self.retweeted_status ? "RT @#{self.retweeted_status.user.screen_name}: #{self.retweeted_status.text}" : self.text
+ end
+
# @return [Twitter::Point, Twitter::Polygon]
def geo
@geo ||= Twitter::GeoFactory.new(@attrs['geo']) unless @attrs['geo'].nil?
@@ -0,0 +1 @@
+{"in_reply_to_user_id_str":null,"in_reply_to_status_id":null,"coordinates":null,"in_reply_to_screen_name":null,"in_reply_to_user_id":null,"truncated":true,"id_str":"200155886403067904","contributors":null,"retweeted_status":{"in_reply_to_user_id_str":null,"in_reply_to_status_id":null,"coordinates":null,"in_reply_to_screen_name":null,"in_reply_to_user_id":null,"truncated":false,"id_str":"199986035554394112","contributors":null,"user":{"is_translator":false,"id":48156007,"profile_link_color":"2FC2EF","time_zone":"Brasilia","profile_image_url_https":"https:\/\/si0.twimg.com\/profile_images\/1891390827\/logo-plataformatec-icone-com-alpha_normal.png","profile_background_image_url_https":"https:\/\/si0.twimg.com\/images\/themes\/theme9\/bg.gif","friends_count":18,"id_str":"48156007","default_profile_image":false,"profile_use_background_image":false,"following":false,"favourites_count":6,"utc_offset":-10800,"profile_text_color":"666666","notifications":false,"name":"Plataformatec","profile_sidebar_border_color":"181A1E","screen_name":"plataformatec","url":"http:\/\/plataformatec.com.br","protected":false,"created_at":"Wed Jun 17 23:11:25 +0000 2009","statuses_count":244,"profile_background_tile":false,"default_profile":false,"profile_sidebar_fill_color":"252429","description":"We build tailored web and mobile applications for our customers.","contributors_enabled":false,"geo_enabled":false,"profile_image_url":"http:\/\/a0.twimg.com\/profile_images\/1891390827\/logo-plataformatec-icone-com-alpha_normal.png","location":"S\u00e3o Paulo, Brazil","followers_count":1230,"show_all_inline_media":false,"lang":"en","follow_request_sent":false,"profile_background_color":"1A1B1F","verified":false,"listed_count":81,"profile_background_image_url":"http:\/\/a0.twimg.com\/images\/themes\/theme9\/bg.gif"},"retweeted":false,"retweet_count":4,"source":"web","created_at":"Tue May 08 22:16:01 +0000 2012","in_reply_to_status_id_str":null,"place":null,"id":199986035554394112,"geo":null,"favorited":false,"text":"RSpec Formatter, Oracle and AR, RSpec Matchers, Solr Facets, Modular JS apps, JS Deferred: topics so far in today's Lightning Talks"},"user":{"is_translator":false,"id":10230812,"profile_link_color":"0084B4","time_zone":"Rome","profile_image_url_https":"https:\/\/si0.twimg.com\/profile_images\/2156708631\/Cropped_normal.png","profile_background_image_url_https":"https:\/\/si0.twimg.com\/images\/themes\/theme15\/bg.png","friends_count":218,"id_str":"10230812","default_profile_image":false,"profile_use_background_image":true,"following":true,"favourites_count":55,"utc_offset":3600,"profile_text_color":"333333","notifications":false,"name":"Jos\u00e9 Valim","profile_sidebar_border_color":"a8c7f7","screen_name":"josevalim","url":"http:\/\/plataformatec.com\/","protected":false,"created_at":"Tue Nov 13 23:23:25 +0000 2007","statuses_count":8133,"profile_background_tile":false,"default_profile":false,"profile_sidebar_fill_color":"C0DFEC","description":"@plataformatec founder, Open Source developer, Rails Core Team Member, Ruby Hero and creator of Elixir, code available at github.com\/josevalim","contributors_enabled":false,"geo_enabled":false,"profile_image_url":"http:\/\/a0.twimg.com\/profile_images\/2156708631\/Cropped_normal.png","location":"Krak\u00f3w, Poland","followers_count":6719,"show_all_inline_media":true,"lang":"en","follow_request_sent":false,"profile_background_color":"022330","verified":false,"listed_count":546,"profile_background_image_url":"http:\/\/a0.twimg.com\/images\/themes\/theme15\/bg.png"},"retweeted":false,"retweet_count":4,"source":"\u003Ca href=\"http:\/\/twitter.com\/#!\/download\/iphone\" rel=\"nofollow\"\u003ETwitter for iPhone\u003C\/a\u003E","created_at":"Wed May 09 09:30:56 +0000 2012","in_reply_to_status_id_str":null,"place":null,"id":200155886403067904,"geo":null,"favorited":false,"text":"RT @plataformatec: RSpec Formatter, Oracle and AR, RSpec Matchers, Solr Facets, Modular JS apps, JS Deferred: topics so far in today's L ..."}
@@ -74,6 +74,23 @@
end
end
+ describe "#full_text" do
+ it "should return the text of a status" do
+ status = Twitter::Status.new('text' => 'BOOSH')
+ status.full_text.should be_a String
+ status.full_text.should == "BOOSH"
+ end
+ it "should return the full text of a retweeted status" do
+ status = Twitter::Status.new('retweeted_status' => {'text' => 'BOOSH', 'user' => {'screen_name' => 'sferik'}})
+ status.full_text.should be_a String
+ status.full_text.should == "RT @sferik: BOOSH"
+ end
+ it "should return nil when retweeted_status is not set" do
+ status = Twitter::Status.new
+ status.full_text.should be_nil
+ end
+ end
+
describe "#geo" do
it "should return a Twitter::Point when set" do
status = Twitter::Status.new('geo' => {'type' => 'Point'})
@@ -167,13 +184,11 @@
end
describe "#retweeted_status" do
- before do
- @a_retweeted_status = Twitter::Status.new('retweeted_status' => {'text' => 'BOOSH'})
- end
it "should return a Status when retweeted_status is set" do
- @a_retweeted_status.retweeted_status.should be_a Twitter::Status
+ status = Twitter::Status.new('retweeted_status' => {'text' => 'BOOSH'})
+ status.retweeted_status.should be_a Twitter::Status
end
- it "should return nil when a retweeted_status is NOT set" do
+ it "should return nil when retweeted_status is not set" do
status = Twitter::Status.new
status.retweeted_status.should be_nil
end

0 comments on commit a03eb94

Please sign in to comment.