Class: Wuclan::JsonModel::JsonTweet
- Inherits:
-
GenericJsonParser
- Object
- GenericJsonParser
- Wuclan::JsonModel::JsonTweet
- Defined in:
- lib/wuclan/twitter/parse/json_tweet.rb
Overview
The JSON tweets records come off the wire a bit more heavyweight than we’d like.
A sample JSON file, reformatted for clarity:
"id" : 1012519767,
"created_at" : "Wed Nov 19 07:16:58 +0000 2008",
// twitter_user_id
"favorited" : false,
"truncated" : false,
"in_reply_to_user_id" : null,
"in_reply_to_status_id" : null,
"text" : "[Our lander (RIP) had the best name. The next rover to Mars, @MarsScienceLab, needs a name. A contest for kids: http:\/\/is.gd\/85rQ ]"
"source" : "web",
Instance Attribute Summary collapse
-
#raw ⇒ Object
Returns the value of attribute raw.
Instance Method Summary collapse
-
#fix_raw! ⇒ Object
Make the data easier for batch flat-record processing.
- #generate_tweet ⇒ Object
-
#generate_user_partial ⇒ Object
produce the included last tweet.
- #healthy? ⇒ Boolean
-
#initialize(raw, twitter_user_id = nil) ⇒ JsonTweet
constructor
A new instance of JsonTweet.
Methods inherited from GenericJsonParser
Constructor Details
#initialize(raw, twitter_user_id = nil) ⇒ JsonTweet
Returns a new instance of JsonTweet.
24 25 26 27 28 29 30 31 32 |
# File 'lib/wuclan/twitter/parse/json_tweet.rb', line 24 def initialize raw, twitter_user_id = nil self.raw = raw; return unless healthy? if twitter_user_id raw['twitter_user_id'] = twitter_user_id elsif raw['user'] && raw['user']['id'] raw['twitter_user_id'] = raw['user']['id'] end self.fix_raw! end |
Instance Attribute Details
#raw ⇒ Object
Returns the value of attribute raw.
23 24 25 |
# File 'lib/wuclan/twitter/parse/json_tweet.rb', line 23 def raw @raw end |
Instance Method Details
#fix_raw! ⇒ Object
Make the data easier for batch flat-record processing
39 40 41 42 43 44 45 46 47 48 |
# File 'lib/wuclan/twitter/parse/json_tweet.rb', line 39 def fix_raw! raw['id'] = ModelCommon.zeropad_id( raw['id']) raw['created_at'] = ModelCommon.flatten_date(raw['created_at']) raw['favorited'] = ModelCommon.unbooleanize(raw['favorited']) raw['truncated'] = ModelCommon.unbooleanize(raw['truncated']) raw['twitter_user_id'] = ModelCommon.zeropad_id(raw['twitter_user_id'] ) raw['in_reply_to_user_id'] = ModelCommon.zeropad_id(raw['in_reply_to_user_id']) unless raw['in_reply_to_user_id'].blank? || (raw['in_reply_to_user_id'].to_i == 0) raw['in_reply_to_status_id'] = ModelCommon.zeropad_id(raw['in_reply_to_status_id']) unless raw['in_reply_to_status_id'].blank? || (raw['in_reply_to_status_id'].to_i == 0) Wukong.encode_components raw, 'text' end |
#generate_tweet ⇒ Object
50 51 52 53 |
# File 'lib/wuclan/twitter/parse/json_tweet.rb', line 50 def generate_tweet return unless healthy? Tweet.from_hash(raw) end |
#generate_user_partial ⇒ Object
produce the included last tweet
57 58 59 60 |
# File 'lib/wuclan/twitter/parse/json_tweet.rb', line 57 def generate_user_partial raw_user = raw['user'] or return JsonTwitterUser.new(raw_user, raw['created_at']).generate_user_partial end |
#healthy? ⇒ Boolean
33 |
# File 'lib/wuclan/twitter/parse/json_tweet.rb', line 33 def healthy?() raw && raw.is_a?(Hash) end |