Class: Tweet
- Inherits:
-
ActiveRecord::Base
- Object
- ActiveRecord::Base
- Tweet
- Defined in:
- app/models/tweet.rb
Class Method Summary collapse
-
.find_or_create!(tuit) ⇒ Tweet
It uses a Twitter::Tweet to find and update an existing Tweet or create a new one.
Instance Method Summary collapse
Class Method Details
.find_or_create!(tuit) ⇒ Tweet
It uses a Twitter::Tweet to find and update an existing Tweet or create a new one
19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 |
# File 'app/models/tweet.rb', line 19 def self.find_or_create!(tuit) opts = { id: tuit.id } if result = self.find_by(opts) result.update_attributes!(json: tuit.to_json) else result = self.new(opts.merge(json: tuit.to_json)) user = User.find_or_create!(result) result.user = user result.save! end result end |
Instance Method Details
#created_at ⇒ Object
43 44 45 46 |
# File 'app/models/tweet.rb', line 43 def created_at @created_at ||= Time.parse(source["created_at"]) @created_at.in_time_zone end |
#source ⇒ Object
35 36 37 |
# File 'app/models/tweet.rb', line 35 def source @source ||= OpenStruct.new(JSON.load(json)) end |
#source_url ⇒ Object
39 40 41 |
# File 'app/models/tweet.rb', line 39 def source_url "https://twitter.com/#{user.username}/status/#{source.id_str}" end |