Class: Faker::X
Constant Summary
Constants inherited from Base
Base::LLetters, Base::Letters, Base::NOT_GIVEN, Base::Numbers, Base::ULetters
Class Method Summary collapse
-
.screen_name ⇒ String
Produces a random screen_name.
-
.tweet(include_media: false, include_user: false) ⇒ Hash
Produces a random X tweet with default attributes.
-
.user ⇒ Hash
Produces a random X user based on X’s v2 API.
Methods inherited from Base
bothify, disable_enforce_available_locales, fetch, fetch_all, flexible, generate, letterify, method_missing, numerify, parse, rand, rand_in_range, regexify, resolve, respond_to_missing?, sample, shuffle, shuffle!, translate, unique, with_locale
Class Method Details
.screen_name ⇒ String
Produces a random screen_name.
312 313 314 |
# File 'lib/faker/default/twitter.rb', line 312 def screen_name Faker::Internet.username(specifier: nil, separators: ['_'])[0...20] end |
.tweet(include_media: false, include_user: false) ⇒ Hash
Produces a random X tweet with default attributes.
278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 |
# File 'lib/faker/default/twitter.rb', line 278 def tweet(include_media: false, include_user: false) tweet = {} tweet_object = tweet_item includes = {} if include_media media_key = Faker::Number.between(from: 1, to: 9_223_372_036_854_775_807).to_s includes[:media] = media(media_key) tweet_object[:attachments] = { media_keys: [media_key] } end includes[:users] = user[:includes][:users] if include_user tweet[:data] = [ tweet_object ] unless includes.empty? tweet[:includes] = includes end tweet end |
.user ⇒ Hash
Produces a random X user based on X’s v2 API.
227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 |
# File 'lib/faker/default/twitter.rb', line 227 def user = Faker::Number.between(from: 1, to: 9_223_372_036_854_775_807) { data: [ { author_id: .to_s, id: id.to_s, text: Faker::Lorem.sentence } ], includes: { users: [ { public_metrics: { followers_count: Faker::Number.between(to: 1, from: 1_000), following_count: Faker::Number.between(to: 1, from: 200), tweet_count: Faker::Number.between(to: 1, from: 10_000), listed_count: Faker::Number.between(to: 1, from: 1_000) }, username: screen_name, pinned_tweet_id: Faker::Number.between(from: 1, to: 9_223_372_036_854_775_807).to_s, entities: user_entities, description: Faker::Lorem.sentence, name: Faker::Name.name, verified: Faker::Boolean.boolean(true_ratio: 0.1), location: Faker::Internet.public_ip_v4_address, id: .to_s, protected: Faker::Boolean.boolean(true_ratio: 0.1), url: url, profile_image_url: Faker::Avatar.image(slug: id, size: '48x48'), created_at: created_at } ] } } end |