Class: Tweet
- Inherits:
-
Object
- Object
- Tweet
- Includes:
- MongoMapper::Document
- Defined in:
- lib/oii_twitter_goodies/model/tweet.rb
Class Method Summary collapse
Class Method Details
.example ⇒ Object
45 46 47 |
# File 'lib/oii_twitter_goodies/model/tweet.rb', line 45 def self.example {"entities"=>{"user_mentions"=>[], "urls"=>[{"display_url"=>"tehelka.com/story_main54.a...", "expanded_url"=>"http://www.tehelka.com/story_main54.asp?filename=Ws041212SPORTS.asp", "url"=>"http://t.co/uZmKgdkO", "indices"=>[120, 140]}], "hashtags"=>[]}, "text"=>"On the day Indian Olympics Association was suspended by IOC, Rahul Mehra says the move gives an opportunity to clean up http://t.co/uZmKgdkO", "retweet_count"=>2, "coordinates"=>nil, "possibly_sensitive"=>false, "in_reply_to_status_id_str"=>nil, "contributors"=>nil, "in_reply_to_user_id_str"=>nil, "id_str"=>"276035961274638336", "in_reply_to_screen_name"=>nil, "retweeted"=>false, "truncated"=>false, "created_at"=>"Tue Dec 04 18:51:16 +0000 2012", "geo"=>nil, "place"=>nil, "in_reply_to_status_id"=>nil, "favorited"=>false, "source"=>"web", "id"=>276035961274638336, "in_reply_to_user_id"=>nil} end |
.new_from_raw(tweet, user_id) ⇒ Object
49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 |
# File 'lib/oii_twitter_goodies/model/tweet.rb', line 49 def self.new_from_raw(tweet, user_id) return if tweet.nil? tweet = Hashie::Mash[tweet] obj = self.new obj.created_at = tweet["created_at"] obj.twitter_id = tweet["id"] obj.twitter_id_str = tweet["id_str"] obj.text = tweet["text"] obj.source = tweet["source"] obj.truncated = tweet["truncated"] obj.in_reply_to_status_id = tweet["in_reply_to_status_id"] obj.in_reply_to_status_id_str = tweet["in_reply_to_status_id_str"] obj.in_reply_to_user_id = tweet["in_reply_to_user_id"] obj.in_reply_to_user_id_str = tweet["in_reply_to_user_id_str"] obj.in_reply_to_screen_name = tweet["in_reply_to_screen_name"] obj.contributors = tweet["contributors"] obj.retweet_count = tweet["retweet_count"] obj.favorited = tweet["favorited"] obj.retweeted = tweet["retweeted"] obj.possibly_sensitive = tweet["possibly_sensitive"] tweet["twitter_id"] = obj.twitter_id if tweet["entities"] tweet["entities"].each_pair do |entity_type, entities| if entity_type == "media" entities.each do |entity| entity = Medium.new_from_raw(entity, obj._id) obj.media << entity end elsif entity_type == "urls" entities.each do |entity| entity = Url.new_from_raw(entity, obj._id) obj.urls << entity end elsif entity_type == "hashtags" entities.each do |entity| entity = Hashtag.new_from_raw(entity, obj._id) obj. << entity end elsif entity_type == "user_mentions" entities.each do |entity| entity = UserMention.new_from_raw(entity, obj._id) obj.user_mentions << entity end end end end place = Place.new_from_raw(tweet["place"], obj._id) if place obj.place = place end geo = Geo.new_from_raw(tweet["geo"], obj._id) if geo obj.geo = geo end coordinate = Coordinate.new_from_raw(tweet["coordinate"], obj._id) if coordinate obj.coordinate = coordinate end obj.user_id = user_id obj.save! obj end |