@@ -52,6 +52,10 @@ def author_id
5252 data [ "author_id" ]
5353 end
5454
55+ def author
56+ expansions &.users . find { |user | user . id == author_id }
57+ end
58+
5559 # Returns the origin / root Tweet ID of the conversation (which includes direct replies, replies of replies)
5660 #
5761 # @note The field +tweet.fields=conversation_id+ must be specified when fetching the tweet to access this data
@@ -61,6 +65,10 @@ def conversation_id
6165 data [ "conversation_id" ]
6266 end
6367
68+ def conversation
69+ expansions &.tweets . find { |tweet | tweet . conversation_id == conversation_id }
70+ end
71+
6472 # If this Tweet is a reply, returns the user ID of the parent tweet's author
6573 #
6674 # @note The expansion +expansions=in_reply_to_user_id+ must be specified when fetching the tweet to access this data
@@ -70,6 +78,10 @@ def in_reply_to_user_id
7078 data [ "in_reply_to_user_id" ]
7179 end
7280
81+ def reply_to
82+ expansions &.users . find { |user | user . id == in_reply_to_user_id }
83+ end
84+
7385 # A list of Tweets this Tweet refers to. For example, if the parent Tweet is a Retweet, a Retweet with comment (also known as Quoted Tweet) or a Reply, it will include the related Tweet referenced to by its parent
7486 #
7587 # @note The field +tweet.fields=referenced_tweets+ must be specified when fetching the tweet to access this data
@@ -87,6 +99,8 @@ def referenced_tweets
8799 #
88100 # @return [Attachments]
89101 def attachments
102+ return if data . dig ( "attachments" , "media_keys" ) . nil?
103+
90104 @attachments ||= Attachments . new ( data [ "attachments" ] [ "media_keys" ] )
91105 end
92106
@@ -96,6 +110,8 @@ def attachments
96110 #
97111 # @return [Polls]
98112 def polls
113+ return if data . dig ( "attachments" , "poll_ids" ) . nil?
114+
99115 @polls ||= Polls . new ( data [ "attachments" ] [ "poll_ids" ] )
100116 end
101117
@@ -105,6 +121,8 @@ def polls
105121 #
106122 # @return [Geo]
107123 def geo
124+ return if data [ "geo" ] . nil?
125+
108126 @geo ||= Geo . new ( data [ "geo" ] )
109127 end
110128
@@ -116,6 +134,8 @@ def geo
116134 #
117135 # @return [ContextAnnotations]
118136 def context_annotations
137+ return if data [ "context_annotations" ] . nil?
138+
119139 @context_annotations ||= ContextAnnotations . new ( data [ "context_annotations" ] )
120140 end
121141
@@ -128,6 +148,8 @@ def context_annotations
128148 #
129149 # @return [EntityAnnotations]
130150 def entity_annotations
151+ return if data [ "entities" ] . nil?
152+
131153 @entity_annotations ||= EntityAnnotations . new ( data [ "entities" ] )
132154 end
133155
@@ -153,6 +175,8 @@ def withheld
153175 #
154176 # @return [Tweetkit::Response::Tweet::Metrics]
155177 def metrics
178+ return if data [ "public_metrics" ] . nil? && data [ "non_public_metrics" ] . nil? && data [ "organic_metrics" ] . nil? && data [ "promoted_metrics" ] . nil?
179+
156180 @metrics ||= Metrics . new (
157181 public_metrics : data [ "public_metrics" ] ,
158182 private_metrics : data [ "non_public_metrics" ] ,
@@ -250,7 +274,6 @@ def url
250274 alias_method :device , :source
251275 alias_method :date , :created_at
252276 alias_method :parent_tweet_id , :conversation_id
253- alias_method :reply_to , :in_reply_to_user_id
254277 alias_method :nsfw? , :possibly_sensitive
255278 alias_method :sensitive? , :possibly_sensitive
256279 alias_method :non_public_metrics , :private_metrics
0 commit comments