twitter_stream_message/tweet.rs
1//! Tweets
2
3use std::borrow::Cow;
4use std::collections::HashMap;
5
6use {Entities, Geometry, Place};
7use types::{DateTime, FilterLevel, JsonValue, WithheldScope};
8use user::{User, UserId};
9
10/// Represents a Tweet.
11///
12/// # Reference
13///
14/// [Tweets — Twitter Developers][1]
15///
16/// [1]: https://dev.twitter.com/overview/api/tweets
17#[derive(Clone, Debug, Deserialize, PartialEq)]
18pub struct Tweet<'a> {
19 // pub contributors: Option<_>, // deprecated
20
21 /// Represents the geographic location of this Tweet as reported
22 /// by the user or client application.
23 pub coordinates: Option<Geometry>,
24
25 /// UTC time when this Tweet was created.
26 #[serde(deserialize_with = "::util::deserialize_datetime")]
27 pub created_at: DateTime,
28
29 // pub current_user_retweet: Option<StatusId>,
30
31 /// Entities which have been parsed out of the text of the Tweet.
32 #[serde(borrow)]
33 pub entities: Entities<'a>,
34
35 /// Indicates approximately how many times this Tweet has been liked
36 /// by Twitter users.
37 pub favorite_count: Option<u64>,
38
39 /// *Perspectival* Indicates whether this Tweet has been liked
40 /// by the authenticating user.
41 pub favorited: Option<bool>,
42
43 /// Indicates the maximum value of the `filter_level` parameter which may
44 /// be used and still stream this Tweet. So a value of `Medium` will be
45 /// streamed on `None`, `Low`, and `Medium` streams.
46 #[serde(borrow)]
47 pub filter_level: Option<FilterLevel<'a>>,
48
49 // pub geo: _, // deprecated in favor of `coordinates` field.
50
51 /// The integer representation of the unique identifier for this Tweet.
52 pub id: StatusId,
53
54 // pub id_str: String,
55
56 /// If the represented Tweet is a reply, this field will contain
57 /// the screen name of the original Tweet’s author.
58 #[serde(borrow)]
59 #[serde(default)]
60 #[serde(deserialize_with = "::util::deserialize_opt_cow_str")]
61 pub in_reply_to_screen_name: Option<Cow<'a, str>>,
62
63 /// If the represented Tweet is a reply, this field will contain
64 /// the integer representation of the original Tweet’s ID.
65 pub in_reply_to_status_id: Option<StatusId>,
66
67 // pub in_reply_to_status_id_str: Option<String>,
68
69 /// If the represented Tweet is a reply, this field will contain
70 /// the integer representation of the original Tweet’s author ID. This will
71 /// not necessarily always be the user directly mentioned in the Tweet.
72 pub in_reply_to_user_id: Option<UserId>,
73
74 // pub in_reply_to_user_id_str: Option<String>,
75
76 pub is_quote_status: bool,
77
78 /// When present, indicates a [BCP 47][1] language identifier corresponding
79 /// to the machine-detected language of the Tweet text,
80 /// or `und` if no language could be detected.
81 ///
82 /// [1]: http://tools.ietf.org/html/bcp47
83 #[serde(borrow)]
84 #[serde(default)]
85 #[serde(deserialize_with = "::util::deserialize_opt_cow_str")]
86 pub lang: Option<Cow<'a, str>>,
87
88 /// When present, indicates that the tweet is associated
89 /// (but not necessarily originating from) a [Place][1].
90 ///
91 /// [1]: struct.Place.html
92 #[serde(borrow)]
93 pub place: Option<Place<'a>>,
94
95 /// This field only surfaces when a Tweet contains a link.
96 /// The meaning of the field doesn’t pertain to the Tweet content itself,
97 /// but instead it is an indicator that the URL contained in the Tweet
98 /// may contain content or media identified as sensitive content.
99 pub possibly_sensitive: Option<bool>,
100
101 /// This field only surfaces when the Tweet is a quote Tweet.
102 /// This field contains the integer value Tweet ID of the quoted Tweet.
103 pub quoted_status_id: Option<StatusId>,
104
105 // pub quoted_status_id_str: Option<String>,
106
107 /// This field only surfaces when the Tweet is a quote Tweet. This attribute
108 /// contains the `Tweet` object of the original Tweet that was quoted.
109 #[serde(borrow)]
110 pub quoted_status: Option<Box<Tweet<'a>>>,
111
112 /// A set of key-value pairs indicating the intended contextual delivery
113 /// of the containing Tweet. Currently used by Twitter’s Promoted Products.
114 pub scopes: Option<HashMap<String, JsonValue>>,
115
116 /// Number of times this Tweet has been retweeted.
117 pub retweet_count: u64,
118
119 /// *Perspectival* Indicates whether this Tweet has been retweeted
120 /// by the authenticating user.
121 pub retweeted: bool,
122
123 /// Users can amplify the broadcast of Tweets authored by other users
124 /// by [retweeting][1]. Retweets can be distinguished from typical Tweets
125 /// by the existence of a `retweeted_status` attribute. This attribute
126 /// contains a representation of the original Tweet that was retweeted.
127 ///
128 /// [1]: https://dev.twitter.com/rest/reference/post/statuses/retweet/%3Aid
129 ///
130 /// Note that retweets of retweets do not show representations of
131 /// the intermediary retweet, but only the original Tweet. (Users can also
132 /// [unretweet][2] a retweet they created by deleting their retweet.)
133 ///
134 /// [2]: https://dev.twitter.com/rest/reference/post/statuses/destroy/%3Aid
135 #[serde(borrow)]
136 pub retweeted_status: Option<Box<Tweet<'a>>>,
137
138 /// Utility used to post the Tweet, as an HTML-formatted string.
139 /// Tweets from the Twitter website have a source value of `web`.
140 #[serde(borrow)]
141 pub source: Cow<'a, str>,
142
143 /// The actual UTF-8 text of the status update. See [twitter-text][1]
144 /// for details on what is currently considered valid characters.
145 ///
146 /// [1]: https://github.com/twitter/twitter-text/blob/master/rb/lib/twitter-text/regex.rb
147 #[serde(borrow)]
148 pub text: Cow<'a, str>,
149
150 /// Indicates whether the value of the `text` parameter was truncated,
151 /// for example, as a result of a retweet exceeding the 140 character
152 /// Tweet length. Truncated text will end in ellipsis, like this `...`
153 ///
154 /// Since Twitter now rejects long Tweets vs truncating them,
155 /// the large majority of Tweets will have this set to `false`.
156 ///
157 /// Note that while native retweets may have their toplevel `text` property
158 /// shortened, the original text will be available under
159 /// the `retweeted_status` object and the `truncated` parameter will be set
160 /// to the value of the original status (in most cases, `false`).
161 pub truncated: bool,
162
163 /// The user who posted this Tweet.
164 /// Perspectival attributes embedded within this object are unreliable.
165 #[serde(borrow)]
166 pub user: User<'a>,
167
168 /// When set to `true`, it indicates that this piece of content has been
169 /// withheld due to a [DMCA complaint][1].
170 ///
171 /// [1]: http://en.wikipedia.org/wiki/Digital_Millennium_Copyright_Act
172 #[serde(default)]
173 pub withheld_copyright: bool,
174
175 /// When present, indicates a list of uppercase
176 /// [two-letter country codes][1] this content is withheld from.
177 /// Twitter supports the following non-country values for this field:
178 ///
179 /// [1]: http://en.wikipedia.org/wiki/ISO_3166-1_alpha-2
180 ///
181 /// - `XX` - Content is withheld in all countries
182 /// - `XY` - Content is withheld due to a DMCA request.
183 #[serde(borrow)]
184 #[serde(default)]
185 pub withheld_in_countries: Vec<Cow<'a, str>>,
186
187 /// When present, indicates whether the content being withheld is
188 /// the `Status` or a `User`.
189 #[serde(borrow)]
190 pub withheld_scope: Option<WithheldScope<'a>>,
191}
192
193/// ID of a Tweet.
194pub type StatusId = u64;