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.
100 101 102 |
# File 'lib/faker/default/x.rb', line 100 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.
66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 |
# File 'lib/faker/default/x.rb', line 66 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.
15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 |
# File 'lib/faker/default/x.rb', line 15 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 |