|
| 1 | +`Faker::Twitter` has been deprecated. While it's still maintained, its docs can be found at [Faker::Twitter](#fakertwitter). |
| 2 | + |
| 3 | +# Faker::X |
| 4 | + |
| 5 | +Generates approximate X (previous 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 | + data: [ |
| 16 | + { |
| 17 | + author_id: "5688134805624042468", |
| 18 | + id: "2007502004337242257", |
| 19 | + text: "Qui sint magni vel." |
| 20 | + } |
| 21 | + ], |
| 22 | + includes: { |
| 23 | + users: [ |
| 24 | + { |
| 25 | + public_metrics: { |
| 26 | + followers_count: 1000, |
| 27 | + following_count: 77, |
| 28 | + tweet_count: 4642, |
| 29 | + listed_count: 704 |
| 30 | + }, |
| 31 | + username: "lilian", |
| 32 | + pinned_tweet_id: "1702549793917523469", |
| 33 | + entities: { |
| 34 | + url: { |
| 35 | + urls: [ { url: "https://t.co/0iz5wx1ysh", expanded_url: "http://example.com/stuart", display_url: "example.com/stuart" }] |
| 36 | + }, |
| 37 | + description: { hashtags: [{tag: "Adipisci"}] } |
| 38 | + }, |
| 39 | + description: "Est est laborum dolores.", |
| 40 | + name: "Kimberli Ullrich Jr.", |
| 41 | + verified: false, |
| 42 | + location: "104.82.135.3", |
| 43 | + id: "5688134805624042468", |
| 44 | + protected: false, |
| 45 | + url: "https://t.co/lqsqf67cx5", |
| 46 | + profile_image_url: "https://robohash.org/990174365255127568.png?size=48x48&set=set1", |
| 47 | + created_at: "2018-07-11T00:00:00+00:00" |
| 48 | + } |
| 49 | + ] |
| 50 | + } |
| 51 | +} |
| 52 | +``` |
| 53 | + |
| 54 | +## Faker::X.tweet |
| 55 | + |
| 56 | +Produces a random X tweet with default attributes. Available extensions can be returned with `include_media` and `include_user`: |
| 57 | + |
| 58 | +```ruby |
| 59 | +# Keyword arguments: include_user, include_media |
| 60 | +Faker::Twitter.tweet #=> { data: [{:id=>"8821452687517076614", :text=>"Ea et laboriosam vel non.",... |
| 61 | +Faker::Twitter.tweet(include_user: true) # Includes user attributes |
| 62 | +Faker::Twitter.tweet(include_media: true) # Includes media (photo) attributes |
| 63 | +``` |
| 64 | + |
| 65 | +Example outputs: |
| 66 | + |
| 67 | +```ruby |
| 68 | +Faker::X.tweet => |
| 69 | +{ |
| 70 | + data: [ |
| 71 | + { |
| 72 | + id: "7999525033982409544", |
| 73 | + text: "Molestias non possimus voluptatem.", |
| 74 | + lang: "VA", |
| 75 | + conversation_id: "7999525033982409544", |
| 76 | + created_at: "2011-03-16T00:00:00+00:00", |
| 77 | + public_metrics: {retweet_count: 69, reply_count: 17, like_count: 21, quote_count: 8}, |
| 78 | + possibly_sensitive: false, |
| 79 | + entities: { |
| 80 | + url: { urls: [{url: "https://t.co/gz4z8dvybe", expanded_url: "http://example.com/salley.grant", display_url: "example.com/salley.grant"}] }, |
| 81 | + description: { hashtags: [{tag: "Veritatis"}] } |
| 82 | + }, |
| 83 | + in_reply_to_user_id: false |
| 84 | + } |
| 85 | + ] |
| 86 | +} |
| 87 | +``` |
| 88 | + |
| 89 | +With additional fields: |
| 90 | + |
| 91 | +```ruby |
| 92 | +Faker::X.tweet(include_media: true, include_user: true) => |
| 93 | + |
| 94 | +{ |
| 95 | + data: [ |
| 96 | + { |
| 97 | + id: "8194812886422142201", |
| 98 | + text: "Eos sed quibusdam aperiam.", |
| 99 | + lang: "AU", |
| 100 | + conversation_id: "8194812886422142201", |
| 101 | + created_at: "2017-10-24T00:00:00+00:00", |
| 102 | + public_metrics: {retweet_count: 87, reply_count: 19, like_count: 14, quote_count: 4}, |
| 103 | + possibly_sensitive: false, |
| 104 | + entities: { |
| 105 | + url: { urls: [{url: "https://t.co/h9pi5f7q7j", expanded_url: "http://example.com/angelica_moore", display_url: "example.com/angelica_moore"}] }, |
| 106 | + description: { hashtags: [{tag: "Saepe"}] } |
| 107 | + }, |
| 108 | + in_reply_to_user_id: false}, |
| 109 | + { attachments: {media_keys: ["466995304449852781"]} |
| 110 | + } |
| 111 | + ], |
| 112 | + includes: { |
| 113 | + media: [ |
| 114 | + { |
| 115 | + type: "photo", |
| 116 | + indices: [103, 126], |
| 117 | + height: 446, |
| 118 | + media_key: "466995304449852781", |
| 119 | + preview_image_url: "https://loremflickr.com/1064/600", |
| 120 | + width: 1321, |
| 121 | + url: "https://t.co/s3j25etwdj", |
| 122 | + expanded_url: "https://loremflickr.com/1064/600", |
| 123 | + display_url: "loremflickr.com/1064/600", |
| 124 | + alt_text: "Et possimus repudiandae tenetur." |
| 125 | + } |
| 126 | + ], |
| 127 | + users: [ |
| 128 | + { |
| 129 | + public_metrics: {followers_count: 488, following_count: 180, tweet_count: 6368, listed_count: 209}, |
| 130 | + username: "shante", |
| 131 | + pinned_tweet_id: "7350697183426089357", |
| 132 | + entities: { |
| 133 | + url: { urls: [{url: "https://t.co/cxwehs7i1z", expanded_url: "http://example.com/kirstie.reilly", display_url: "example.com/kirstie.reilly"}] }, |
| 134 | + description: { hashtags: [{tag: "Rem"}] } |
| 135 | + }, |
| 136 | + description: "Ipsa nihil velit adipisci.", |
| 137 | + name: "Jerome Heathcote III", |
| 138 | + verified: false, |
| 139 | + location: "222.70.154.120", |
| 140 | + id: "5679269981284870916", |
| 141 | + protected: false, |
| 142 | + url: "https://t.co/5xyjlv6ckv", |
| 143 | + profile_image_url: "https://robohash.org/4106878141532070549.png?size=48x48&set=set1", |
| 144 | + created_at: "2019-01-27T00:00:00+00:00" |
| 145 | + } |
| 146 | + ] |
| 147 | + } |
| 148 | +} |
| 149 | +``` |
| 150 | + |
| 151 | +## Faker::X.screen_name |
| 152 | + |
| 153 | +Produces a random screen_name: |
| 154 | + |
| 155 | +```ruby |
| 156 | +Faker::Twitter.screen_name #=> "audreanne_hackett" |
| 157 | +``` |
| 158 | + |
| 159 | +# Faker::Twitter |
| 160 | + |
| 161 | +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). |
| 162 | + |
| 163 | +Available since version 1.7.3. |
| 164 | + |
| 165 | +Generate realistic Twitter user and status objects similar to what you would get back from the API. |
| 166 | + |
| 167 | +```json |
| 168 | +{ |
| 169 | + "created_at": "Mon Dec 10 00:00:00 +0000 2012", |
| 170 | + "id": 8821452687517076614, |
| 171 | + "id_str": "8821452687517076614", |
| 172 | + "text": "Ea et laboriosam vel non.", |
| 173 | + // ... |
| 174 | +} |
| 175 | +``` |
| 176 | + |
| 177 | +```ruby |
| 178 | +# Keyword arguments: include_status, include_email |
| 179 | +Faker::Twitter.user #=> {:id=>8821452687517076614, :name=>"Lincoln Paucek", :screen_name=>"cody"... |
| 180 | +Faker::Twitter.user(include_status: false) # Just get a user object with no embed status |
| 181 | +Faker::Twitter.user(include_email: true) # Simulate an authenticated user with the email permission |
| 182 | + |
| 183 | +# Keyword arguments: include_user, include_photo |
| 184 | +Faker::Twitter.status #=> {:id=>8821452687517076614, :text=>"Ea et laboriosam vel non."... |
| 185 | +Faker::Twitter.status(include_user: false) # Just get a status object with no embed user |
| 186 | +Faker::Twitter.status(include_photo: true) # Includes entities for an attached image |
| 187 | + |
| 188 | +Faker::Twitter.screen_name #=> "audreanne_hackett" |
| 189 | +``` |
0 commit comments