Skip to content

Commit 80253e9

Browse files
Deprecate Faker::Twitter in favor of Faker::X and update attributes (#3138)
* Add deprecation warning for Faker::Twitter Besides renaming the generator to Faker::X, the generator is vastly outdated. Twitter, aka X API, has changed a lot (it's now v2), and most of the attributes being returned in the user have been deprecated: https://docs.x.com/x-api/enterprise-gnip-2.0/fundamentals/data-dictionary#no-longer-supported-deprecated-attributes To maintain backwards compatibility, users still using Faker::Twitter will keep using it but be notified of the upcoming changes. Initially, the goal was to only update the `user` generator but then I realized it wouldn't make sense to leave `status` as it is. * Deprecate Faker::Twitter and update status to tweet After working on the user generator, it made sense to also deprecate the `status` one. The API migration docs don't mention changing status to tweet, but after inspecting what `status` returns, I realized the new API calls is `tweet`. There were lots of changes for both user and tweet objects. Most notably, the shape of the response, additional fields, and removal of deprecated attributes. Used resources as references: - https://docs.x.com/x-api/migrate/data-format-migration#user-object - https://docs.x.com/x-api/fundamentals/data-dictionary#tweet - https://docs.x.com/x-api/migrate/data-format-migration#entities-and-expanded-entities-objects * Update docs
1 parent 94adefd commit 80253e9

File tree

5 files changed

+480
-30
lines changed

5 files changed

+480
-30
lines changed

README.md

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -34,6 +34,7 @@ and it was the original impetus for the creation of this gem.
3434

3535
- [Faker](#faker)
3636
- [Quick links](#quick-links)
37+
- [In the media](#in-the-media)
3738
- [Table of Contents](#table-of-contents)
3839
- [Notes](#notes)
3940
- [Getting Started](#getting-started)
@@ -291,13 +292,13 @@ gem 'faker', :git => 'https://github.com/faker-ruby/faker.git', :branch => 'main
291292
- [Faker::Team](doc/default/team.md)
292293
- [Faker::Theater](doc/default/theater.md)
293294
- [Faker::Time](doc/default/time.md)
294-
- [Faker::Twitter](doc/default/twitter.md)
295295
- [Faker::Types](doc/default/types.md)
296296
- [Faker::University](doc/default/university.md)
297297
- [Faker::Vehicle](doc/default/vehicle.md)
298298
- [Faker::Verbs](doc/default/verbs.md)
299299
- [Faker::VulnerabilityIdentifier](doc/default/vulnerability_identifier.md)
300300
- [Faker::WorldCup](doc/default/world_cup.md)
301+
- [Faker::X](doc/default/x.md)
301302
</details>
302303

303304
<details>

doc/default/twitter.md

Lines changed: 0 additions & 29 deletions
This file was deleted.

doc/default/x.md

Lines changed: 228 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,228 @@
1+
`Faker::Twitter` has been deprecated in favor of `Faker::X`. While it's still maintained, its docs can be found at [Faker::Twitter](#fakertwitter).
2+
3+
# Faker::X
4+
5+
Generates approximate X (previously Twitter) user and tweet objects, based on X's API v2 responses.
6+
7+
The generators are not a comprehensive match of the API. However, they are enough to create a demo app using X’s user or tweet data, for example.
8+
9+
## Faker::X.user
10+
11+
Produces a random X user based on X's v2 API:
12+
13+
```ruby
14+
Faker::X.user =>
15+
{
16+
data: [
17+
{
18+
author_id: "5688134805624042468",
19+
id: "2007502004337242257",
20+
text: "Qui sint magni vel."
21+
}
22+
],
23+
includes: {
24+
users: [
25+
{
26+
public_metrics: {
27+
followers_count: 1000,
28+
following_count: 77,
29+
tweet_count: 4642,
30+
listed_count: 704
31+
},
32+
username: "lilian",
33+
pinned_tweet_id: "1702549793917523469",
34+
entities: {
35+
url: {
36+
urls: [ { url: "https://t.co/0iz5wx1ysh", expanded_url: "http://example.com/stuart", display_url: "example.com/stuart" }]
37+
},
38+
description: { hashtags: [{tag: "Adipisci"}] }
39+
},
40+
description: "Est est laborum dolores.",
41+
name: "Kimberli Ullrich Jr.",
42+
verified: false,
43+
location: "104.82.135.3",
44+
id: "5688134805624042468",
45+
protected: false,
46+
url: "https://t.co/lqsqf67cx5",
47+
profile_image_url: "https://robohash.org/990174365255127568.png?size=48x48&set=set1",
48+
created_at: "2018-07-11T00:00:00+00:00"
49+
}
50+
]
51+
}
52+
}
53+
```
54+
55+
## Faker::X.tweet
56+
57+
Produces a random X tweet with default attributes. Available extensions can be returned with `include_media` and `include_user`:
58+
59+
```ruby
60+
# Keyword arguments: include_user, include_media
61+
Faker::Twitter.tweet #=> { data: [{:id=>"8821452687517076614", :text=>"Ea et laboriosam vel non.",...
62+
Faker::Twitter.tweet(include_user: true) # Includes user attributes
63+
Faker::Twitter.tweet(include_media: true) # Includes media (photo) attributes
64+
```
65+
66+
Example outputs:
67+
68+
```ruby
69+
Faker::X.tweet =>
70+
{
71+
data: [{
72+
id: "5530076569335337477",
73+
text: "Omnis facere ullam velit.",
74+
lang: "ja",
75+
conversation_id: "5530076569335337477",
76+
created_at: "2009-02-21T07:00:00.000Z",
77+
author_id: "2788144046134446176",
78+
public_metrics: {
79+
retweet_count: 95,
80+
reply_count: 3,
81+
like_count: 10,
82+
quote_count: 3
83+
},
84+
possibly_sensitive: false,
85+
entities: {
86+
urls: [{
87+
start: 0,
88+
end: 5,
89+
url: "https://t.co/t6o3lav9z1",
90+
expanded_url: "http://example.com/errol.upton",
91+
display_url: "example.com/errol.upton"
92+
}],
93+
hashtags: [{
94+
start: 0,
95+
end: 5,
96+
tag: "Odit"
97+
}]
98+
}
99+
}]
100+
}
101+
```
102+
103+
With additional fields:
104+
105+
```ruby
106+
Faker::X.tweet(include_media: true, include_user: true) =>
107+
{
108+
data: [{
109+
id: "5340086698567112794",
110+
text: "Esse nulla minus qui.",
111+
lang: "en",
112+
conversation_id: "5340086698567112794",
113+
created_at: "2009-07-04T06:00:00.000Z",
114+
author_id: "5156189524741091965",
115+
public_metrics: {
116+
retweet_count: 56,
117+
reply_count: 2,
118+
like_count: 23,
119+
quote_count: 1
120+
},
121+
possibly_sensitive: false,
122+
entities: {
123+
urls: [{
124+
start: 0,
125+
end: 5,
126+
url: "https://t.co/mqplf9rhpn",
127+
expanded_url: "http://example.com/mohamed_koelpin",
128+
display_url: "example.com/mohamed_koelpin"
129+
}],
130+
hashtags: [{
131+
start: 0,
132+
end: 5,
133+
tag: "Atque"
134+
}]
135+
},
136+
attachments: {
137+
media_keys: ["6992225089295851582"]
138+
}
139+
}],
140+
includes: {
141+
media: [{
142+
height: 526,
143+
media_key: "6992225089295851582",
144+
type: "photo",
145+
preview_image_url: "https://loremflickr.com/1064/600",
146+
width: 1571,
147+
alt_text: "Qui ratione magnam et."
148+
}],
149+
users: [{
150+
public_metrics: {
151+
followers_count: 467,
152+
following_count: 3,
153+
tweet_count: 9006,
154+
listed_count: 984
155+
},
156+
username: "gayle",
157+
pinned_tweet_id: "2282479924658708548",
158+
entities: {
159+
url: {
160+
urls: [{
161+
start: 0,
162+
end: 5,
163+
url: "https://t.co/69eytnuwwu",
164+
expanded_url: "http://example.com/werner",
165+
display_url: "example.com/werner"
166+
}]
167+
},
168+
description: {
169+
hashtags: [{
170+
start: 0,
171+
end: 5,
172+
tag: "Soluta"
173+
}]
174+
}
175+
},
176+
description: "Esse harum voluptatem voluptate.",
177+
name: "Elva Spinka",
178+
verified: false,
179+
location: "34.230.131.77",
180+
id: "2365736908578621112",
181+
protected: false,
182+
url: "https://t.co/pyuqky3gdl",
183+
profile_image_url: "https://robohash.org/2204799175591912732.png?size=48x48&set=set1",
184+
created_at: "2025-01-30T07:00:00.000Z"
185+
}]
186+
}
187+
}
188+
```
189+
190+
## Faker::X.screen_name
191+
192+
Produces a random screen_name:
193+
194+
```ruby
195+
Faker::X.screen_name #=> "audreanne_hackett"
196+
```
197+
198+
# Faker::Twitter
199+
200+
This generator has been deprecated. Please use `Faker::X` instead. Note that some attributes have been deprecated by [X's API](https://docs.x.com/x-api/migrate/data-format-migration).
201+
202+
Available since version 1.7.3.
203+
204+
Generate realistic Twitter user and status objects similar to what you would get back from the API.
205+
206+
```json
207+
{
208+
"created_at": "Mon Dec 10 00:00:00 +0000 2012",
209+
"id": 8821452687517076614,
210+
"id_str": "8821452687517076614",
211+
"text": "Ea et laboriosam vel non.",
212+
// ...
213+
}
214+
```
215+
216+
```ruby
217+
# Keyword arguments: include_status, include_email
218+
Faker::Twitter.user #=> {:id=>8821452687517076614, :name=>"Lincoln Paucek", :screen_name=>"cody"...
219+
Faker::Twitter.user(include_status: false) # Just get a user object with no embed status
220+
Faker::Twitter.user(include_email: true) # Simulate an authenticated user with the email permission
221+
222+
# Keyword arguments: include_user, include_photo
223+
Faker::Twitter.status #=> {:id=>8821452687517076614, :text=>"Ea et laboriosam vel non."...
224+
Faker::Twitter.status(include_user: false) # Just get a status object with no embed user
225+
Faker::Twitter.status(include_photo: true) # Includes entities for an attached image
226+
227+
Faker::Twitter.screen_name #=> "audreanne_hackett"
228+
```

0 commit comments

Comments
 (0)